From 0a47e4c7714c9d1cf62efef3efafd3fc3ad354c2 Mon Sep 17 00:00:00 2001 From: Wayne Zhang Date: Fri, 3 Dec 2021 04:04:44 -0500 Subject: [PATCH] zos: use destructor for uv__threadpool_cleanup() (#3376) On z/OS, instead of calling the uv__threadpool_cleanup() function from inside uv_library_shutdown(), the destructor attribute must be used; otherwise, tests will fail with exit code 1 and no output. Additionally, post() does not need to be called when the destructor attribute is used. Also adds uv__os390_cleanup() function to clean System V message queue on z/OS. Co-authored-by: Igor Todorovski Co-authored-by: Gaby Baghdadi --- src/threadpool.c | 7 +++++++ src/unix/os390-syscalls.c | 5 +++++ src/unix/os390-syscalls.h | 1 + src/uv-common.c | 5 +++++ 4 files changed, 18 insertions(+) diff --git a/src/threadpool.c b/src/threadpool.c index 869ae95f..e804c7c4 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -160,13 +160,20 @@ static void post(QUEUE* q, enum uv__work_kind kind) { } +#ifdef __MVS__ +/* TODO(itodorov) - zos: revisit when Woz compiler is available. */ +__attribute__((destructor)) +#endif void uv__threadpool_cleanup(void) { unsigned int i; if (nthreads == 0) return; +#ifndef __MVS__ + /* TODO(gabylb) - zos: revisit when Woz compiler is available. */ post(&exit_message, UV__WORK_CPU); +#endif for (i = 0; i < nthreads; i++) if (uv_thread_join(threads + i)) diff --git a/src/unix/os390-syscalls.c b/src/unix/os390-syscalls.c index c1915533..a7411270 100644 --- a/src/unix/os390-syscalls.c +++ b/src/unix/os390-syscalls.c @@ -136,6 +136,11 @@ static void maybe_resize(uv__os390_epoll* lst, unsigned int len) { } +void uv__os390_cleanup(void) { + msgctl(uv_backend_fd(uv_default_loop()), IPC_RMID, NULL); +} + + static void init_message_queue(uv__os390_epoll* lst) { struct { long int header; diff --git a/src/unix/os390-syscalls.h b/src/unix/os390-syscalls.h index 7d59b75e..9f504171 100644 --- a/src/unix/os390-syscalls.h +++ b/src/unix/os390-syscalls.h @@ -70,5 +70,6 @@ int sem_destroy(UV_PLATFORM_SEM_T* semid); int sem_post(UV_PLATFORM_SEM_T* semid); int sem_trywait(UV_PLATFORM_SEM_T* semid); int sem_wait(UV_PLATFORM_SEM_T* semid); +void uv__os390_cleanup(void); #endif /* UV_OS390_SYSCALL_H_ */ diff --git a/src/uv-common.c b/src/uv-common.c index b0d5822e..f43dd3de 100644 --- a/src/uv-common.c +++ b/src/uv-common.c @@ -901,7 +901,12 @@ void uv_library_shutdown(void) { uv__process_title_cleanup(); uv__signal_cleanup(); +#ifdef __MVS__ + /* TODO(itodorov) - zos: revisit when Woz compiler is available. */ + uv__os390_cleanup(); +#else uv__threadpool_cleanup(); +#endif uv__store_relaxed(&was_shutdown, 1); }