Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2005-03-06 23:21:30 +0300
committerChristopher Faylor <me@cgf.cx>2005-03-06 23:21:30 +0300
commit3f02a8d0f4ca99d7e82fb678db8d50819ce4156e (patch)
tree4a286194ec404b446526d9c27542eea27ac01aab /winsup
parenta50b6b2dcd76cfb494617c37f93ebed175d60560 (diff)
* 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.
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/dcrt0.cc1
-rw-r--r--winsup/cygwin/sync.cc29
-rw-r--r--winsup/cygwin/sync.h2
3 files changed, 25 insertions, 7 deletions
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index df639c20f..b269b21d1 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -574,6 +574,7 @@ void __stdcall
dll_crt0_0 ()
{
wincap.init ();
+ muto::init ();
initial_env ();
char zeros[sizeof (child_proc_info->zero)] = {0};
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;
}
diff --git a/winsup/cygwin/sync.h b/winsup/cygwin/sync.h
index 7e8b60c10..90e70a243 100644
--- a/winsup/cygwin/sync.h
+++ b/winsup/cygwin/sync.h
@@ -17,6 +17,7 @@ details. */
class muto
{
static DWORD exiting_thread;
+ static CRITICAL_SECTION init_lock;
LONG sync; /* Used to serialize access to this class. */
LONG waiters; /* Number of threads waiting for lock. */
HANDLE bruteforce; /* event handle used to control waiting for lock. */
@@ -39,6 +40,7 @@ public:
void upforgrabs () {tls = this;} // just set to an invalid address
void grab () __attribute__ ((regparm (1)));
static void set_exiting_thread () {exiting_thread = GetCurrentThreadId ();}
+ static void init ();
};
extern muto muto_start;