Include options.h/statistics.h.
[cacao.git] / threads / locks.c
index f200794c816d0228f274d974f9b3e2f13e8d2ae2..b550f3208cdd73da201e81b78531103e4e34294d 100644 (file)
 #include "tables.h"
 #include "native.h"
 #include "loader.h"
+#include "toolbox/memory.h"
 
-static classinfo *class_java_lang_IllegalMonitorStateException;
+
+#if !defined(NATIVE_THREADS)
 
 extern thread* currentThread;
 
@@ -50,7 +52,7 @@ initLocks (void)
     int i;
 
     mutexHashTableSize = MUTEX_HASH_TABLE_SIZE;
-    mutexHashTable = (mutexHashEntry*)malloc(sizeof(mutexHashEntry) * mutexHashTableSize);
+    mutexHashTable = MNEW(mutexHashEntry, mutexHashTableSize);
     mutexHashMask = (mutexHashTableSize - 1) << 3;
 
     for (i = 0; i < mutexHashTableSize; ++i)
@@ -64,8 +66,7 @@ initLocks (void)
     }
 
     mutexOverflowTableSize = MUTEX_OVERFLOW_TABLE_SIZE;
-    mutexOverflowTable = (mutexHashEntry*)malloc(sizeof(mutexHashEntry)
-                                                                                                * mutexOverflowTableSize);
+    mutexOverflowTable = MNEW(mutexHashEntry, mutexOverflowTableSize);
 
     firstFreeOverflowEntry = &mutexOverflowTable[0];
 
@@ -81,8 +82,7 @@ initLocks (void)
     mutexOverflowTable[i - 1].next = 0;
 
     conditionHashTableSize = CONDITION_HASH_TABLE_SIZE;
-    conditionHashTable = (conditionHashEntry*)malloc(sizeof(conditionHashEntry)
-                                                                                                        * conditionHashTableSize);
+    conditionHashTable = MNEW(conditionHashEntry, conditionHashTableSize);
     conditionHashMask = (conditionHashTableSize - 1) << 3;
 
     for (i = 0; i < conditionHashTableSize; ++i)
@@ -91,12 +91,9 @@ initLocks (void)
                conditionHashTable[i].condition.cvWaiters = 0;
                conditionHashTable[i].condition.mux = 0;
     }
-
-       /* Load exception classes */
-    loader_load_sysclass(&class_java_lang_IllegalMonitorStateException,
-                         utf_new_char("java/lang/IllegalMonitorStateException"));
 }
 
+
 /*
  * Reorders part of the condition hash table. Must be called after an entry has been deleted.
  */
@@ -456,7 +453,7 @@ internal_unlock_mutex(iMux* mux)
                if (mux->muxWaiters != 0)
                {
                        tid = mux->muxWaiters;
-                       mux->muxWaiters = tid->next;
+                       mux->muxWaiters = tid->vmThread->next;
                        iresumeThread(tid);
                }
     }
@@ -475,7 +472,7 @@ internal_wait_cond(iMux* mux, iCv* cv, s8 timeout)
     DBG( fprintf(stderr, "waiting on %p\n", cv); );
 
     if (mux->holder != currentThread) {
-               *exceptionptr = native_new_and_init(class_java_lang_IllegalMonitorStateException);
+               *exceptionptr = new_exception(string_java_lang_IllegalMonitorStateException);
     }
 
        assert(blockInts > 0);
@@ -488,7 +485,7 @@ internal_wait_cond(iMux* mux, iCv* cv, s8 timeout)
     /* If there's anyone waiting here, wake them up */
     if (mux->muxWaiters != 0) {
                tid = mux->muxWaiters;
-               mux->muxWaiters = tid->next;
+               mux->muxWaiters = tid->vmThread->next;
                iresumeThread(tid);
     }
 
@@ -519,7 +516,7 @@ internal_signal_cond (iCv* cv)
     }
 
     if (cv->mux->holder != currentThread) {
-               *exceptionptr = native_new_and_init(class_java_lang_IllegalMonitorStateException);
+               *exceptionptr = new_exception(string_java_lang_IllegalMonitorStateException);
     }
 
        assert(blockInts > 0);
@@ -529,10 +526,10 @@ internal_signal_cond (iCv* cv)
                DBG( fprintf(stderr, "releasing a waiter\n"); );
 
                tid = cv->cvWaiters;
-               cv->cvWaiters = tid->next;
+               cv->cvWaiters = tid->vmThread->next;
 
                /* Place it on mux list */
-               tid->next = cv->mux->muxWaiters;
+               tid->vmThread->next = cv->mux->muxWaiters;
                cv->mux->muxWaiters = tid;
     }
 }
@@ -551,14 +548,14 @@ internal_broadcast_cond (iCv* cv)
     }
 
     if (cv->mux->holder != currentThread) {
-               *exceptionptr = native_new_and_init(class_java_lang_IllegalMonitorStateException);
+               *exceptionptr = new_exception(string_java_lang_IllegalMonitorStateException);
     }
 
        assert(blockInts > 0);
 
     /* Find the end of the cv list */
     if (cv->cvWaiters) {
-               for (tidp = &cv->cvWaiters; *tidp != 0; tidp = &(*tidp)->next)
+               for (tidp = &cv->cvWaiters; *tidp != 0; tidp = &(*tidp)->vmThread->next)
                        ;
 
                /* Place entire cv list on mux list */
@@ -567,3 +564,5 @@ internal_broadcast_cond (iCv* cv)
                cv->cvWaiters = 0;
     }
 }
+
+#endif