From fa35a1ee5c602b765ca8a2886b2062971f871c47 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Mon, 3 Oct 2005 17:23:54 +0000 Subject: [PATCH] * cygheap.h (class process_lock): New class. * dtable.h (class dtable): Add class process_lock as a friend. * dcrt0.cc (get_exit_lock): Delete. (do_exit): Use process_lock class instead of get_exit_lock. * exceptions.cc (signal_exit): Ditto. * pinfo.cc (pinfo::exit): Ditto. (_pinfo::commune_process): Set process lock around this whole function. (_pinfo::commune_request): Use process_lock rather than myself.lock. * pinfo.h (pinfo::_lock): Delete. (pinfo::initialize_lock): Delete. (pinfo::lock): Delete. (pinfo::unlock): Delete. * winsup.h (get_exit_lock): Delete declaration. --- winsup/cygwin/ChangeLog | 17 +++++++++++++++++ winsup/cygwin/cygheap.h | 21 +++++++++++++++++++++ winsup/cygwin/dcrt0.cc | 13 +------------ winsup/cygwin/dtable.h | 1 + winsup/cygwin/exceptions.cc | 6 +++++- winsup/cygwin/pinfo.cc | 9 ++++----- winsup/cygwin/pinfo.h | 4 ---- winsup/cygwin/winsup.h | 1 - 8 files changed, 49 insertions(+), 23 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index d5711b324..77b6dec4f 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,20 @@ +2005-10-03 Christopher Faylor + + * cygheap.h (class process_lock): New class. + * dtable.h (class dtable): Add class process_lock as a friend. + * dcrt0.cc (get_exit_lock): Delete. + (do_exit): Use process_lock class instead of get_exit_lock. + * exceptions.cc (signal_exit): Ditto. + * pinfo.cc (pinfo::exit): Ditto. + (_pinfo::commune_process): Set process lock around this whole function. + (_pinfo::commune_request): Use process_lock rather than myself.lock. + * pinfo.h (pinfo::_lock): Delete. + (pinfo::initialize_lock): Delete. + (pinfo::lock): Delete. + (pinfo::unlock): Delete. + * winsup.h (get_exit_lock): Delete declaration. + + 2005-10-03 Corinna Vinschen * uname.cc (uname): Disable use of GetNativeSystemInfo. diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h index e5ce58f4d..059e01d2e 100644 --- a/winsup/cygwin/cygheap.h +++ b/winsup/cygwin/cygheap.h @@ -415,6 +415,27 @@ class cygheap_fdenum : public cygheap_fdmanip } }; +class process_lock +{ + bool skip_unlock; +public: + process_lock (bool exiting = false) + { + cygheap->fdtab.lock (); + skip_unlock = exiting; + if (exiting && exit_state < ES_SET_MUTO) + { + exit_state = ES_SET_MUTO; + muto::set_exiting_thread (); + } + } + ~process_lock () + { + if (!skip_unlock) + cygheap->fdtab.unlock (); + } +}; + class child_info; void __stdcall cygheap_fixup_in_child (bool); extern "C" { diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 48a7b9fe0..6f82e1273 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -1021,7 +1021,7 @@ do_exit (int status) } #endif - get_exit_lock (); + process_lock until_exit (true); if (exit_state < ES_GLOBAL_DTORS) { @@ -1138,17 +1138,6 @@ _exit (int n) do_exit (((DWORD) n & 0xff) << 8); } -void -get_exit_lock () -{ - myself.lock (); - if (exit_state < ES_SET_MUTO) - { - exit_state = ES_SET_MUTO; - muto::set_exiting_thread (); - } -} - extern "C" void __api_fatal (const char *fmt, ...) { diff --git a/winsup/cygwin/dtable.h b/winsup/cygwin/dtable.h index 202e288a1..b71b3f1db 100644 --- a/winsup/cygwin/dtable.h +++ b/winsup/cygwin/dtable.h @@ -89,6 +89,7 @@ public: friend class cygheap_fdget; friend class cygheap_fdnew; friend class cygheap_fdenum; + friend class process_lock; }; fhandler_base *build_fh_dev (const device&, const char * = NULL); diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 93a3e8067..b1315239d 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -26,6 +26,10 @@ details. */ #include "shared_info.h" #include "perprocess.h" #include "security.h" +#include "path.h" +#include "fhandler.h" +#include "dtable.h" +#include "cygheap.h" #define CALL_HANDLER_RETRY 20 @@ -1179,7 +1183,7 @@ signal_exit (int rc) TerminateProcess (hExeced, sigExeced = rc); } - get_exit_lock (); + process_lock until_exit (true); if (hExeced || exit_state) myself.exit (rc); diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index e77a4e6a3..5df86c730 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -59,7 +59,6 @@ set_myself (HANDLE h) #endif strace.hello (); debug_printf ("myself->dwProcessId %u", myself->dwProcessId); - myself.initialize_lock (); if (h) { /* here if execed */ @@ -140,7 +139,7 @@ pinfo::zap_cwd () void pinfo::exit (DWORD n) { - get_exit_lock (); + process_lock until_exit (); cygthread::terminate (); if (n != EXITCODE_NOSET) self->exitcode = EXITCODE_SET | n;/* We're really exiting. Record the UNIX exit code. */ @@ -390,6 +389,8 @@ _pinfo::commune_process (siginfo_t& si) if (process_sync) // FIXME: this test shouldn't be necessary ProtectHandle (process_sync); + process_lock now (false); + switch (si._si_commune._si_code) { case PICOM_CMDLINE: @@ -586,7 +587,7 @@ _pinfo::commune_request (__uint32_t code, ...) break; } - myself.lock (); + process_lock now (); locked = true; char name_buf[CYG_MAX_PATH]; request_sync = CreateSemaphore (&sec_none_nih, 0, LONG_MAX, @@ -665,8 +666,6 @@ out: ReleaseSemaphore (request_sync, 1, &res); ForceCloseHandle (request_sync); } - if (locked) - myself.unlock (); if (hp) CloseHandle (hp); if (fromthem) diff --git a/winsup/cygwin/pinfo.h b/winsup/cygwin/pinfo.h index 1462e5f6d..0c7a26413 100644 --- a/winsup/cygwin/pinfo.h +++ b/winsup/cygwin/pinfo.h @@ -149,7 +149,6 @@ class pinfo public: HANDLE rd_proc_pipe; HANDLE hProcess; - CRITICAL_SECTION _lock; bool waiter_ready; class cygthread *wait_thread; void init (pid_t, DWORD, HANDLE) __attribute__ ((regparm(3))); @@ -166,9 +165,6 @@ public: } void exit (DWORD n) __attribute__ ((noreturn, regparm(2))); void maybe_set_exit_code_from_windows () __attribute__ ((regparm(1))); - void initialize_lock () {InitializeCriticalSection (&_lock);} - void lock () {EnterCriticalSection (&_lock);} - void unlock () {LeaveCriticalSection (&_lock);} _pinfo *operator -> () const {return procinfo;} int operator == (pinfo *x) const {return x->procinfo == procinfo;} int operator == (pinfo &x) const {return x.procinfo == procinfo;} diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h index 004f5b90b..d31dd9abd 100644 --- a/winsup/cygwin/winsup.h +++ b/winsup/cygwin/winsup.h @@ -203,7 +203,6 @@ enum exit_states extern exit_states exit_state; void __stdcall do_exit (int) __attribute__ ((regparm (1), noreturn)); -void __stdcall get_exit_lock (); /* UID/GID */ void uinfo_init ();