From: Aleksey Demakov Date: Tue, 19 Dec 2006 22:05:23 +0000 (+0000) Subject: make sure that backend initialization is done only once X-Git-Tag: before.move.to.git~171 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=5abea97ffa4fbad4aa1d1f3a327740e71b139959;p=francis%2Flibjit.git make sure that backend initialization is done only once --- diff --git a/ChangeLog b/ChangeLog index f446534..9853442 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,14 @@ +2006-12-20 Aleksey Demakov + + * jit/jit-thread.h, jit/jit-thread.c: add _jit_global_lock mutex. + * jit/jit-init.c (jit_init): make sure that initialization is done + only once. + 2006-12-17 Klaus Treichel * include/jit/jit-function.h, jit/jit-function.c: Add the function - jit_function_from_vtable_pointer to convert a vtable pointer back to the - jit_function_t. + jit_function_from_vtable_pointer to convert a vtable pointer back to + the jit_function_t. 2006-11-29 Aleksey Demakov diff --git a/jit/jit-init.c b/jit/jit-init.c index c1f8282..8e855f6 100644 --- a/jit/jit-init.c +++ b/jit/jit-init.c @@ -37,9 +37,20 @@ @*/ void jit_init(void) { + static int init_done = 0; + /* Make sure that the thread subsystem is initialized */ _jit_thread_init(); + /* Make sure that the initialization is done only once + (requires the global lock initialized above) */ + jit_mutex_lock(&_jit_global_lock); + if(init_done) + { + goto done; + } + init_done = 1; + #ifdef JIT_USE_SIGNALS /* Initialize the signal handlers */ _jit_signal_init(); @@ -47,6 +58,9 @@ void jit_init(void) /* Initialize the backend */ _jit_init_backend(); + +done: + jit_mutex_unlock(&_jit_global_lock); } /*@ diff --git a/jit/jit-thread.c b/jit/jit-thread.c index a013528..0e0a35c 100644 --- a/jit/jit-thread.c +++ b/jit/jit-thread.c @@ -34,6 +34,11 @@ #endif #include +/* + * Mutex that synchronizes global data initialization. + */ +jit_mutex_t _jit_global_lock; + #if defined(JIT_THREADS_PTHREAD) /* @@ -46,6 +51,8 @@ static pthread_key_t control_key; */ static void init_pthread(void) { + jit_mutex_create(&_jit_global_lock); + /* Allocate a thread-specific variable for the JIT's thread control object, and arrange for it to be freed when the thread exits or is otherwise terminated */ @@ -64,6 +71,8 @@ static DWORD control_key; */ static void init_win32_thread(void) { + jit_mutex_create(&_jit_global_lock); + control_key = TlsAlloc(); } diff --git a/jit/jit-thread.h b/jit/jit-thread.h index b38da04..6d326b3 100644 --- a/jit/jit-thread.h +++ b/jit/jit-thread.h @@ -115,6 +115,11 @@ typedef int jit_mutex_t; #endif +/* + * Mutex that synchronizes global data initialization. + */ +extern jit_mutex_t _jit_global_lock; + /* * Define the primitive monitor operations. */