From 1f7ee1a001291571f6be9fefd97e66e66c6296ef Mon Sep 17 00:00:00 2001 From: Jeremy Drake Date: Mon, 20 May 2024 14:02:28 -0700 Subject: [PATCH] hack on wait thread shutdown a bit --- winsup/cygwin/local_includes/sigproc.h | 3 ++- winsup/cygwin/pinfo.cc | 1 + winsup/cygwin/sigproc.cc | 15 ++++++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/local_includes/sigproc.h b/winsup/cygwin/local_includes/sigproc.h index 7aca80595d..a885a625e2 100644 --- a/winsup/cygwin/local_includes/sigproc.h +++ b/winsup/cygwin/local_includes/sigproc.h @@ -38,7 +38,8 @@ enum procstuff PROC_CLEARWAIT = 4, // clear all waits - signal arrived PROC_WAIT = 5, // setup for wait() for subproc PROC_EXECING = 6, // used to get a lock when execing - PROC_NOTHING = 7 // nothing, really + PROC_CLEARTHREAD = 7, // null out matching wait_thread + PROC_NOTHING = 8 // nothing, really }; struct sigpacket diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index bfd338e5b8..57d4626907 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -1327,6 +1327,7 @@ proc_waiter (void *arg) } sigproc_printf ("exiting wait thread for pid %d", pid); + proc_subproc (PROC_CLEARTHREAD, (uintptr_t) vchild.wait_thread); vchild.wait_thread = NULL; _my_tls._ctinfo->auto_release (); /* automatically return the cygthread to the cygthread pool */ return 0; diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 2f5fd47d42..c8d6b41b64 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -211,10 +211,12 @@ proc_subproc (DWORD what, uintptr_t val) int rc = 1; int potential_match; int clearing; + int i; waitq *w; #define wval ((waitq *) val) #define vchild (*((pinfo *) val)) +#define tval ((cygthread *) val) sigproc_printf ("args: %x, %d", what, val); @@ -304,6 +306,12 @@ proc_subproc (DWORD what, uintptr_t val) CloseHandle (w->next->ev); break; + case PROC_CLEARTHREAD: + for (i = 0; i < chld_procs.count (); i++) + if (chld_procs[i].wait_thread == tval) + chld_procs[i].wait_thread = NULL; + break; + /* Clear all waiting threads. Called from exceptions.cc prior to the main thread's dispatch to a signal handler function. (called from wait_sig thread) */ @@ -351,7 +359,7 @@ proc_subproc (DWORD what, uintptr_t val) } if (global_sigs[SIGCHLD].sa_handler == (void *) SIG_IGN) - for (int i = 0; i < chld_procs.count (); i += remove_proc (i)) + for (i = 0; i < chld_procs.count (); i += remove_proc (i)) continue; } @@ -362,6 +370,7 @@ proc_subproc (DWORD what, uintptr_t val) return rc; #undef wval #undef vchild +#undef tval } // FIXME: This is inelegant @@ -409,8 +418,8 @@ proc_terminate () to 1 iff it is a Cygwin process. */ if (!have_execed || !have_execed_cygwin) chld_procs[i]->ppid = 1; - if (chld_procs[i].wait_thread) - chld_procs[i].wait_thread->terminate_thread (); + /*if (chld_procs[i].wait_thread) + chld_procs[i].wait_thread->terminate_thread ();*/ /* Release memory associated with this process unless it is 'myself'. 'myself' is only in the chld_procs table when we've execed. We reach here when the next process has finished initializing but we