various race conditions.
R=r
DELTA=43 (29 added, 5 deleted, 9 changed)
OCL=23608
CL=23611
diff --git a/src/runtime/rt1_amd64_darwin.c b/src/runtime/rt1_amd64_darwin.c
index b614756..c476f89 100644
--- a/src/runtime/rt1_amd64_darwin.c
+++ b/src/runtime/rt1_amd64_darwin.c
@@ -277,19 +277,25 @@
void
lock(Lock *l)
{
+ if(m->locks < 0)
+ throw("lock count");
+ m->locks++;
+
// Allocate semaphore if needed.
if(l->sema == 0)
initsema(&l->sema);
if(xadd(&l->key, 1) > 1) // someone else has it; wait
mach_semacquire(l->sema);
- m->locks++;
}
void
unlock(Lock *l)
{
m->locks--;
+ if(m->locks < 0)
+ throw("lock count");
+
if(xadd(&l->key, -1) > 0) // someone else is waiting
mach_semrelease(l->sema);
}