adding thread support w/ locks
[IRC.git] / Robust / src / Runtime / thread.c
index 99e79cef59514d75bee960580ca4e2870838388e..2f745651e5d1f355ad9ddcc73fcefe0a67188c25 100644 (file)
@@ -7,18 +7,20 @@
 
 
 #include <stdio.h>
-pthread_mutex_t threadtable;
 int threadcount;
 pthread_mutex_t gclock;
 pthread_mutex_t gclistlock;
 pthread_cond_t gccond;
+pthread_mutex_t objlock;
+pthread_cond_t objcond;
 
 void initializethreads() {
-  pthread_mutex_init(&threadtable,NULL);
   threadcount=1;
   pthread_mutex_init(&gclock, NULL);
   pthread_mutex_init(&gclistlock, NULL);
   pthread_cond_init(&gccond, NULL);
+  pthread_mutex_init(&objlock,NULL);
+  pthread_cond_init(&objcond,NULL);
 }
 
 void initthread(struct ___Thread___ * ___this___) {
@@ -28,18 +30,16 @@ void initthread(struct ___Thread___ * ___this___) {
 #else
   ___Thread______staticStart____L___Thread___(___this___);
 #endif
-  pthread_mutex_lock(&threadtable);
-  threadcount--;
-  pthread_mutex_unlock(&threadtable);
   pthread_mutex_lock(&gclistlock);
+  threadcount--;
   pthread_cond_signal(&gccond);
   pthread_mutex_unlock(&gclistlock);
 }
 
 void CALL01(___Thread______nativeCreate____, struct ___Thread___ * ___this___) {
   pthread_t thread;
-  pthread_mutex_lock(&threadtable);
+  pthread_mutex_lock(&gclistlock);
   threadcount++;
-  pthread_mutex_unlock(&threadtable);
+  pthread_mutex_unlock(&gclistlock);
   pthread_create(&thread, NULL,(void * (*)(void *)) &initthread, VAR(___this___));
 }