* 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.
This commit is contained in:
Christopher Faylor 2005-03-06 20:21:30 +00:00
parent a50b6b2dcd
commit 3f02a8d0f4
3 changed files with 25 additions and 7 deletions

@ -574,6 +574,7 @@ void __stdcall
dll_crt0_0 () dll_crt0_0 ()
{ {
wincap.init (); wincap.init ();
muto::init ();
initial_env (); initial_env ();
char zeros[sizeof (child_proc_info->zero)] = {0}; char zeros[sizeof (child_proc_info->zero)] = {0};

@ -28,6 +28,13 @@ details. */
#undef WaitForSingleObject #undef WaitForSingleObject
DWORD NO_COPY muto::exiting_thread; DWORD NO_COPY muto::exiting_thread;
CRITICAL_SECTION NO_COPY muto::init_lock;
void
muto::init ()
{
InitializeCriticalSection (&init_lock);
}
void void
muto::grab () muto::grab ()
@ -39,15 +46,23 @@ muto::grab ()
muto * muto *
muto::init (const char *s) muto::init (const char *s)
{ {
waiters = -1; muto *res = this;
/* Create event which is used in the fallback case when blocking is necessary */ EnterCriticalSection (&init_lock);
if (!(bruteforce = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL))) if (!bruteforce)
{ {
DWORD oerr = GetLastError (); waiters = -1;
SetLastError (oerr); bruteforce = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL);
return 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; return this;
} }

@ -17,6 +17,7 @@ details. */
class muto class muto
{ {
static DWORD exiting_thread; static DWORD exiting_thread;
static CRITICAL_SECTION init_lock;
LONG sync; /* Used to serialize access to this class. */ LONG sync; /* Used to serialize access to this class. */
LONG waiters; /* Number of threads waiting for lock. */ LONG waiters; /* Number of threads waiting for lock. */
HANDLE bruteforce; /* event handle used to control 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 upforgrabs () {tls = this;} // just set to an invalid address
void grab () __attribute__ ((regparm (1))); void grab () __attribute__ ((regparm (1)));
static void set_exiting_thread () {exiting_thread = GetCurrentThreadId ();} static void set_exiting_thread () {exiting_thread = GetCurrentThreadId ();}
static void init ();
}; };
extern muto muto_start; extern muto muto_start;