From: Russ Cox Date: Thu, 4 Sep 2014 18:19:50 +0000 (-0400) Subject: runtime: use C for readgstatus, goroutine status values X-Git-Tag: go1.4beta1~535 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=503bcd464e8974b3295177c1a0ed5a4ba5bc5a01;p=gostls13.git runtime: use C for readgstatus, goroutine status values When this code was written, there was no way for Go to reuse the C function and enum values. Now there is. LGTM=bradfitz R=rlh, bradfitz CC=dvyukov, golang-codereviews, iant, khr, r https://golang.org/cl/139150045 --- diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c index 3e7b07c2c5..d75c210c5a 100644 --- a/src/pkg/runtime/proc.c +++ b/src/pkg/runtime/proc.c @@ -442,6 +442,7 @@ isscanstatus(uint32 status) // All reads and writes of g's status go through readgstatus, casgstatus // castogscanstatus, casfromgscanstatus. +#pragma textflag NOSPLIT uint32 runtime·readgstatus(G *gp) { diff --git a/src/pkg/runtime/proc.go b/src/pkg/runtime/proc.go index 3e1d0694a0..4789a51b66 100644 --- a/src/pkg/runtime/proc.go +++ b/src/pkg/runtime/proc.go @@ -6,27 +6,6 @@ package runtime import "unsafe" -// This is not mechanically generated -// so be very careful and refer to runtime.h -// for the definitive enum. -const ( - gStatusidle = iota - gStatusRunnable - gStatusRunning - gStatusSyscall - gStatusWaiting - gStatusMoribundUnused - gStatusDead - gStatusEnqueue - gStatusCopystack - gStatusScan = 0x1000 - gStatusScanRunnable = gStatusScan + gStatusRunnable - gStatusScanRunning = gStatusScan + gStatusRunning - gStatusScanSyscall = gStatusScan + gStatusSyscall - gStatusScanWaiting = gStatusScan + gStatusWaiting - gStatusScanEnqueue = gStatusScan + gStatusEnqueue -) - var parkunlock_c byte // start forcegc helper goroutine @@ -58,18 +37,13 @@ func Gosched() { mcall(gosched_m) } -func readgStatus(gp *g) uint32 { - //return atomic.LoadUint32(&gp.atomicstatus) // TODO: add bootstrap code to provide. - return gp.atomicstatus -} - // 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) { mp := acquirem() gp := mp.curg - status := readgStatus(gp) - if status != gStatusRunning && status != gStatusScanRunning { + status := readgstatus(gp) + if status != _Grunning && status != _Gscanrunning { gothrow("gopark: bad g status") } mp.waitlock = lock