1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:04:44 -07:00

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
This commit is contained in:
Russ Cox 2014-09-04 14:19:50 -04:00
parent 81ed684a71
commit 503bcd464e
2 changed files with 3 additions and 28 deletions

View 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)
{

View 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