1
0
mirror of https://github.com/golang/go synced 2024-11-23 06:10:05 -07:00

internal/poll, os/exec, runtime: replace PollDescriptor by IsPollDescriptor

This commit changes poll.PollDescriptor by poll.IsPollDescriptor. This
is needed for OS like AIX which have more than one FD using inside their
netpoll implementation.

Change-Id: I49e12a8d74045c501e19fdd8527cf166a3c64850
Reviewed-on: https://go-review.googlesource.com/c/146938
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Clément Chigot 2018-11-02 10:02:38 +01:00 committed by Ian Lance Taylor
parent 56421f26ef
commit 5ee06f5471
5 changed files with 32 additions and 21 deletions

View File

@ -193,10 +193,10 @@ func isInterrupted(err error) bool {
return err != nil && stringsHasSuffix(err.Error(), "interrupted")
}
// PollDescriptor returns the descriptor being used by the poller,
// or ^uintptr(0) if there isn't one. This is only used for testing.
func PollDescriptor() uintptr {
return ^uintptr(0)
// IsPollDescriptor returns true if fd is the descriptor being used by the poller.
// This is only used for testing.
func IsPollDescriptor(fd uintptr) bool {
return false
}
// RawControl invokes the user-defined function f for a non-IO

View File

@ -92,8 +92,8 @@ func setDeadlineImpl(fd *FD, t time.Time, mode int) error {
return nil
}
// PollDescriptor returns the descriptor being used by the poller,
// or ^uintptr(0) if there isn't one. This is only used for testing.
func PollDescriptor() uintptr {
return ^uintptr(0)
// IsPollDescriptor returns true if fd is the descriptor being used by the poller.
// This is only used for testing.
func IsPollDescriptor(fd uintptr) bool {
return false
}

View File

@ -19,7 +19,6 @@ import (
func runtimeNano() int64
func runtime_pollServerInit()
func runtime_pollServerDescriptor() uintptr
func runtime_pollOpen(fd uintptr) (uintptr, int)
func runtime_pollClose(ctx uintptr)
func runtime_pollWait(ctx uintptr, mode int) int
@ -27,6 +26,7 @@ func runtime_pollWaitCanceled(ctx uintptr, mode int) int
func runtime_pollReset(ctx uintptr, mode int) int
func runtime_pollSetDeadline(ctx uintptr, d int64, mode int)
func runtime_pollUnblock(ctx uintptr)
func runtime_isPollServerDescriptor(fd uintptr) bool
type pollDesc struct {
runtimeCtx uintptr
@ -154,8 +154,8 @@ func setDeadlineImpl(fd *FD, t time.Time, mode int) error {
return nil
}
// PollDescriptor returns the descriptor being used by the poller,
// or ^uintptr(0) if there isn't one. This is only used for testing.
func PollDescriptor() uintptr {
return runtime_pollServerDescriptor()
// IsPollDescriptor returns true if fd is the descriptor being used by the poller.
// This is only used for testing.
func IsPollDescriptor(fd uintptr) bool {
return runtime_isPollServerDescriptor(fd)
}

View File

@ -459,7 +459,7 @@ func basefds() uintptr {
// The poll (epoll/kqueue) descriptor can be numerically
// either between stderr and the testlog-fd, or after
// testlog-fd.
if poll.PollDescriptor() == n {
if poll.IsPollDescriptor(n) {
n++
}
for _, arg := range os.Args {
@ -472,7 +472,7 @@ func basefds() uintptr {
func closeUnexpectedFds(t *testing.T, m string) {
for fd := basefds(); fd <= 101; fd++ {
if fd == poll.PollDescriptor() {
if poll.IsPollDescriptor(fd) {
continue
}
err := os.NewFile(fd, "").Close()
@ -734,6 +734,8 @@ func TestHelperProcess(*testing.T) {
ofcmd = "fstat"
case "plan9":
ofcmd = "/bin/cat"
case "aix":
ofcmd = "procfiles"
}
args := os.Args
@ -837,7 +839,7 @@ func TestHelperProcess(*testing.T) {
// Now verify that there are no other open fds.
var files []*os.File
for wantfd := basefds() + 1; wantfd <= 100; wantfd++ {
if wantfd == poll.PollDescriptor() {
if poll.IsPollDescriptor(wantfd) {
continue
}
f, err := os.Open(os.Args[0])
@ -851,6 +853,8 @@ func TestHelperProcess(*testing.T) {
switch runtime.GOOS {
case "plan9":
args = []string{fmt.Sprintf("/proc/%d/fd", os.Getpid())}
case "aix":
args = []string{fmt.Sprint(os.Getpid())}
default:
args = []string{"-p", fmt.Sprint(os.Getpid())}
}

View File

@ -93,12 +93,19 @@ func netpollinited() bool {
return atomic.Load(&netpollInited) != 0
}
//go:linkname poll_runtime_pollServerDescriptor internal/poll.runtime_pollServerDescriptor
//go:linkname poll_runtime_isPollServerDescriptor internal/poll.runtime_isPollServerDescriptor
// poll_runtime_pollServerDescriptor returns the descriptor being used,
// or ^uintptr(0) if the system does not use a poll descriptor.
func poll_runtime_pollServerDescriptor() uintptr {
return netpolldescriptor()
// poll_runtime_isPollServerDescriptor returns true if fd is a
// descriptor being used by netpoll.
func poll_runtime_isPollServerDescriptor(fd uintptr) bool {
fds := netpolldescriptor()
if GOOS != "aix" {
return fd == fds
} else {
// AIX have a pipe in its netpoll implementation.
// Therefore, two fd are returned by netpolldescriptor using a mask.
return fd == fds&0xFFFF || fd == (fds>>16)&0xFFFF
}
}
//go:linkname poll_runtime_pollOpen internal/poll.runtime_pollOpen