Skip to content

Commit

Permalink
hack on wait thread shutdown a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyd2019 committed Jul 25, 2024
1 parent 7484c55 commit 1f7ee1a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion winsup/cygwin/local_includes/sigproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions winsup/cygwin/pinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 12 additions & 3 deletions winsup/cygwin/sigproc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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) */
Expand Down Expand Up @@ -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;
}

Expand All @@ -362,6 +370,7 @@ proc_subproc (DWORD what, uintptr_t val)
return rc;
#undef wval
#undef vchild
#undef tval
}

// FIXME: This is inelegant
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1f7ee1a

Please sign in to comment.