From 3f02a8d0f4ca99d7e82fb678db8d50819ce4156e Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Sun, 6 Mar 2005 20:21:30 +0000 Subject: * sync.h (sync::init_lock): Declare new static member. (sync::init()): Declare new static function. * sync.cc (sync::init): Define. (sync::init): Lock attempt to initialize a muto to stop multiple threads from colliding. * dcrt0.cc (dll_crt0_0): Initialize muto environment. --- winsup/cygwin/sync.cc | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'winsup/cygwin/sync.cc') diff --git a/winsup/cygwin/sync.cc b/winsup/cygwin/sync.cc index a7994048d..f946bc705 100644 --- a/winsup/cygwin/sync.cc +++ b/winsup/cygwin/sync.cc @@ -28,6 +28,13 @@ details. */ #undef WaitForSingleObject DWORD NO_COPY muto::exiting_thread; +CRITICAL_SECTION NO_COPY muto::init_lock; + +void +muto::init () +{ + InitializeCriticalSection (&init_lock); +} void muto::grab () @@ -39,15 +46,23 @@ muto::grab () muto * muto::init (const char *s) { - waiters = -1; - /* Create event which is used in the fallback case when blocking is necessary */ - if (!(bruteforce = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL))) + muto *res = this; + EnterCriticalSection (&init_lock); + if (!bruteforce) { - DWORD oerr = GetLastError (); - SetLastError (oerr); - return NULL; + waiters = -1; + bruteforce = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL); + /* Create event which is used in the fallback case when blocking is necessary */ + if (bruteforce) + name = s; + else + { + DWORD oerr = GetLastError (); + SetLastError (oerr); + res = NULL; + } } - name = s; + LeaveCriticalSection (&init_lock); return this; } -- cgit v1.2.3