add primitive support for multithreading
[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 pthread_mutex_t threadtable;
11 int threadcount;
12 pthread_mutex_t gclock;
13 pthread_mutex_t gclistlock;
14 pthread_cond_t gccond;
15
16 void initializethreads() {
17   pthread_mutex_init(&threadtable,NULL);
18   threadcount=1;
19   pthread_mutex_init(&gclock, NULL);
20   pthread_mutex_init(&gclistlock, NULL);
21   pthread_cond_init(&gccond, NULL);
22 }
23
24 void initthread(struct ___Thread___ * ___this___) {
25 #ifdef PRECISE_GC
26   struct ___Thread______staticStart____L___Thread____params p={1, NULL, ___this___};
27   ___Thread______staticStart____L___Thread___(&p);
28 #else
29   ___Thread______staticStart____L___Thread___(___this___);
30 #endif
31   pthread_mutex_lock(&threadtable);
32   threadcount--;
33   pthread_mutex_unlock(&threadtable);
34 }
35
36 void CALL01(___Thread______nativeCreate____, struct ___Thread___ * ___this___) {
37   pthread_t thread;
38   pthread_mutex_lock(&threadtable);
39   threadcount++;
40   pthread_mutex_unlock(&threadtable);
41   pthread_create(&thread, NULL,(void * (*)(void *)) &initthread, VAR(___this___));
42 }