@@ -5,72 +5,77 @@
55
66typedef struct {
77 pthread_mutex_t m_id;
8−} Mutex;
8+} IdrisMutex;
99
1010typedef struct {
1111 pthread_t t_id;
12−} Thread;
12+} IdrisThread;
1313
14−Mutex** ms = NULL;
15−int mutexes = 0;
14+IdrisMutex** idris_ms = NULL;
15+int idris_mutexes = 0;
1616
17−int idris_newLock(int sem)
17+int idris_newLock()
1818{
1919 pthread_mutex_t m;
2020
2121 pthread_mutex_init(&m, NULL);
22− Mutex* newm = EMALLOC(sizeof(Mutex));
22+ IdrisMutex* newm = EMALLOC(sizeof(IdrisMutex));
2323 newm->m_id = m;
2424
2525 // Increase space for the mutexes
26− if (ms==NULL) {
27− ms = (Mutex**)EMALLOC(sizeof(Mutex*));
28− mutexes=1;
26+ if (idris_ms==NULL) {
27+ idris_ms = (IdrisMutex**)EMALLOC(sizeof(IdrisMutex*));
28+ idris_mutexes=1;
2929 } else {
30− ms = (Mutex**)(EREALLOC(ms, sizeof(Mutex*)*(mutexes+1)));
31− mutexes++;
30+ idris_ms = (IdrisMutex**)(EREALLOC(idris_ms, sizeof(IdrisMutex*)*(idris_mutexes+1)));
31+ idris_mutexes++;
3232 }
3333
34− ms[mutexes-1] = newm;
35− return mutexes-1;
34+ idris_ms[idris_mutexes-1] = newm;
35+ return idris_mutexes-1;
3636}
3737
3838void idris_doLock(int lock)
3939{
40− pthread_mutex_lock(&(ms[lock]->m_id));
40+ pthread_mutex_lock(&(idris_ms[lock]->m_id));
4141}
4242
4343void idris_doUnlock(int lock)
4444{
45− pthread_mutex_unlock(&(ms[lock]->m_id));
45+ pthread_mutex_unlock(&(idris_ms[lock]->m_id));
4646}
4747
48−struct threadinfo {
48+struct idris_threadinfo {
4949 void* proc;
5050 void* result;
5151};
5252
5353void* idris_runThread(void* th_in) {
54− struct threadinfo* th = (struct threadinfo*)th_in;
55− void* v = DO_EVAL(th->proc, 1);
54+ printf("IN THREAD\n");
55+ struct idris_threadinfo* th = (struct idris_threadinfo*)th_in;
56+ printf("using %d\n", th_in);
57+ void* v = DO_EVAL(th_in, 1);
5658 th->result = v;
5759 return v;
5860}
5961
6062void idris_doFork(void* proc)
6163{
62− pthread_t* t = EMALLOC(sizeof(pthread_t));
63− struct threadinfo th;
64+ printf("FORKING!\n");
65+ pthread_t* t = malloc(sizeof(pthread_t));
66+ struct idris_threadinfo th;
67+ printf("in %d\n", proc);
6468 th.proc = proc;
6569 th.result = NULL;
66− pthread_create(t, NULL, idris_runThread, &th);
70+ pthread_create(t, NULL, idris_runThread, proc);
71+ printf("FORKED!\n");
6772}
6873
6974void* idris_doWithin(int limit, void* proc, void* doOnFail)
7075{
7176 pthread_t* t = EMALLOC(sizeof(pthread_t));
7277// printf("CREATING THREAD %d\n", t);
73− struct threadinfo th;
78+ struct idris_threadinfo th;
7479 th.proc = proc;
7580 th.result = NULL;
7681