1
0
mirror of https://github.com/golang/go synced 2024-11-11 19:51:37 -07:00

runtime: avoid racing on pendingUpdates in AIX netpollBreak

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>
This commit is contained in:
Ian Lance Taylor 2020-03-27 17:37:37 -07:00
parent d99fe1f40d
commit 45f99d85e0

View File

@ -4,7 +4,10 @@
package runtime package runtime
import "unsafe" import (
"runtime/internal/atomic"
"unsafe"
)
// This is based on the former libgo/runtime/netpoll_select.c implementation // 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. // except that it uses poll instead of select and is written in Go.
@ -41,6 +44,8 @@ var (
rdwake int32 rdwake int32
wrwake int32 wrwake int32
pendingUpdates int32 pendingUpdates int32
netpollWakeSig uintptr // used to avoid duplicate calls of netpollBreak
) )
func netpollinit() { func netpollinit() {
@ -130,7 +135,10 @@ func netpollarm(pd *pollDesc, mode int) {
// netpollBreak interrupts a poll. // netpollBreak interrupts a poll.
func netpollBreak() { 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. // netpoll checks for ready network connections.
@ -184,6 +192,7 @@ retry:
var b [1]byte var b [1]byte
for read(rdwake, unsafe.Pointer(&b[0]), 1) == 1 { 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 // Still look at the other fds even if the mode may have
// changed, as netpollBreak might have been called. // changed, as netpollBreak might have been called.