@@ -1,10 +1,11 @@
11#include <stdlib.h>
22#include <stdio.h>
33#include <string.h>
4−#include <unistd.h>
54#include <stdarg.h>
65#include <assert.h>
6+#ifdef HAS_PTHREAD
77#include <pthread.h>
8+#endif
89
910#include "idris_rts.h"
1011#include "idris_gc.h"
@@ -30,7 +31,7 @@ VM* init_vm(int stack_size, size_t heap_size,
3031
3132 vm->ret = NULL;
3233 vm->reg1 = NULL;
33−
34+#ifdef HAS_PTHREAD
3435 vm->inbox = malloc(1024*sizeof(VAL));
3536 memset(vm->inbox, 0, 1024*sizeof(VAL));
3637 vm->inbox_end = vm->inbox + 1024;
@@ -53,7 +54,7 @@ VM* init_vm(int stack_size, size_t heap_size,
5354
5455 vm->max_threads = max_threads;
5556 vm->processes = 0;
56−
57+#endif
5758 STATS_LEAVE_INIT(vm->stats)
5859 return vm;
5960}
@@ -61,14 +62,16 @@ VM* init_vm(int stack_size, size_t heap_size,
6162Stats terminate(VM* vm) {
6263 Stats stats = vm->stats;
6364 STATS_ENTER_EXIT(stats)
64−
65+#ifdef HAS_PTHREAD
6566 free(vm->inbox);
67+#endif
6668 free(vm->valstack);
6769 free_heap(&(vm->heap));
68−
70+#ifdef HAS_PTHREAD
6971 pthread_mutex_destroy(&(vm -> inbox_lock));
7072 pthread_mutex_destroy(&(vm -> inbox_block));
7173 pthread_cond_destroy(&(vm -> inbox_waiting));
74+#endif
7275 free(vm);
7376
7477 STATS_LEAVE_EXIT(stats)
@@ -79,18 +82,21 @@ void idris_requireAlloc(VM* vm, size_t size) {
7982 if (!(vm->heap.next + size < vm->heap.end)) {
8083 idris_gc(vm);
8184 }
82−
85+#ifdef HAS_PTHREAD
8386 int lock = vm->processes > 0;
8487 if (lock) { // We only need to lock if we're in concurrent mode
8588 pthread_mutex_lock(&vm->alloc_lock);
8689 }
90+#endif
8791}
8892
8993void idris_doneAlloc(VM* vm) {
94+#ifdef HAS_PTHREAD
9095 int lock = vm->processes > 0;
9196 if (lock) { // We only need to lock if we're in concurrent mode
9297 pthread_mutex_unlock(&vm->alloc_lock);
9398 }
99+#endif
94100}
95101
96102int space(VM* vm, size_t size) {
@@ -99,16 +105,18 @@ int space(VM* vm, size_t size) {
99105
100106void* allocate(VM* vm, size_t size, int outerlock) {
101107// return malloc(size);
108+#ifdef HAS_PTHREAD
102109 int lock = vm->processes > 0 && !outerlock;
103110
104111 if (lock) { // not message passing
105112 pthread_mutex_lock(&vm->alloc_lock);
106113 }
114+#endif
107115
108116 if ((size & 7)!=0) {
109117 size = 8 + ((size >> 3) << 3);
110118 }
111−
119+
112120 size_t chunk_size = size + sizeof(size_t);
113121
114122 if (vm->heap.next + chunk_size < vm->heap.end) {
@@ -120,16 +128,19 @@ void* allocate(VM* vm, size_t size, int outerlock) {
120128 assert(vm->heap.next <= vm->heap.end);
121129
122130 memset(ptr, 0, size);
123−
131+#ifdef HAS_PTHREAD
124132 if (lock) { // not message passing
125133 pthread_mutex_unlock(&vm->alloc_lock);
126134 }
135+#endif
127136 return ptr;
128137 } else {
129138 idris_gc(vm);
139+#ifdef HAS_PTHREAD
130140 if (lock) { // not message passing
131141 pthread_mutex_unlock(&vm->alloc_lock);
132142 }
143+#endif
133144 return allocate(vm, size, 0);
134145 }
135146
@@ -187,7 +198,7 @@ VAL MKPTR(VM* vm, void* ptr) {
187198 return cl;
188199}
189200
190−VAL MKMPTR(VM* vm, void* ptr, int size) {
201+VAL MKMPTR(VM* vm, void* ptr, size_t size) {
191202 Closure* cl = allocate(vm, sizeof(Closure) +
192203 sizeof(ManagedPtr) + size, 0);
193204 SETTY(cl, MANAGEDPTR);
@@ -222,7 +233,7 @@ VAL MKPTRc(VM* vm, void* ptr) {
222233 return cl;
223234}
224235
225−VAL MKMPTRc(VM* vm, void* ptr, int size) {
236+VAL MKMPTRc(VM* vm, void* ptr, size_t size) {
226237 Closure* cl = allocate(vm, sizeof(Closure) +
227238 sizeof(ManagedPtr) + size, 1);
228239 SETTY(cl, MANAGEDPTR);
@@ -760,6 +771,7 @@ typedef struct {
760771 VAL arg;
761772} ThreadData;
762773
774+#ifdef HAS_PTHREAD
763775void* runThread(void* arg) {
764776 ThreadData* td = (ThreadData*)arg;
765777 VM* vm = td->vm;
@@ -949,7 +961,7 @@ VAL idris_recvMessage(VM* vm) {
949961
950962 return msg;
951963}
952−
964+#endif
953965int __idris_argc;
954966char **__idris_argv;
955967