aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime/proc.c
diff options
context:
space:
mode:
authorDmitriy Vyukov <dvyukov@google.com>2012-09-18 21:15:46 +0400
committerDmitriy Vyukov <dvyukov@google.com>2012-09-18 21:15:46 +0400
commitf20fd87384d152ed91439e824333fbb78688e741 (patch)
tree555ce56d7b34e0eac187ef3e65d3dd8578054553 /src/pkg/runtime/proc.c
parente4389c008a223213fc3f506756f38d695cf60d40 (diff)
downloadgo-f20fd87384d152ed91439e824333fbb78688e741.tar.xz
runtime: refactor goroutine blocking
The change is a preparation for the new scheduler. It introduces runtime.park() function, that will atomically unlock the mutex and park the goroutine. It will allow to remove the racy readyonstop flag that is difficult to implement w/o the global scheduler mutex. R=rsc, remyoudompheng, dave CC=golang-dev https://golang.org/cl/6501077
Diffstat (limited to 'src/pkg/runtime/proc.c')
-rw-r--r--src/pkg/runtime/proc.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c
index 2d837c537f..d763d01b08 100644
--- a/src/pkg/runtime/proc.c
+++ b/src/pkg/runtime/proc.c
@@ -951,6 +951,18 @@ runtime·gosched(void)
runtime·mcall(schedule);
}
+// Puts the current goroutine into a waiting state and unlocks the lock.
+// The goroutine can be made runnable again by calling runtime·ready(gp).
+void
+runtime·park(void (*unlockf)(Lock*), Lock *lock, int8 *reason)
+{
+ g->status = Gwaiting;
+ g->waitreason = reason;
+ if(unlockf)
+ unlockf(lock);
+ runtime·gosched();
+}
+
// The goroutine g is about to enter a system call.
// Record that it's not using the cpu anymore.
// This is called only from the go syscall library and cgocall,