aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/netpoll_solaris.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2019-04-02 20:27:35 -0700
committerIan Lance Taylor <iant@golang.org>2019-10-15 20:29:56 +0000
commit831e3cfaa594ceb70c3cbeff2d31fddcd9a25a5e (patch)
tree6a5203ae8e7b24bce6e2c76986aecf17e039e4a7 /src/runtime/netpoll_solaris.go
parent6da300b196df5fc3b33dd3bc87c477d46473abde (diff)
downloadgo-831e3cfaa594ceb70c3cbeff2d31fddcd9a25a5e.tar.gz
go-831e3cfaa594ceb70c3cbeff2d31fddcd9a25a5e.zip
runtime: change netpoll to take an amount of time to block
This new facility will be used by future CLs in this series. Change the only blocking call to netpoll to do the right thing when netpoll returns an empty list. Updates #6239 Updates #27707 Change-Id: I58b3c2903eda61a3698b1a4729ed0e81382bb1ed Reviewed-on: https://go-review.googlesource.com/c/go/+/171821 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Diffstat (limited to 'src/runtime/netpoll_solaris.go')
-rw-r--r--src/runtime/netpoll_solaris.go35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/runtime/netpoll_solaris.go b/src/runtime/netpoll_solaris.go
index ddddb27962..ad41ab5af2 100644
--- a/src/runtime/netpoll_solaris.go
+++ b/src/runtime/netpoll_solaris.go
@@ -178,27 +178,45 @@ func netpollarm(pd *pollDesc, mode int) {
unlock(&pd.lock)
}
-// polls for ready network connections
-// returns list of goroutines that become runnable
-func netpoll(block bool) gList {
+// netpoll checks for ready network connections.
+// Returns list of goroutines that become runnable.
+// delay < 0: blocks indefinitely
+// delay == 0: does not block, just polls
+// delay > 0: block for up to that many nanoseconds
+func netpoll(delay int64) gList {
if portfd == -1 {
return gList{}
}
var wait *timespec
- var zero timespec
- if !block {
- wait = &zero
+ var ts timespec
+ if delay < 0 {
+ wait = nil
+ } else if delay == 0 {
+ wait = &ts
+ } else {
+ ts.setNsec(delay)
+ if ts.tv_sec > 1e6 {
+ // An arbitrary cap on how long to wait for a timer.
+ // 1e6 s == ~11.5 days.
+ ts.tv_sec = 1e6
+ }
+ wait = &ts
}
var events [128]portevent
retry:
var n uint32 = 1
if port_getn(portfd, &events[0], uint32(len(events)), &n, wait) < 0 {
- if e := errno(); e != _EINTR {
+ if e := errno(); e != _EINTR && e != _ETIME {
print("runtime: port_getn on fd ", portfd, " failed (errno=", e, ")\n")
throw("runtime: netpoll failed")
}
+ // If a timed sleep was interrupted, just return to
+ // recalculate how long we should sleep now.
+ if delay > 0 {
+ return gList{}
+ }
goto retry
}
@@ -242,8 +260,5 @@ retry:
}
}
- if block && toRun.empty() {
- goto retry
- }
return toRun
}