wanted [(_NSIG + 31) / 32]uint32
ignored [(_NSIG + 31) / 32]uint32
recv [(_NSIG + 31) / 32]uint32
- state uint32
- delivering uint32
+ state atomic.Uint32
+ delivering atomic.Uint32
inuse bool
}
return false
}
- atomic.Xadd(&sig.delivering, 1)
+ sig.delivering.Add(1)
// We are running in the signal handler; defer is not available.
if w := atomic.Load(&sig.wanted[s/32]); w&bit == 0 {
- atomic.Xadd(&sig.delivering, -1)
+ sig.delivering.Add(-1)
return false
}
for {
mask := sig.mask[s/32]
if mask&bit != 0 {
- atomic.Xadd(&sig.delivering, -1)
+ sig.delivering.Add(-1)
return true // signal already in queue
}
if atomic.Cas(&sig.mask[s/32], mask, mask|bit) {
// Notify receiver that queue has new bit.
Send:
for {
- switch atomic.Load(&sig.state) {
+ switch sig.state.Load() {
default:
throw("sigsend: inconsistent state")
case sigIdle:
- if atomic.Cas(&sig.state, sigIdle, sigSending) {
+ if sig.state.CompareAndSwap(sigIdle, sigSending) {
break Send
}
case sigSending:
// notification already pending
break Send
case sigReceiving:
- if atomic.Cas(&sig.state, sigReceiving, sigIdle) {
+ if sig.state.CompareAndSwap(sigReceiving, sigIdle) {
if GOOS == "darwin" || GOOS == "ios" {
sigNoteWakeup(&sig.note)
break Send
}
}
- atomic.Xadd(&sig.delivering, -1)
+ sig.delivering.Add(-1)
return true
}
// Wait for updates to be available from signal sender.
Receive:
for {
- switch atomic.Load(&sig.state) {
+ switch sig.state.Load() {
default:
throw("signal_recv: inconsistent state")
case sigIdle:
- if atomic.Cas(&sig.state, sigIdle, sigReceiving) {
+ if sig.state.CompareAndSwap(sigIdle, sigReceiving) {
if GOOS == "darwin" || GOOS == "ios" {
sigNoteSleep(&sig.note)
break Receive
break Receive
}
case sigSending:
- if atomic.Cas(&sig.state, sigSending, sigIdle) {
+ if sig.state.CompareAndSwap(sigSending, sigIdle) {
break Receive
}
}
// a signal, has read from sig.wanted, is now updating sig.mask,
// and has not yet woken up the processor thread. We need to wait
// until all current signal deliveries have completed.
- for atomic.Load(&sig.delivering) != 0 {
+ for sig.delivering.Load() != 0 {
Gosched()
}
// Although WaitUntilIdle seems like the right name for this
// function, the state we are looking for is sigReceiving, not
// sigIdle. The sigIdle state is really more like sigProcessing.
- for atomic.Load(&sig.state) != sigReceiving {
+ for sig.state.Load() != sigReceiving {
Gosched()
}
}