var netpollStubLock mutex
var netpollNote note
-var netpollBroken uint32
+
+// netpollBroken, protected by netpollBrokenLock, avoids a double notewakeup.
+var netpollBrokenLock mutex
+var netpollBroken bool
func netpollGenericInit() {
atomic.Store(&netpollInited, 1)
}
func netpollBreak() {
- if atomic.Cas(&netpollBroken, 0, 1) {
+ lock(&netpollBrokenLock)
+ broken := netpollBroken
+ netpollBroken = true
+ if !broken {
notewakeup(&netpollNote)
}
+ unlock(&netpollBrokenLock)
}
// Polls for ready network connections.
// This lock ensures that only one goroutine tries to use
// the note. It should normally be completely uncontended.
lock(&netpollStubLock)
+
+ lock(&netpollBrokenLock)
noteclear(&netpollNote)
- atomic.Store(&netpollBroken, 0)
+ netpollBroken = false
+ unlock(&netpollBrokenLock)
+
notetsleep(&netpollNote, delay)
unlock(&netpollStubLock)
}