mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-01-16 03:19:54 +08:00
962f9a2ccc
* cygserver_ipc.h (ipc_set_proc_info): Use _cygtls::ipc_set_proc_info to set per-thread signal arrived value. * cygthread.cc (cygthread::detach): Use per-thread signal_arrived via set_thread_waiting. * fork.cc (_cygtls::fixup_after_fork): Clear signal_arrived. (_cygtls::remove): Close any signal_arrived handle when thread exists. (_cygtls::find_tls): Remove unneeded function. * cygtls.h: Update copyright. (class _cygtls): Reorganize to help avoid rebuilding newlib when structure changes. (_cygtls::event): Delete. (_cygtls::threadkill): Ditto. (_cygtls::signal_waiting): Declare new bool. (_cygtls::find_tls): Delete declaration. (_cygtls::set_threadkill): Ditto. (_cygtls::reset_threadkill): Ditto. (_cygtls::set_signal_arrived): Declare new function. (class set_thread_waiting): Declare new class. * cygwait.cc (cw_nowait_storage): Define. (cygwait): Set per-thread signal_arrived via set_thread_waiting. Don't special-case _main_tls. * cygwait.h (cw_nowait): Define. (cw_infinite): Ditto. (cygwait): Redefine pathological wait-only case. * dcrt0.cc (dll_crt0_0): Remove call to now-defunct events_init(). (dll_crt0_1): Remove call to now-defunct create_signal_arrived(). * exceptions.cc: Reflect set_signal_mask() argument reordering throughout. Remove signal mask synchronization throughout. (events_init): Delete definition. (mask_sync): Delete now-unneeded mask synchronization. (set_signal_mask): Reverse order of arguments to "standard" to, from layout. Rename "newmask" argument to "setmask". Remove debugging. (sig_handle_tty_stop): Use cancelable_wait rather than WFMO. (_cygtls::interrupt_setup): Don't treat "threadkill" events specially. Conditionally set signal_arrived depending on whether the thread has created it or not. (sigpacket::process): Reorganize to reflect thread-specific sending of signals which is more in line with the way it was actually supposed to work. * fhandler_socket.cc (get_inet_addr): Use cancelable_wait rather than IsEventSignalled to avoid potential race. (fhandler_socket::wait_for_events): Set signal_arrived event using set_thread_waiting(). (fhandler_socket::close): Use cygwait for the case of just waiting 10 ms for a signal. * fhandler_tape.cc (fhandler_dev_tape::_lock): Use cancelable_wait rather than WFMO. Redo switch/case tests accordingly. * fhandler_termios.cc (fhandler_termios::bg_check): Use cygwait for case of just waiting 0 ms for a potential signal. * fhandler_tty.cc (fhandler_pty_master::process_slave_output): Use cancelable_wait rather than WFSO. * fhandler_windows.cc (fhandler_windows::read): Set per-thread signal_arrived via set_thread_waiting(). * flock.cc (lf_setlock): Ditto. * select.cc (pselect): Ditto. Set per-thread signal_arrived using set_thread_waiting(). * gendef: Don't special case handling of _cygtls::sig for threads. * gentls_offsets: Use #pragma once in tlsoffsets.h. * ntdll.h: Use #pragma once. * poll.cc: Reflect set_signal_mask() argument reordering. * posix_ipc.cc (ipc_mutex_lock): Use cancelable_wait rather than WFMO. (ipc_cond_timedwait): Set perl-thread signal arrived using set_thread_waiting(). * security.h: Use #pragma once. * signal.cc (abort): Reflect set_signal_mask() argument reordering. (clock_nanosleep): Ditto. Change call to cancelable_wait to properly specify handling of cancel and interrupt. (sigwaitinfo): Remove handling of per-thread event in favor of per-thread signal_arrived. Use cancelable_wait rather than WFSO. * sigproc.cc (signal_arrived): Delete definition. (create_signal_arrived): Ditto. * sigproc.h (signal_arrived): Delete declaration. (set_signal_mask): Avoid defining as a "C" function. Don't conditionally declare. (create_signal_arrived): Delete declaration. * syscalls.cc (rename): Use cygwait() rather than WFSO. * thread.h (fast_mutex::lock): Use cw_infinite rather than LARGE_NULL. * wait.cc (wait4): Ditto. * thread.cc (pthread_mutex::lock): Ditto. (pthread::join): Ditto. (semaphore::_wait): Ditto. (pthread_kill): Remove set_threadkill() accommodation. * tlsoffsets.h: Regenerate.
117 lines
2.4 KiB
C++
117 lines
2.4 KiB
C++
/* wait.cc: Posix wait routines.
|
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
|
2005, 2009, 2011, 2012 Red Hat, Inc.
|
|
|
|
This file is part of Cygwin.
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
details. */
|
|
|
|
#include "winsup.h"
|
|
#include <sys/wait.h>
|
|
#include "sigproc.h"
|
|
#include "thread.h"
|
|
#include "cygtls.h"
|
|
#include "cygwait.h"
|
|
|
|
/* This is called _wait and not wait because the real wait is defined
|
|
in libc/syscalls/syswait.c. It calls us. */
|
|
|
|
extern "C" pid_t
|
|
wait (int *status)
|
|
{
|
|
return wait4 (-1, status, 0, NULL);
|
|
}
|
|
|
|
extern "C" pid_t
|
|
waitpid (pid_t intpid, int *status, int options)
|
|
{
|
|
return wait4 (intpid, status, options, NULL);
|
|
}
|
|
|
|
extern "C" pid_t
|
|
wait3 (int *status, int options, struct rusage *r)
|
|
{
|
|
return wait4 (-1, status, options, r);
|
|
}
|
|
|
|
/* Wait for any child to complete.
|
|
* Note: this is not thread safe. Use of wait in multiple threads will
|
|
* not work correctly.
|
|
*/
|
|
|
|
extern "C" pid_t
|
|
wait4 (int intpid, int *status, int options, struct rusage *r)
|
|
{
|
|
int res;
|
|
HANDLE waitfor;
|
|
waitq *w = &_my_tls.wq;
|
|
|
|
pthread_testcancel ();
|
|
|
|
while (1)
|
|
{
|
|
sig_dispatch_pending ();
|
|
if (options & ~(WNOHANG | WUNTRACED | WCONTINUED))
|
|
{
|
|
set_errno (EINVAL);
|
|
res = -1;
|
|
break;
|
|
}
|
|
|
|
if (r)
|
|
memset (r, 0, sizeof (*r));
|
|
|
|
w->pid = intpid;
|
|
w->options = options;
|
|
w->rusage = r;
|
|
sigproc_printf ("calling proc_subproc, pid %d, options %d",
|
|
w->pid, w->options);
|
|
if (!proc_subproc (PROC_WAIT, (DWORD) w))
|
|
{
|
|
set_errno (ENOSYS);
|
|
paranoid_printf ("proc_subproc returned 0");
|
|
res = -1;
|
|
break;
|
|
}
|
|
|
|
if ((waitfor = w->ev) == NULL)
|
|
goto nochildren;
|
|
|
|
res = cancelable_wait (waitfor, cw_infinite, cw_cancel | cw_cancel_self);
|
|
|
|
sigproc_printf ("%d = cancelable_wait (...)", res);
|
|
|
|
if (w->ev == NULL)
|
|
{
|
|
nochildren:
|
|
/* found no children */
|
|
set_errno (ECHILD);
|
|
res = -1;
|
|
break;
|
|
}
|
|
|
|
if (w->status == -1)
|
|
{
|
|
if (_my_tls.call_signal_handler ())
|
|
continue;
|
|
set_sig_errno (EINTR);
|
|
res = -1;
|
|
}
|
|
else if (res != WAIT_OBJECT_0)
|
|
{
|
|
set_errno (EINVAL);
|
|
res = -1;
|
|
}
|
|
else if ((res = w->pid) != 0 && status)
|
|
*status = w->status;
|
|
break;
|
|
}
|
|
|
|
syscall_printf ("%R = wait4(%d, %p, %d, %p)", res, intpid, w->status, options, r);
|
|
w->status = -1;
|
|
return res;
|
|
}
|