]> git.unchartedbackwaters.co.uk Git - francis/libjit.git/commitdiff
make sure that backend initialization is done only once
authorAleksey Demakov <ademakov@gmail.com>
Tue, 19 Dec 2006 22:05:23 +0000 (22:05 +0000)
committerAleksey Demakov <ademakov@gmail.com>
Tue, 19 Dec 2006 22:05:23 +0000 (22:05 +0000)
ChangeLog
jit/jit-init.c
jit/jit-thread.c
jit/jit-thread.h

index f4465345272fb3ae42476d5e35d66c70eadd3ca1..9853442bb5b93307b31ebcd69556fc3ac78512a7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,14 @@
+2006-12-20  Aleksey Demakov  <ademakov@gmail.com>
+
+       * 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  <ktreichel@web.de>
 
        * 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  <ademakov@gmail.com>
 
index c1f8282ffbe8b2ac5ad63ec152de56570ba0a201..8e855f682d1f5b4601f0c0ae1ccc80c98b5937b2 100644 (file)
 @*/
 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);
 }
 
 /*@
index a013528d3f3f9c79c6af510d40a2b4f21fef715e..0e0a35c904cf5354cf100992368bdd5604abf45a 100644 (file)
 #endif
 #include <errno.h>
 
+/*
+ * 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();
 }
 
index b38da047363304aa0768e1b298feac199796b2e5..6d326b373cde489b707ba51ec97c58ee742a69f6 100644 (file)
@@ -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.
  */