diff options
author | Christopher Faylor <me@cgf.cx> | 2005-10-17 23:27:00 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2005-10-17 23:27:00 +0000 |
commit | 267e201dae394e2d5deaa00fc2d4904a311210d8 (patch) | |
tree | 987ed376cf4af33ebd83038e81ed295158f5f671 /winsup/cygwin/sigproc.cc | |
parent | 8b00a766ff6986a76a794e3b21539023910dacd3 (diff) | |
download | cygnal-267e201dae394e2d5deaa00fc2d4904a311210d8.tar.gz cygnal-267e201dae394e2d5deaa00fc2d4904a311210d8.tar.bz2 cygnal-267e201dae394e2d5deaa00fc2d4904a311210d8.zip |
Change process_lock to lock_process throughout. Change all calls to new
cygthread to handle extra argument, throughout.
* cygthread.h (cygthread::callproc): Declare new method.
(cygthread::cygthread): Add optional length argument to allow copying arguments
to executing thread.
* cygthread.cc (cygthread::callproc): Define new method.
(cygthread::stub): Use callfunc to invoke thread func to allow potentially
allocating stack memory which will be returned.
(cygthread::simplestub): Ditto.
(cygthread::cygthread): Accept arglen argument. Reset ev here prior to
activating thread. Wait for ev after activating thread if we're copying
contents to the thread. Wait until the end before setting h, to allow thread
synchronization.
(cygthread::release): Don't reset ev here. Rely on that happening the next
time the thread is activated.
* pinfo.h (commune_process): Rename declaration from _pinfo::commune_process.
* pinfo.cc (commune_process): Ditto for definition. Modify slightly to allow
running as a separate cygthread.
* sigproc.cc (child_info::sync): Always wait for both subproc_ready and any
hProcess if we have a cygwin parent.
(talktome): Change argument to be a pointer to siginfo_t. Contiguously
allocate whole siginfo_t structure + any needed extra for eventual passing to
commune_process thread.
(wait_sig): Accommodate change in talktome argument.
* pipe.cc (fhandler_pipe::fixup_after_exec): Remove debugging.
Diffstat (limited to 'winsup/cygwin/sigproc.cc')
-rw-r--r-- | winsup/cygwin/sigproc.cc | 87 |
1 files changed, 49 insertions, 38 deletions
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 27f38f0ae..3a5132600 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -481,7 +481,7 @@ sigproc_init () sync_proc_subproc.init ("sync_proc_subproc"); my_sendsig = INVALID_HANDLE_VALUE; // changed later - cygthread *hwait_sig = new cygthread (wait_sig, cygself, "sig"); + cygthread *hwait_sig = new cygthread (wait_sig, 0, cygself, "sig"); hwait_sig->zap_h (); global_sigs[SIGSTOP].sa_flags = SA_RESTART | SA_NODEFER; @@ -816,36 +816,44 @@ child_info::ready (bool execed) } bool -child_info::sync (pid_t pid, HANDLE hProcess, DWORD howlong) +child_info::sync (pid_t pid, HANDLE& hProcess, DWORD howlong) { - if (!subproc_ready) + bool res; + if (!subproc_ready && !myself->wr_proc_pipe) + res = false; + else { - sigproc_printf ("not waiting. subproc_ready is NULL"); - return false; - } + HANDLE w4[2]; + unsigned n = 0; + unsigned nsubproc_ready; - HANDLE w4[2]; - w4[0] = subproc_ready; - w4[1] = hProcess; + if (!subproc_ready) + nsubproc_ready = WAIT_OBJECT_0 + 3; + else + { + w4[n++] = subproc_ready; + nsubproc_ready = 0; + } + w4[n++] = hProcess; - bool res; - sigproc_printf ("waiting for subproc_ready(%p) and child process(%p)", w4[0], w4[1]); - switch (WaitForMultipleObjects (2, w4, FALSE, howlong)) - { - case WAIT_OBJECT_0: - sigproc_printf ("got subproc_ready for pid %d", pid); - res = true; - break; - case WAIT_OBJECT_0 + 1: - sigproc_printf ("process exited before subproc_ready"); - if (WaitForSingleObject (subproc_ready, 0) == WAIT_OBJECT_0) - sigproc_printf ("should never happen. noticed subproc_ready after process exit"); - res = false; - break; - default: - system_printf ("wait failed, pid %d, %E", pid); - res = false; - break; + sigproc_printf ("waiting for subproc_ready(%p) and child process(%p)", w4[0], w4[1]); + DWORD x = WaitForMultipleObjects (n, w4, FALSE, howlong); + x -= WAIT_OBJECT_0; + if (x >= n) + { + system_printf ("wait failed, pid %d, %E", pid); + res = false; + } + else + { + if (n == nsubproc_ready) + { + CloseHandle (hProcess); + hProcess = NULL; + } + sigproc_printf ("process %d synchronized, WFMO returned %d", pid, x); + res = true; + } } return res; } @@ -968,25 +976,28 @@ stopped_or_terminated (waitq *parent_w, _pinfo *child) } static void -talktome (siginfo_t& si, HANDLE readsig) +talktome (siginfo_t *si, HANDLE readsig) { - sigproc_printf ("pid %d wants some information", si.si_pid); - pinfo pi (si.si_pid); - sigproc_printf ("pid %d pi %p", si.si_pid, (_pinfo *) pi); // DELETEME - if (si._si_commune._si_code & PICOM_EXTRASTR) + unsigned size = sizeof (*si); + sigproc_printf ("pid %d wants some information", si->si_pid); + if (si->_si_commune._si_code & PICOM_EXTRASTR) { size_t n; DWORD nb; if (!ReadFile (readsig, &n, sizeof (n), &nb, NULL) || nb != sizeof (n)) return; - // FIXME: Is alloca here? - si._si_commune._si_str = (char *) alloca (n + 1); - if (!ReadFile (readsig, si._si_commune._si_str, n, &nb, NULL) || nb != n) + siginfo_t *newsi = (siginfo_t *) alloca (size += n + 1); + *newsi = *si; + newsi->_si_commune._si_str = (char *) (newsi + 1); + if (!ReadFile (readsig, newsi->_si_commune._si_str, n, &nb, NULL) || nb != n) return; - si._si_commune._si_str[n] = '\0'; + newsi->_si_commune._si_str[n] = '\0'; + si = newsi; } + + pinfo pi (si->si_pid); if (pi) - pi->commune_process (si); + new cygthread (commune_process, size, si, "commune_process"); } void @@ -1100,7 +1111,7 @@ wait_sig (VOID *) switch (pack.si.si_signo) { case __SIGCOMMUNE: - talktome (pack.si, readsig); + talktome (&pack.si, readsig); break; case __SIGSTRACE: strace.hello (); |