aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/os_linux.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2019-03-13 18:56:37 -0700
committerIan Lance Taylor <iant@golang.org>2019-03-15 03:37:49 +0000
commit0a7bc8f430e3e4017910780a898a5f20d337895b (patch)
tree05de8f86002d9e9313331d1c917fe88925625b81 /src/runtime/os_linux.go
parent829c140f149dba8933dea0cead3a78de4c83b529 (diff)
downloadgo-0a7bc8f430e3e4017910780a898a5f20d337895b.tar.xz
runtime: introduce and consistently use setNsec for timespec
The general code for setting a timespec value sometimes used set_nsec and sometimes used a combination of set_sec and set_nsec. Standardize on a setNsec function that takes a number of nanoseconds and splits them up to set the tv_sec and tv_nsec fields. Consistently mark setNsec as go:nosplit, since it has to be that way on some systems including Darwin and GNU/Linux. Consistently use timediv on 32-bit systems to help stay within split-stack limits on processors that don't have a 64-bit division instruction. Change-Id: I6396bb7ddbef171a96876bdeaf7a1c585a6d725b Reviewed-on: https://go-review.googlesource.com/c/go/+/167389 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/runtime/os_linux.go')
-rw-r--r--src/runtime/os_linux.go17
1 files changed, 2 insertions, 15 deletions
diff --git a/src/runtime/os_linux.go b/src/runtime/os_linux.go
index a04c995c00..8f3afe0577 100644
--- a/src/runtime/os_linux.go
+++ b/src/runtime/os_linux.go
@@ -35,8 +35,6 @@ const (
// Don't sleep longer than ns; ns < 0 means forever.
//go:nosplit
func futexsleep(addr *uint32, val uint32, ns int64) {
- var ts timespec
-
// Some Linux kernels have a bug where futex of
// FUTEX_WAIT returns an internal error code
// as an errno. Libpthread ignores the return value
@@ -47,19 +45,8 @@ func futexsleep(addr *uint32, val uint32, ns int64) {
return
}
- // It's difficult to live within the no-split stack limits here.
- // On ARM and 386, a 64-bit divide invokes a general software routine
- // that needs more stack than we can afford. So we use timediv instead.
- // But on real 64-bit systems, where words are larger but the stack limit
- // is not, even timediv is too heavy, and we really need to use just an
- // ordinary machine instruction.
- if sys.PtrSize == 8 {
- ts.set_sec(ns / 1000000000)
- ts.set_nsec(int32(ns % 1000000000))
- } else {
- ts.tv_nsec = 0
- ts.set_sec(int64(timediv(ns, 1000000000, (*int32)(unsafe.Pointer(&ts.tv_nsec)))))
- }
+ var ts timespec
+ ts.setNsec(ns)
futex(unsafe.Pointer(addr), _FUTEX_WAIT_PRIVATE, val, unsafe.Pointer(&ts), nil, 0)
}