aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/netpoll_kqueue.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_kqueue.go
parent6da300b196df5fc3b33dd3bc87c477d46473abde (diff)
downloadgo-831e3cfaa594ceb70c3cbeff2d31fddcd9a25a5e.tar.xz
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_kqueue.go')
-rw-r--r--src/runtime/netpoll_kqueue.go26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/runtime/netpoll_kqueue.go b/src/runtime/netpoll_kqueue.go
index a8880e82a5..ce8da73d1e 100644
--- a/src/runtime/netpoll_kqueue.go
+++ b/src/runtime/netpoll_kqueue.go
@@ -57,15 +57,27 @@ func netpollarm(pd *pollDesc, mode int) {
throw("runtime: unused")
}
-// Polls for ready network connections.
+// netpoll checks for ready network connections.
// Returns list of goroutines that become runnable.
-func netpoll(block bool) gList {
+// 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 kq == -1 {
return gList{}
}
var tp *timespec
var ts timespec
- if !block {
+ if delay < 0 {
+ tp = nil
+ } else if delay == 0 {
+ tp = &ts
+ } else {
+ ts.setNsec(delay)
+ if ts.tv_sec > 1e6 {
+ // Darwin returns EINVAL if the sleep time is too long.
+ ts.tv_sec = 1e6
+ }
tp = &ts
}
var events [64]keventt
@@ -76,6 +88,11 @@ retry:
println("runtime: kevent on fd", kq, "failed with", -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
}
var toRun gList
@@ -110,8 +127,5 @@ retry:
netpollready(&toRun, pd, mode)
}
}
- if block && toRun.empty() {
- goto retry
- }
return toRun
}