Native threads almost working
[cacao.git] / jit / jit.c
index 47a42cafad1c305cc86e98a252a6c2c8938041d7..534955899dbd331d5617d0f9948d582b84b45aa6 100644 (file)
--- a/jit/jit.c
+++ b/jit/jit.c
@@ -29,7 +29,7 @@
 
    Changes: Edwin Steiner
 
-   $Id: jit.c 941 2004-03-06 17:27:56Z jowenn $
+   $Id: jit.c 991 2004-03-29 11:22:34Z stefan $
 
 */
 
@@ -1439,6 +1439,7 @@ static void* do_nothing_function()
 
 methodptr jit_compile(methodinfo *m)
 {
+       static bool jitrunning;
        s4 dumpsize;
        s8 starttime = 0;
        s8 stoptime  = 0;
@@ -1453,7 +1454,7 @@ methodptr jit_compile(methodinfo *m)
        count_methods++;
 
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-       pthread_mutex_lock(&compiler_mutex);
+       compiler_lock();
 #endif
 
 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
@@ -1481,6 +1482,10 @@ methodptr jit_compile(methodinfo *m)
                log_text(logtext);
 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
                intsRestore();                             /* enable interrupts again */
+#endif
+               jitrunning = false;
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+               compiler_unlock();
 #endif
                return (methodptr) do_nothing_function;    /* return empty method     */
        }
@@ -1508,6 +1513,10 @@ methodptr jit_compile(methodinfo *m)
                class_init(m->class);
        }
 
+       if (jitrunning)
+               panic("Compiler lock recursion");
+       jitrunning = true;
+
        /* initialisation of variables and subsystems */
 
        isleafmethod = true;
@@ -1605,13 +1614,13 @@ methodptr jit_compile(methodinfo *m)
 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
        intsRestore();    /* enable interrupts again */
 #endif
-
+       jitrunning = false;
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-       pthread_mutex_unlock(&compiler_mutex);
+       compiler_unlock();
 #endif
 
        /* return pointer to the methods entry point */
-       
+
        LOG_STEP("Done compiling");
        return m->entrypoint;
 }