diff options
-rw-r--r-- | winsup/cygwin/ChangeLog | 32 | ||||
-rw-r--r-- | winsup/cygwin/cygthread.cc | 8 | ||||
-rw-r--r-- | winsup/cygwin/cygthread.h | 21 | ||||
-rw-r--r-- | winsup/cygwin/dcrt0.cc | 11 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_netdrive.cc | 2 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_tty.cc | 8 | ||||
-rw-r--r-- | winsup/cygwin/fork.cc | 7 | ||||
-rw-r--r-- | winsup/cygwin/init.cc | 7 | ||||
-rw-r--r-- | winsup/cygwin/pinfo.cc | 2 | ||||
-rw-r--r-- | winsup/cygwin/select.cc | 8 | ||||
-rw-r--r-- | winsup/cygwin/sigproc.cc | 76 | ||||
-rw-r--r-- | winsup/cygwin/sigproc.h | 3 | ||||
-rw-r--r-- | winsup/cygwin/timer.cc | 2 | ||||
-rw-r--r-- | winsup/cygwin/window.cc | 2 |
14 files changed, 91 insertions, 98 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 0a3ae60..aa8ceab 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,35 @@ +2010-09-01 Christopher Faylor <me+cygwin@cgf.cx> + + * cygthread.cc (cygthread::create): Fix incorrect use of name rather + than __name. + * cygthread.h (cygthread::cygthread): Create versions which eliminate + 'n' parameter. + * dcrt0.cc (dll_crt0_1): Remove check for threadfunc_ix. Remove + obsolete comments. Set process_state to active here. + * fhandler_netdrive.cc (create_thread_and_wait): Use shortened + cygthread constructor. + * timer.cc (timer_tracker::settime): Ditto. + * window.cc (HWND): Ditto. + * fhandler_tty.cc: Use shortened cygthread constructor, where + appropriate, throughout. + * select.cc: Ditto. + * fork.cc (frok::child): Remove wait_for_sigthread. + (fork): Reformat if for slightly better clarity. + * init.cc (dll_finished_loading): New variable. + (dll_entry): Use dll_finished_loading to determine when we should call + merge_threadfunc. + * sigproc.cc (no_signals_available): Simplify by using my_readsig. + (wait_sig_inited): Delete. + (wait_sig): Define as void function. + (pending_signals): Accommodate change to wait_sig definition. + (wait_for_sigthread): Delete definition. + (sigproc_init): Initialize signal pipe here, before wait_sig thread is + created. Use void form of cygthread creation. + (init_sig_pipe): Delete. + (wait_sig): Return void rather than DWORD. Assume previous + initialization of signal pipe. Set my_sendsig to NULL when exiting. + * sigproc.h (wait_for_sigthread): Delete declaration. + 2010-09-01 Corinna Vinschen <corinna@vinschen.de> * fhandler_netdrive.cc (fhandler_netdrive::readdir): Set d_type. diff --git a/winsup/cygwin/cygthread.cc b/winsup/cygwin/cygthread.cc index 85aeb86..b59140e 100644 --- a/winsup/cygwin/cygthread.cc +++ b/winsup/cygwin/cygthread.cc @@ -188,7 +188,7 @@ out: void cygthread::create () { - thread_printf ("name %s, id %p", name, id); + thread_printf ("name %s, id %p, this %p", __name, id, this); HANDLE htobe; if (h) { @@ -197,7 +197,7 @@ cygthread::create () while (!thread_sync) yield (); SetEvent (thread_sync); - thread_printf ("activated name '%s', thread_sync %p for thread %p", name, thread_sync, id); + thread_printf ("activated name '%s', thread_sync %p for id %p", __name, thread_sync, id); htobe = h; } else @@ -206,8 +206,8 @@ cygthread::create () htobe = CreateThread (&sec_none_nih, 0, is_freerange ? simplestub : stub, this, 0, &id); if (!htobe) - api_fatal ("CreateThread failed for %s - %p<%p>, %E", name, h, id); - thread_printf ("created name '%s', thread %p, id %p", name, h, id); + api_fatal ("CreateThread failed for %s - %p<%p>, %E", __name, h, id); + thread_printf ("created name '%s', thread %p, id %p", __name, h, id); #ifdef DEBUGGING terminated = false; #endif diff --git a/winsup/cygwin/cygthread.h b/winsup/cygwin/cygthread.h index 593cfdd..cf1fd41 100644 --- a/winsup/cygwin/cygthread.h +++ b/winsup/cygwin/cygthread.h @@ -31,7 +31,8 @@ class cygthread bool is_freerange; static bool exiting; HANDLE notify_detached; - void create () __attribute__ ((regparm(1))); + bool standalone; + void create () __attribute__ ((regparm(2))); public: bool terminate_thread (); static DWORD WINAPI stub (VOID *); @@ -42,13 +43,27 @@ class cygthread void auto_release () {func = NULL;} void release (bool); cygthread (LPTHREAD_START_ROUTINE start, unsigned n, LPVOID param, const char *name, HANDLE notify = NULL) - : __name (name), func (start), arglen (n), arg (param), notify_detached (notify) + : __name (name), func (start), arglen (n), arg (param), notify_detached (notify), standalone (false) + { + create (); + } + cygthread (LPVOID_THREAD_START_ROUTINE start, LPVOID param, const char *name, HANDLE notify = NULL) + : __name (name), func ((LPTHREAD_START_ROUTINE) start), arglen (0), + arg (param), notify_detached (notify), standalone (true) + { + create (); + /* This is a neverending/high-priority thread */ + ::SetThreadPriority (h, THREAD_PRIORITY_HIGHEST); + zap_h (); + } + cygthread (LPTHREAD_START_ROUTINE start, LPVOID param, const char *name, HANDLE notify = NULL) + : __name (name), func (start), arglen (0), arg (param), notify_detached (notify), standalone (false) { create (); } cygthread (LPVOID_THREAD_START_ROUTINE start, unsigned n, LPVOID param, const char *name, HANDLE notify = NULL) : __name (name), func ((LPTHREAD_START_ROUTINE) start), arglen (n), - arg (param), notify_detached (notify) + arg (param), notify_detached (notify), standalone (true) { create (); /* This is a neverending/high-priority thread */ diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 4ab39af..ecd9a6c 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -715,6 +715,9 @@ dll_crt0_0 () GetCurrentProcess (), &hMainThread, 0, false, DUPLICATE_SAME_ACCESS); + myself->process_state |= PID_ACTIVE; + myself->process_state &= ~PID_INITIALIZING; + OpenProcessToken (GetCurrentProcess (), MAXIMUM_ALLOWED, &hProcToken); set_cygwin_privileges (hProcToken); @@ -869,11 +872,6 @@ dll_crt0_1 (void *) uinfo_init (); /* initialize user info */ - wait_for_sigthread (); - extern DWORD threadfunc_ix; - if (!threadfunc_ix) - system_printf ("internal error: couldn't determine location of thread function on stack. Expect signal problems."); - /* Connect to tty. */ tty::init_session (); @@ -961,9 +959,6 @@ dll_crt0_1 (void *) MALLOC_CHECK; cygbench (__progname); - /* Flush signals and ensure that signal thread is up and running. Can't - do this for noncygwin case since the signal thread is blocked due to - LoadLibrary serialization. */ ld_preload (); /* Per POSIX set the default application locale back to "C". */ _setlocale_r (_REENT, LC_CTYPE, "C"); diff --git a/winsup/cygwin/fhandler_netdrive.cc b/winsup/cygwin/fhandler_netdrive.cc index bd826fc..4797152 100644 --- a/winsup/cygwin/fhandler_netdrive.cc +++ b/winsup/cygwin/fhandler_netdrive.cc @@ -136,7 +136,7 @@ create_thread_and_wait (int what, PVOID in, PVOID out, DWORD outsize, { netdriveinf ndi = { what, 0, in, out, outsize, CreateSemaphore (&sec_none_nih, 0, 2, NULL) }; - cygthread *thr = new cygthread (thread_netdrive, 0, &ndi, name); + cygthread *thr = new cygthread (thread_netdrive, &ndi, name); if (thr->detach (ndi.sem)) ndi.ret = ERROR_OPERATION_ABORTED; CloseHandle (ndi.sem); diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 1d44f32..45ab24b 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -89,9 +89,9 @@ fhandler_tty_master::init () set_close_on_exec (true); - new cygthread (process_input, 0, cygself, "ttyin"); - new cygthread (process_ioctl, 0, cygself, "ttyioctl"); - new cygthread (process_output, 0, cygself, "ttyout"); + new cygthread (process_input, cygself, "ttyin"); + new cygthread (process_ioctl, cygself, "ttyioctl"); + new cygthread (process_output, cygself, "ttyout"); return 0; } @@ -1805,7 +1805,7 @@ fhandler_pty_master::setup (bool ispty) errstr = "pty master control pipe"; goto err; } - master_thread = new cygthread (::pty_master_thread, 0, this, "pty_master"); + master_thread = new cygthread (::pty_master_thread, this, "pty_master"); if (!master_thread) { errstr = "pty master control thread"; diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc index fe977d2..b942c72 100644 --- a/winsup/cygwin/fork.cc +++ b/winsup/cygwin/fork.cc @@ -242,7 +242,6 @@ frok::child (volatile char * volatile here) ld_preload (); fixup_hooks_after_fork (); _my_tls.fixup_after_fork (); - wait_for_sigthread (); cygwin_finished_initializing = true; return 0; } @@ -619,9 +618,9 @@ fork () } MALLOC_CHECK; - if (ischild || res > 0) - /* everything is ok */; - else + if (ischild) + /* nothing to do */; + else if (res < 0) { if (!grouped.error) syscall_printf ("fork failed - child pid %d, errno %d", grouped.child_pid, grouped.this_errno); diff --git a/winsup/cygwin/init.cc b/winsup/cygwin/init.cc index 9bf49f2..0f6b67e 100644 --- a/winsup/cygwin/init.cc +++ b/winsup/cygwin/init.cc @@ -18,8 +18,8 @@ static DWORD _my_oldfunc; static char NO_COPY *search_for = (char *) cygthread::stub; unsigned threadfunc_ix[8] __attribute__((section (".cygwin_dll_common"), shared)); -extern cygthread *hwait_sig; +static bool dll_finished_loading; #define OLDFUNC_OFFSET -1 static void WINAPI @@ -138,17 +138,18 @@ dll_entry (HANDLE h, DWORD reason, void *static_load) dll_crt0_0 (); _my_oldfunc = TlsAlloc (); + dll_finished_loading = true; break; case DLL_PROCESS_DETACH: if (dynamically_loaded) shared_destroy (); break; case DLL_THREAD_ATTACH: - if (hwait_sig) + if (dll_finished_loading) munge_threadfunc (); break; case DLL_THREAD_DETACH: - if (hwait_sig && (void *) &_my_tls > (void *) &wow64_test_stack_marker + if (dll_finished_loading && (void *) &_my_tls > (void *) &wow64_test_stack_marker && _my_tls.isinitialized ()) _my_tls.remove (0); break; diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index e0b1e1f..106d357 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -962,7 +962,7 @@ pinfo::wait () waiter_ready = false; /* Fire up a new thread to track the subprocess */ - cygthread *h = new cygthread (proc_waiter, 0, this, "proc_waiter"); + cygthread *h = new cygthread (proc_waiter, this, "proc_waiter"); if (!h) sigproc_printf ("tracking thread creation failed for pid %d", (*this)->pid); else diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc index 611367b..87b8d15 100644 --- a/winsup/cygwin/select.cc +++ b/winsup/cygwin/select.cc @@ -635,7 +635,7 @@ start_thread_pipe (select_record *me, select_stuff *stuff) { pi->start = &stuff->start; pi->stop_thread = false; - pi->thread = new cygthread (thread_pipe, 0, pi, "select_pipe"); + pi->thread = new cygthread (thread_pipe, pi, "select_pipe"); me->h = *pi->thread; if (!me->h) return 0; @@ -1140,7 +1140,7 @@ start_thread_serial (select_record *me, select_stuff *stuff) select_serial_info *si = new select_serial_info; si->start = &stuff->start; si->stop_thread = false; - si->thread = new cygthread (thread_serial, 0, si, "select_serial"); + si->thread = new cygthread (thread_serial, si, "select_serial"); me->h = *si->thread; stuff->device_specific_serial = si; } @@ -1456,7 +1456,7 @@ start_thread_socket (select_record *me, select_stuff *stuff) stuff->device_specific_socket = si; si->start = &stuff->start; select_printf ("stuff_start %p", &stuff->start); - si->thread = new cygthread (thread_socket, 0, si, "select_socket"); + si->thread = new cygthread (thread_socket, si, "select_socket"); me->h = *si->thread; return 1; } @@ -1699,7 +1699,7 @@ start_thread_mailslot (select_record *me, select_stuff *stuff) select_mailslot_info *mi = new select_mailslot_info; mi->start = &stuff->start; mi->stop_thread = false; - mi->thread = new cygthread (thread_mailslot, 0, mi, "select_mailslot"); + mi->thread = new cygthread (thread_mailslot, mi, "select_mailslot"); me->h = *mi->thread; if (!me->h) return 0; diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index a8bb4f3..2e63068 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -33,7 +33,7 @@ details. */ #define WSSC 60000 // Wait for signal completion #define WPSP 40000 // Wait for proc_subproc mutex -#define no_signals_available(x) (!hwait_sig || (hwait_sig == INVALID_HANDLE_VALUE) || ((x) && myself->exitcode & EXITCODE_SET) || (&_my_tls == _sig_tls) || !cygwin_finished_initializing) +#define no_signals_available(x) (!my_sendsig ||( myself->exitcode & EXITCODE_SET) || (&_my_tls == _sig_tls) || !cygwin_finished_initializing) #define NPROCS 256 @@ -55,9 +55,6 @@ HANDLE NO_COPY signal_arrived; // Event signaled when a signal has HANDLE NO_COPY sigCONT; // Used to "STOP" a process -cygthread NO_COPY *hwait_sig; -Static HANDLE wait_sig_inited; // Control synchronization of - // message queue startup Static bool sigheld; // True if holding signals Static int nprocs; // Number of deceased children @@ -78,7 +75,7 @@ static int __stdcall checkstate (waitq *) __attribute__ ((regparm (1))); static __inline__ bool get_proc_lock (DWORD, DWORD); static bool __stdcall remove_proc (int); static bool __stdcall stopped_or_terminated (waitq *, _pinfo *); -static DWORD WINAPI wait_sig (VOID *arg); +static void WINAPI wait_sig (VOID *arg); /* wait_sig bookkeeping */ @@ -97,7 +94,7 @@ public: sigpacket *save () const {return curr;} void restore (sigpacket *saved) {curr = saved;} friend void __stdcall sig_dispatch_pending (bool); - friend DWORD WINAPI wait_sig (VOID *arg); + friend void WINAPI wait_sig (VOID *arg); }; Static pending_signals sigq; @@ -127,20 +124,6 @@ signal_fixup_after_exec () } } -void __stdcall -wait_for_sigthread () -{ - sigproc_printf ("wait_sig_inited %p", wait_sig_inited); - HANDLE hsig_inited = wait_sig_inited; - WaitForSingleObject (hsig_inited, INFINITE); - wait_sig_inited = NULL; - myself->sendsig = my_sendsig; - myself->process_state |= PID_ACTIVE; - myself->process_state &= ~PID_INITIALIZING; - ForceCloseHandle1 (hsig_inited, wait_sig_inited); - sigproc_printf ("process/signal handling enabled, state %p", myself->process_state); -} - /* Get the sync_proc_subproc muto to control access to * children, proc arrays. * Attempt to handle case where process is exiting as we try to grab @@ -468,23 +451,21 @@ create_signal_arrived () } /* Signal thread initialization. Called from dll_crt0_1. - - This routine starts the signal handling thread. The wait_sig_inited - event is used to signal that the thread is ready to handle signals. - We don't wait for this during initialization but instead detect it - in sig_send to gain a little concurrency. */ + This routine starts the signal handling thread. */ void __stdcall sigproc_init () { - wait_sig_inited = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL); - ProtectHandle (wait_sig_inited); - + char char_sa_buf[1024]; + PSECURITY_ATTRIBUTES sa_buf = sec_user_nih ((PSECURITY_ATTRIBUTES) char_sa_buf, cygheap->user.sid()); + for (int i = 5; i > 0 && !CreatePipe (&my_readsig, &my_sendsig, sa_buf, 0); i--) + if (i == 1) + api_fatal ("couldn't create signal pipe, %E"); + ProtectHandle (my_readsig); + myself->sendsig = my_sendsig; + new cygthread (wait_sig, cygself, "sig"); /* sync_proc_subproc is used by proc_subproc. It serialises access to the children and proc arrays. */ sync_proc_subproc.init ("sync_proc_subproc"); - - hwait_sig = new cygthread (wait_sig, 0, cygself, "sig"); - hwait_sig->zap_h (); } /* Called on process termination to terminate signal and process threads. @@ -566,13 +547,9 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls) { if (no_signals_available (si.si_signo != __SIGEXIT)) { - sigproc_printf ("my_sendsig %p, myself->sendsig %p, exit_state %d", - my_sendsig, myself->sendsig, exit_state); set_errno (EAGAIN); goto out; // Either exiting or not yet initializing } - if (wait_sig_inited) - wait_for_sigthread (); wait_for_completion = p != myself_nowait && _my_tls.isinitialized () && !exit_state; p = myself; } @@ -1150,37 +1127,14 @@ pending_signals::next () return res; } -/* Called separately to allow stack space reutilization by wait_sig. - This function relies on the fact that it will be called after cygheap - has been set up. For the case of non-dynamic DLL initialization this - means that it relies on the implicit serialization guaranteed by being - run as part of DLL_PROCESS_ATTACH. */ -static void __attribute__ ((noinline)) -init_sig_pipe() -{ - char char_sa_buf[1024]; - PSECURITY_ATTRIBUTES sa_buf = sec_user_nih ((PSECURITY_ATTRIBUTES) char_sa_buf, cygheap->user.sid()); - for (int i = 5; i > 0 && !CreatePipe (&my_readsig, &my_sendsig, sa_buf, 0); i--) - if (i == 1) - api_fatal ("couldn't create signal pipe, %E"); - ProtectHandle (my_readsig); -} - - /* Process signals by waiting for signal data to arrive in a pipe. Set a completion event if one was specified. */ -static DWORD WINAPI +static void WINAPI wait_sig (VOID *) { - init_sig_pipe (); - /* Initialization */ - SetThreadPriority (GetCurrentThread (), WAIT_SIG_PRIORITY); - + _sig_tls = &_my_tls; sigCONT = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL); - SetEvent (wait_sig_inited); - - _sig_tls = &_my_tls; sigproc_printf ("entering ReadFile loop, my_readsig %p, my_sendsig %p", my_readsig, my_sendsig); @@ -1253,7 +1207,7 @@ wait_sig (VOID *) } break; case __SIGEXIT: - hwait_sig = (cygthread *) INVALID_HANDLE_VALUE; + my_sendsig = NULL; sigproc_printf ("saw __SIGEXIT"); break; /* handle below */ default: diff --git a/winsup/cygwin/sigproc.h b/winsup/cygwin/sigproc.h index 7da1bc3..ee6e7d5 100644 --- a/winsup/cygwin/sigproc.h +++ b/winsup/cygwin/sigproc.h @@ -81,7 +81,6 @@ bool __stdcall pid_exists (pid_t) __attribute__ ((regparm(1))); int __stdcall sig_send (_pinfo *, siginfo_t&, class _cygtls *tls = NULL) __attribute__ ((regparm (3))); int __stdcall sig_send (_pinfo *, int) __attribute__ ((regparm (2))); void __stdcall signal_fixup_after_exec (); -void __stdcall wait_for_sigthread (); void __stdcall sigalloc (); void __stdcall create_signal_arrived (); @@ -92,7 +91,5 @@ extern char myself_nowait_dummy[]; extern struct sigaction *global_sigs; -#define WAIT_SIG_PRIORITY THREAD_PRIORITY_NORMAL - #define myself_nowait ((_pinfo *) myself_nowait_dummy) #endif /*_SIGPROC_H*/ diff --git a/winsup/cygwin/timer.cc b/winsup/cygwin/timer.cc index 9cf9584..91e7114 100644 --- a/winsup/cygwin/timer.cc +++ b/winsup/cygwin/timer.cc @@ -253,7 +253,7 @@ timer_tracker::settime (int in_flags, const itimerspec *value, itimerspec *ovalu syncthread = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL); else ResetEvent (syncthread); - new cygthread (timer_thread, 0, this, "itimer", syncthread); + new cygthread (timer_thread, this, "itimer", syncthread); } return 0; diff --git a/winsup/cygwin/window.cc b/winsup/cygwin/window.cc index ac00a0c..981c080 100644 --- a/winsup/cygwin/window.cc +++ b/winsup/cygwin/window.cc @@ -111,7 +111,7 @@ HWND () if (!hwnd) { _lock.upforgrabs (); - cygthread *h = new cygthread (::winthread, 0, this, "win"); + cygthread *h = new cygthread (::winthread, this, "win"); h->SetThreadPriority (THREAD_PRIORITY_HIGHEST); h->zap_h (); lock (); |