From 1e3f563b145ad98d2a5fcd4809e25a6a0bc8f892 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 21 Nov 2017 20:46:40 +0000 Subject: [PATCH] runtime: fix build on non-Linux platforms CL 78538 was updated after running TryBots to depend on syscall.NanoSleep which isn't available on all non-Linux platforms. Change-Id: I1fa615232b3920453431861310c108b208628441 Reviewed-on: https://go-review.googlesource.com/79175 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Austin Clements --- src/runtime/proc_test.go | 18 ++++++++++-------- src/runtime/runtime_linux_test.go | 12 ++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/runtime/proc_test.go b/src/runtime/proc_test.go index a0112f2fac..2ece829071 100644 --- a/src/runtime/proc_test.go +++ b/src/runtime/proc_test.go @@ -750,16 +750,18 @@ func BenchmarkWakeupParallelSpinning(b *testing.B) { }) } +// sysNanosleep is defined by OS-specific files (such as runtime_linux_test.go) +// to sleep for the given duration. If nil, dependent tests are skipped. +// The implementation should invoke a blocking system call and not +// call time.Sleep, which would deschedule the goroutine. +var sysNanosleep func(d time.Duration) + func BenchmarkWakeupParallelSyscall(b *testing.B) { + if sysNanosleep == nil { + b.Skipf("skipping on %v; sysNanosleep not defined", runtime.GOOS) + } benchmarkWakeupParallel(b, func(d time.Duration) { - // Invoke a blocking syscall directly; calling time.Sleep() - // would deschedule the goroutine instead. - ts := syscall.NsecToTimespec(d.Nanoseconds()) - for { - if err := syscall.Nanosleep(&ts, &ts); err != syscall.EINTR { - return - } - } + sysNanosleep(d) }) } diff --git a/src/runtime/runtime_linux_test.go b/src/runtime/runtime_linux_test.go index 2b6daecbfc..612397293f 100644 --- a/src/runtime/runtime_linux_test.go +++ b/src/runtime/runtime_linux_test.go @@ -8,6 +8,7 @@ import ( . "runtime" "syscall" "testing" + "time" "unsafe" ) @@ -21,6 +22,17 @@ func init() { // for how it is used in init (must be on main thread). pid, tid = syscall.Getpid(), syscall.Gettid() LockOSThread() + + sysNanosleep = func(d time.Duration) { + // Invoke a blocking syscall directly; calling time.Sleep() + // would deschedule the goroutine instead. + ts := syscall.NsecToTimespec(d.Nanoseconds()) + for { + if err := syscall.Nanosleep(&ts, &ts); err != syscall.EINTR { + return + } + } + } } func TestLockOSThread(t *testing.T) {