// netpollBreak interrupts a poll.
 func netpollBreak() {
-       if atomic.Cas(&netpollWakeSig, 0, 1) {
-               b := [1]byte{0}
-               write(uintptr(wrwake), unsafe.Pointer(&b[0]), 1)
+       // Failing to cas indicates there is an in-flight wakeup, so we're done here.
+       if !atomic.Cas(&netpollWakeSig, 0, 1) {
+               return
        }
+
+       b := [1]byte{0}
+       write(uintptr(wrwake), unsafe.Pointer(&b[0]), 1)
 }
 
 // netpoll checks for ready network connections.
 
 
 // netpollBreak interrupts an epollwait.
 func netpollBreak() {
-       if atomic.Cas(&netpollWakeSig, 0, 1) {
-               for {
-                       var b byte
-                       n := write(netpollBreakWr, unsafe.Pointer(&b), 1)
-                       if n == 1 {
-                               break
-                       }
-                       if n == -_EINTR {
-                               continue
-                       }
-                       if n == -_EAGAIN {
-                               return
-                       }
-                       println("runtime: netpollBreak write failed with", -n)
-                       throw("runtime: netpollBreak write failed")
+       // Failing to cas indicates there is an in-flight wakeup, so we're done here.
+       if !atomic.Cas(&netpollWakeSig, 0, 1) {
+               return
+       }
+
+       for {
+               var b byte
+               n := write(netpollBreakWr, unsafe.Pointer(&b), 1)
+               if n == 1 {
+                       break
+               }
+               if n == -_EINTR {
+                       continue
+               }
+               if n == -_EAGAIN {
+                       return
                }
+               println("runtime: netpollBreak write failed with", -n)
+               throw("runtime: netpollBreak write failed")
        }
 }
 
 
 
 // netpollBreak interrupts a kevent.
 func netpollBreak() {
-       if atomic.Cas(&netpollWakeSig, 0, 1) {
-               for {
-                       var b byte
-                       n := write(netpollBreakWr, unsafe.Pointer(&b), 1)
-                       if n == 1 || n == -_EAGAIN {
-                               break
-                       }
-                       if n == -_EINTR {
-                               continue
-                       }
-                       println("runtime: netpollBreak write failed with", -n)
-                       throw("runtime: netpollBreak write failed")
+       // Failing to cas indicates there is an in-flight wakeup, so we're done here.
+       if !atomic.Cas(&netpollWakeSig, 0, 1) {
+               return
+       }
+
+       for {
+               var b byte
+               n := write(netpollBreakWr, unsafe.Pointer(&b), 1)
+               if n == 1 || n == -_EAGAIN {
+                       break
+               }
+               if n == -_EINTR {
+                       continue
                }
+               println("runtime: netpollBreak write failed with", -n)
+               throw("runtime: netpollBreak write failed")
        }
 }
 
 
 
 // netpollBreak interrupts a port_getn wait.
 func netpollBreak() {
-       if atomic.Cas(&netpollWakeSig, 0, 1) {
-               // Use port_alert to put portfd into alert mode.
-               // This will wake up all threads sleeping in port_getn on portfd,
-               // and cause their calls to port_getn to return immediately.
-               // Further, until portfd is taken out of alert mode,
-               // all calls to port_getn will return immediately.
-               if port_alert(portfd, _PORT_ALERT_UPDATE, _POLLHUP, uintptr(unsafe.Pointer(&portfd))) < 0 {
-                       if e := errno(); e != _EBUSY {
-                               println("runtime: port_alert failed with", e)
-                               throw("runtime: netpoll: port_alert failed")
-                       }
+       // Failing to cas indicates there is an in-flight wakeup, so we're done here.
+       if !atomic.Cas(&netpollWakeSig, 0, 1) {
+               return
+       }
+
+       // Use port_alert to put portfd into alert mode.
+       // This will wake up all threads sleeping in port_getn on portfd,
+       // and cause their calls to port_getn to return immediately.
+       // Further, until portfd is taken out of alert mode,
+       // all calls to port_getn will return immediately.
+       if port_alert(portfd, _PORT_ALERT_UPDATE, _POLLHUP, uintptr(unsafe.Pointer(&portfd))) < 0 {
+               if e := errno(); e != _EBUSY {
+                       println("runtime: port_alert failed with", e)
+                       throw("runtime: netpoll: port_alert failed")
                }
        }
 }
 
 }
 
 func netpollBreak() {
-       if atomic.Cas(&netpollWakeSig, 0, 1) {
-               if stdcall4(_PostQueuedCompletionStatus, iocphandle, 0, 0, 0) == 0 {
-                       println("runtime: netpoll: PostQueuedCompletionStatus failed (errno=", getlasterror(), ")")
-                       throw("runtime: netpoll: PostQueuedCompletionStatus failed")
-               }
+       // Failing to cas indicates there is an in-flight wakeup, so we're done here.
+       if !atomic.Cas(&netpollWakeSig, 0, 1) {
+               return
+       }
+
+       if stdcall4(_PostQueuedCompletionStatus, iocphandle, 0, 0, 0) == 0 {
+               println("runtime: netpoll: PostQueuedCompletionStatus failed (errno=", getlasterror(), ")")
+               throw("runtime: netpoll: PostQueuedCompletionStatus failed")
        }
 }