parent
6dced977ea
commit
5205bc7e58
|
@ -28,15 +28,6 @@ import "sync/atomic"
|
|||
// It is written in assembly because it is called from g0, so it doesn't have
|
||||
// a race context.
|
||||
func commitSleep(g uintptr, waitingG *uintptr) bool {
|
||||
for {
|
||||
// Check if the wait was aborted.
|
||||
if atomic.LoadUintptr(waitingG) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
// Try to store the G so that wakers know who to wake.
|
||||
if atomic.CompareAndSwapUintptr(waitingG, preparingG, g) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
// Try to store the G so that wakers know who to wake.
|
||||
return atomic.CompareAndSwapUintptr(waitingG, preparingG, g)
|
||||
}
|
||||
|
|
|
@ -299,20 +299,17 @@ func (s *Sleeper) enqueueAssertedWaker(w *Waker) {
|
|||
}
|
||||
}
|
||||
|
||||
for {
|
||||
// Nothing to do if there isn't a G waiting.
|
||||
g := atomic.LoadUintptr(&s.waitingG)
|
||||
if g == 0 {
|
||||
return
|
||||
}
|
||||
// Nothing to do if there isn't a G waiting.
|
||||
if atomic.LoadUintptr(&s.waitingG) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// Signal to the sleeper that a waker has been asserted.
|
||||
if atomic.CompareAndSwapUintptr(&s.waitingG, g, 0) {
|
||||
if g != preparingG {
|
||||
// We managed to get a G. Wake it up.
|
||||
goready(g, 0)
|
||||
}
|
||||
}
|
||||
// Signal to the sleeper that a waker has been asserted.
|
||||
switch g := atomic.SwapUintptr(&s.waitingG, 0); g {
|
||||
case 0, preparingG:
|
||||
default:
|
||||
// We managed to get a G. Wake it up.
|
||||
goready(g, 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue