adding thread support w/ locks
[IRC.git] / Robust / src / Runtime / thread.c
1 #include "runtime.h"
2 #include <sys/types.h>
3 #include <unistd.h>
4 #include <errno.h>
5 #include <stdlib.h>
6 #include "thread.h"
7
8
9 #include <stdio.h>
10 int threadcount;
11 pthread_mutex_t gclock;
12 pthread_mutex_t gclistlock;
13 pthread_cond_t gccond;
14 pthread_mutex_t objlock;
15 pthread_cond_t objcond;
16
17 void initializethreads() {
18   threadcount=1;
19   pthread_mutex_init(&gclock, NULL);
20   pthread_mutex_init(&gclistlock, NULL);
21   pthread_cond_init(&gccond, NULL);
22   pthread_mutex_init(&objlock,NULL);
23   pthread_cond_init(&objcond,NULL);
24 }
25
26 void initthread(struct ___Thread___ * ___this___) {
27 #ifdef PRECISE_GC
28   struct ___Thread______staticStart____L___Thread____params p={1, NULL, ___this___};
29   ___Thread______staticStart____L___Thread___(&p);
30 #else
31   ___Thread______staticStart____L___Thread___(___this___);
32 #endif
33   pthread_mutex_lock(&gclistlock);
34   threadcount--;
35   pthread_cond_signal(&gccond);
36   pthread_mutex_unlock(&gclistlock);
37 }
38
39 void CALL01(___Thread______nativeCreate____, struct ___Thread___ * ___this___) {
40   pthread_t thread;
41   pthread_mutex_lock(&gclistlock);
42   threadcount++;
43   pthread_mutex_unlock(&gclistlock);
44   pthread_create(&thread, NULL,(void * (*)(void *)) &initthread, VAR(___this___));
45 }