mirror of
https://github.com/golang/go
synced 2024-11-17 14:54:44 -07:00
runtime: name nil semaphore of pollDesc
Use explicit name pdNil for nil semaphore of a pollDesc to make it self-explanatory like pdReady and pdWait. Change-Id: Ibfb246e14419d366edadbccac4d3717f0c135cb0 Reviewed-on: https://go-review.googlesource.com/c/go/+/424923 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
723a27994d
commit
556c978400
@ -50,16 +50,17 @@ const (
|
||||
// goroutines respectively. The semaphore can be in the following states:
|
||||
//
|
||||
// pdReady - io readiness notification is pending;
|
||||
// a goroutine consumes the notification by changing the state to nil.
|
||||
// a goroutine consumes the notification by changing the state to pdNil.
|
||||
// pdWait - a goroutine prepares to park on the semaphore, but not yet parked;
|
||||
// the goroutine commits to park by changing the state to G pointer,
|
||||
// or, alternatively, concurrent io notification changes the state to pdReady,
|
||||
// or, alternatively, concurrent timeout/close changes the state to nil.
|
||||
// or, alternatively, concurrent timeout/close changes the state to pdNil.
|
||||
// G pointer - the goroutine is blocked on the semaphore;
|
||||
// io notification or timeout/close changes the state to pdReady or nil respectively
|
||||
// io notification or timeout/close changes the state to pdReady or pdNil respectively
|
||||
// and unparks the goroutine.
|
||||
// nil - none of the above.
|
||||
// pdNil - none of the above.
|
||||
const (
|
||||
pdNil uintptr = 0
|
||||
pdReady uintptr = 1
|
||||
pdWait uintptr = 2
|
||||
)
|
||||
@ -93,8 +94,8 @@ type pollDesc struct {
|
||||
|
||||
// rg, wg are accessed atomically and hold g pointers.
|
||||
// (Using atomic.Uintptr here is similar to using guintptr elsewhere.)
|
||||
rg atomic.Uintptr // pdReady, pdWait, G waiting for read or nil
|
||||
wg atomic.Uintptr // pdReady, pdWait, G waiting for write or nil
|
||||
rg atomic.Uintptr // pdReady, pdWait, G waiting for read or pdNil
|
||||
wg atomic.Uintptr // pdReady, pdWait, G waiting for write or pdNil
|
||||
|
||||
lock mutex // protects the following fields
|
||||
closing bool
|
||||
@ -217,21 +218,21 @@ func poll_runtime_pollOpen(fd uintptr) (*pollDesc, int) {
|
||||
pd := pollcache.alloc()
|
||||
lock(&pd.lock)
|
||||
wg := pd.wg.Load()
|
||||
if wg != 0 && wg != pdReady {
|
||||
if wg != pdNil && wg != pdReady {
|
||||
throw("runtime: blocked write on free polldesc")
|
||||
}
|
||||
rg := pd.rg.Load()
|
||||
if rg != 0 && rg != pdReady {
|
||||
if rg != pdNil && rg != pdReady {
|
||||
throw("runtime: blocked read on free polldesc")
|
||||
}
|
||||
pd.fd = fd
|
||||
pd.closing = false
|
||||
pd.setEventErr(false)
|
||||
pd.rseq++
|
||||
pd.rg.Store(0)
|
||||
pd.rg.Store(pdNil)
|
||||
pd.rd = 0
|
||||
pd.wseq++
|
||||
pd.wg.Store(0)
|
||||
pd.wg.Store(pdNil)
|
||||
pd.wd = 0
|
||||
pd.self = pd
|
||||
pd.publishInfo()
|
||||
@ -251,11 +252,11 @@ func poll_runtime_pollClose(pd *pollDesc) {
|
||||
throw("runtime: close polldesc w/o unblock")
|
||||
}
|
||||
wg := pd.wg.Load()
|
||||
if wg != 0 && wg != pdReady {
|
||||
if wg != pdNil && wg != pdReady {
|
||||
throw("runtime: blocked write on closing polldesc")
|
||||
}
|
||||
rg := pd.rg.Load()
|
||||
if rg != 0 && rg != pdReady {
|
||||
if rg != pdNil && rg != pdReady {
|
||||
throw("runtime: blocked read on closing polldesc")
|
||||
}
|
||||
netpollclose(pd.fd)
|
||||
@ -280,9 +281,9 @@ func poll_runtime_pollReset(pd *pollDesc, mode int) int {
|
||||
return errcode
|
||||
}
|
||||
if mode == 'r' {
|
||||
pd.rg.Store(0)
|
||||
pd.rg.Store(pdNil)
|
||||
} else if mode == 'w' {
|
||||
pd.wg.Store(0)
|
||||
pd.wg.Store(pdNil)
|
||||
}
|
||||
return pollNoError
|
||||
}
|
||||
@ -505,16 +506,16 @@ func netpollblock(pd *pollDesc, mode int32, waitio bool) bool {
|
||||
// set the gpp semaphore to pdWait
|
||||
for {
|
||||
// Consume notification if already ready.
|
||||
if gpp.CompareAndSwap(pdReady, 0) {
|
||||
if gpp.CompareAndSwap(pdReady, pdNil) {
|
||||
return true
|
||||
}
|
||||
if gpp.CompareAndSwap(0, pdWait) {
|
||||
if gpp.CompareAndSwap(pdNil, pdWait) {
|
||||
break
|
||||
}
|
||||
|
||||
// Double check that this isn't corrupt; otherwise we'd loop
|
||||
// forever.
|
||||
if v := gpp.Load(); v != pdReady && v != 0 {
|
||||
if v := gpp.Load(); v != pdReady && v != pdNil {
|
||||
throw("runtime: double wait")
|
||||
}
|
||||
}
|
||||
@ -526,7 +527,7 @@ func netpollblock(pd *pollDesc, mode int32, waitio bool) bool {
|
||||
gopark(netpollblockcommit, unsafe.Pointer(gpp), waitReasonIOWait, traceEvGoBlockNet, 5)
|
||||
}
|
||||
// be careful to not lose concurrent pdReady notification
|
||||
old := gpp.Swap(0)
|
||||
old := gpp.Swap(pdNil)
|
||||
if old > pdWait {
|
||||
throw("runtime: corrupted polldesc")
|
||||
}
|
||||
@ -544,7 +545,7 @@ func netpollunblock(pd *pollDesc, mode int32, ioready bool) *g {
|
||||
if old == pdReady {
|
||||
return nil
|
||||
}
|
||||
if old == 0 && !ioready {
|
||||
if old == pdNil && !ioready {
|
||||
// Only set pdReady for ioready. runtime_pollWait
|
||||
// will check for timeout/cancel before waiting.
|
||||
return nil
|
||||
@ -555,7 +556,7 @@ func netpollunblock(pd *pollDesc, mode int32, ioready bool) *g {
|
||||
}
|
||||
if gpp.CompareAndSwap(old, new) {
|
||||
if old == pdWait {
|
||||
old = 0
|
||||
old = pdNil
|
||||
}
|
||||
return (*g)(unsafe.Pointer(old))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user