]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use C for readgstatus, goroutine status values
authorRuss Cox <rsc@golang.org>
Thu, 4 Sep 2014 18:19:50 +0000 (14:19 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 4 Sep 2014 18:19:50 +0000 (14:19 -0400)
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

src/pkg/runtime/proc.c
src/pkg/runtime/proc.go

index 3e7b07c2c5aeb07545014177ad07be4c3a19329a..d75c210c5a374eea4c0fd754d6ddab827b8b8dda 100644 (file)
@@ -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)
 {
index 3e1d0694a0c3d59df3e82cff6c1f83d50b3b0ba1..4789a51b66c836e93a2713737b8067721442ecaa 100644 (file)
@@ -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