diff options
author | Russ Cox <rsc@golang.org> | 2014-11-11 17:08:33 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2014-11-11 17:08:33 -0500 |
commit | 2f5cc193d9daa4c45f45f6c23fd5990d050bd9ec (patch) | |
tree | e7802e66ac54d0fca77bab86c3803f1e224c629b /src/runtime/proc.go | |
parent | e67e97309976d8397061c94c8416bafc11f94b02 (diff) | |
download | go-2f5cc193d9daa4c45f45f6c23fd5990d050bd9ec.tar.gz |
[dev.cc] runtime: convert scheduler from C to Go
The conversion was done with an automated tool and then
modified only as necessary to make it compile and run.
[This CL is part of the removal of C code from package runtime.
See golang.org/s/dev.cc for an overview.]
LGTM=r
R=r, daniel.morsing
CC=austin, dvyukov, golang-codereviews, iant, khr
https://codereview.appspot.com/172260043
Diffstat (limited to 'src/runtime/proc.go')
-rw-r--r-- | src/runtime/proc.go | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 5b8c7d8ae..140717535 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -6,8 +6,6 @@ package runtime import "unsafe" -func newsysmon() - func runtime_init() func main_init() func main_main() @@ -55,6 +53,24 @@ func main() { memstats.enablegc = true // now that runtime is initialized, GC is okay + if iscgo { + if _cgo_thread_start == nil { + gothrow("_cgo_thread_start missing") + } + if _cgo_malloc == nil { + gothrow("_cgo_malloc missing") + } + if _cgo_free == nil { + gothrow("_cgo_free missing") + } + if _cgo_setenv == nil { + gothrow("_cgo_setenv missing") + } + if _cgo_unsetenv == nil { + gothrow("_cgo_unsetenv missing") + } + } + main_init() needUnlock = false @@ -80,8 +96,6 @@ func main() { } } -var parkunlock_c byte - // start forcegc helper goroutine func init() { go forcegchelper() @@ -115,7 +129,7 @@ func Gosched() { // Puts the current goroutine into a waiting state and calls unlockf. // If unlockf returns false, the goroutine is resumed. -func gopark(unlockf unsafe.Pointer, lock unsafe.Pointer, reason string) { +func gopark(unlockf func(*g, unsafe.Pointer) bool, lock unsafe.Pointer, reason string) { mp := acquirem() gp := mp.curg status := readgstatus(gp) @@ -123,7 +137,7 @@ func gopark(unlockf unsafe.Pointer, lock unsafe.Pointer, reason string) { gothrow("gopark: bad g status") } mp.waitlock = lock - mp.waitunlockf = unlockf + mp.waitunlockf = *(*unsafe.Pointer)(unsafe.Pointer(&unlockf)) gp.waitreason = reason releasem(mp) // can't do anything that might move the G between Ms here. @@ -133,14 +147,13 @@ func gopark(unlockf unsafe.Pointer, lock unsafe.Pointer, reason string) { // Puts the current goroutine into a waiting state and unlocks the lock. // The goroutine can be made runnable again by calling goready(gp). func goparkunlock(lock *mutex, reason string) { - gopark(unsafe.Pointer(&parkunlock_c), unsafe.Pointer(lock), reason) + gopark(parkunlock_c, unsafe.Pointer(lock), reason) } func goready(gp *g) { - mp := acquirem() - mp.ptrarg[0] = unsafe.Pointer(gp) - onM(ready_m) - releasem(mp) + onM(func() { + ready(gp) + }) } //go:nosplit @@ -223,6 +236,11 @@ func newG() *g { return new(g) } +var ( + allgs []*g + allglock mutex +) + func allgadd(gp *g) { if readgstatus(gp) == _Gidle { gothrow("allgadd: bad status Gidle") |