package runtime
-import "unsafe"
+import (
+ "runtime/internal/atomic"
+ "unsafe"
+)
// This is based on the former libgo/runtime/netpoll_select.c implementation
// except that it uses poll instead of select and is written in Go.
rdwake int32
wrwake int32
pendingUpdates int32
+
+ netpollWakeSig uintptr // used to avoid duplicate calls of netpollBreak
)
func netpollinit() {
// netpollBreak interrupts a poll.
func netpollBreak() {
- netpollwakeup()
+ if atomic.Casuintptr(&netpollWakeSig, 0, 1) {
+ b := [1]byte{0}
+ write(uintptr(wrwake), unsafe.Pointer(&b[0]), 1)
+ }
}
// netpoll checks for ready network connections.
var b [1]byte
for read(rdwake, unsafe.Pointer(&b[0]), 1) == 1 {
}
+ atomic.Storeuintptr(&netpollWakeSig, 0)
}
// Still look at the other fds even if the mode may have
// changed, as netpollBreak might have been called.