summaryrefslogtreecommitdiff
path: root/libgo/runtime/lock_sema.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/runtime/lock_sema.c')
-rw-r--r--libgo/runtime/lock_sema.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/libgo/runtime/lock_sema.c b/libgo/runtime/lock_sema.c
index 000b9fcf70..ef611fb36a 100644
--- a/libgo/runtime/lock_sema.c
+++ b/libgo/runtime/lock_sema.c
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin netbsd openbsd plan9 windows
+// +build darwin nacl netbsd openbsd plan9 solaris windows
#include "runtime.h"
@@ -167,7 +167,9 @@ runtime_notesleep(Note *n)
return;
}
// Queued. Sleep.
+ m->blocked = true;
runtime_semasleep(-1);
+ m->blocked = false;
}
static bool
@@ -190,18 +192,23 @@ notetsleep(Note *n, int64 ns, int64 deadline, M *mp)
if(ns < 0) {
// Queued. Sleep.
+ m->blocked = true;
runtime_semasleep(-1);
+ m->blocked = false;
return true;
}
deadline = runtime_nanotime() + ns;
for(;;) {
// Registered. Sleep.
+ m->blocked = true;
if(runtime_semasleep(ns) >= 0) {
+ m->blocked = false;
// Acquired semaphore, semawakeup unregistered us.
// Done.
return true;
}
+ m->blocked = false;
// Interrupted or timed out. Still registered. Semaphore not acquired.
ns = deadline - runtime_nanotime();
@@ -223,8 +230,10 @@ notetsleep(Note *n, int64 ns, int64 deadline, M *mp)
} else if(mp == (M*)LOCKED) {
// Wakeup happened so semaphore is available.
// Grab it to avoid getting out of sync.
+ m->blocked = true;
if(runtime_semasleep(-1) < 0)
runtime_throw("runtime: unable to acquire - semaphore out of sync");
+ m->blocked = false;
return true;
} else
runtime_throw("runtime: unexpected waitm - semaphore out of sync");