]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: avoid racing on pendingUpdates in AIX netpollBreak
authorIan Lance Taylor <iant@golang.org>
Sat, 28 Mar 2020 00:37:37 +0000 (17:37 -0700)
committerIan Lance Taylor <iant@golang.org>
Sat, 28 Mar 2020 19:37:39 +0000 (19:37 +0000)
Instead of calling netpollwakeup, just do the write in netpollBreak.
Use the same signaling we now use in other netpollBreak instances.

Change-Id: I53a65c22862ecc8484aee91d0e1ffb21a9e62d8c
Reviewed-on: https://go-review.googlesource.com/c/go/+/226199
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/runtime/netpoll_aix.go

index c936fbb70f75a011394523d63708d0b1df7c2d41..3c1f70874d65c3b70473e8ba5434fbb62dc3fb62 100644 (file)
@@ -4,7 +4,10 @@
 
 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.
@@ -41,6 +44,8 @@ var (
        rdwake         int32
        wrwake         int32
        pendingUpdates int32
+
+       netpollWakeSig uintptr // used to avoid duplicate calls of netpollBreak
 )
 
 func netpollinit() {
@@ -130,7 +135,10 @@ func netpollarm(pd *pollDesc, mode int) {
 
 // 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.
@@ -184,6 +192,7 @@ retry:
                        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.