first cut at multithreading. works on Linux.
* kick off new os procs (machs) as needed
* add sys·sleep for testing
* add Lock, Rendez
* properly lock mal, sys·newproc, scheduler
* linux syscall arg #4 is in R10, not CX
* chans are not multithread-safe yet
* multithreading disabled by default;
set $gomaxprocs=2 (or 1000) to turn it on
This should build on OS X but may not.
Rob and I will fix soon after submitting.
TBR=r
OCL=13784
CL=13842
diff --git a/src/runtime/rt1_amd64_darwin.c b/src/runtime/rt1_amd64_darwin.c
index e0d2cb8..3878649 100644
--- a/src/runtime/rt1_amd64_darwin.c
+++ b/src/runtime/rt1_amd64_darwin.c
@@ -5,7 +5,6 @@
#include "runtime.h"
#include "signals.h"
-
typedef uint64 __uint64_t;
/* From /usr/include/mach/i386/_structs.h */
@@ -174,3 +173,75 @@
sys·sigaction(i, &a, (void*)0);
}
}
+
+static void
+unimplemented(int8 *name)
+{
+ prints(name);
+ prints(" not implemented\n");
+ *(int32*)1231 = 1231;
+}
+
+void
+sys·sleep(int64 ms)
+{
+ unimplemented("sleep");
+}
+
+void
+lock(Lock *l)
+{
+ if(xadd(&l->key, 1) == 1)
+ return;
+ unimplemented("lock wait");
+}
+
+void
+unlock(Lock *l)
+{
+ if(xadd(&l->key, -1) == 0)
+ return;
+ unimplemented("unlock wakeup");
+}
+
+void
+rsleep(Rendez *r)
+{
+ unimplemented("rsleep");
+
+ // dumb implementation:
+ r->sleeping = 1;
+ unlock(r->l);
+ while(r->sleeping)
+ ;
+ lock(r->l);
+}
+
+void
+rwakeup(Rendez *r)
+{
+ unimplemented("rwakeup");
+
+ // dumb implementation:
+ r->sleeping = 0;
+}
+
+void
+rwakeupandunlock(Rendez *r)
+{
+ // dumb implementation:
+ rwakeup(r);
+ unlock(r->l);
+}
+
+void
+newosproc(M *mm, G *gg, void *stk, void (*fn)(void*), void *arg)
+{
+ unimplemented("newosproc");
+}
+
+int32
+getprocid(void)
+{
+ return 0;
+}