From 3deb5d0c043dcfd8523425792c6cf8ec13b19868 Mon Sep 17 00:00:00 2001 From: Adin Scannell Date: Mon, 23 Nov 2020 14:25:37 -0800 Subject: Fix link against runtime.goyield. This function does not exist in Go 1.13. We need to add an adaptor to build against Go 1.13, which is the default Ubuntu version. PiperOrigin-RevId: 343929132 --- pkg/sync/BUILD | 1 + pkg/sync/spin_legacy_unsafe.go | 25 +++++++++++++++++++++++++ pkg/sync/spin_unsafe.go | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 pkg/sync/spin_legacy_unsafe.go diff --git a/pkg/sync/BUILD b/pkg/sync/BUILD index 410e9a3ca..5bd4d09d1 100644 --- a/pkg/sync/BUILD +++ b/pkg/sync/BUILD @@ -40,6 +40,7 @@ go_library( "race_unsafe.go", "rwmutex_unsafe.go", "seqcount.go", + "spin_legacy_unsafe.go", "spin_unsafe.go", "sync.go", ], diff --git a/pkg/sync/spin_legacy_unsafe.go b/pkg/sync/spin_legacy_unsafe.go new file mode 100644 index 000000000..61fc7320e --- /dev/null +++ b/pkg/sync/spin_legacy_unsafe.go @@ -0,0 +1,25 @@ +// Copyright 2020 The gVisor Authors. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build go1.13 +// +build !go1.14 + +package sync + +import ( + "runtime" + _ "unsafe" // for go:linkname +) + +//go:linkname canSpin sync.runtime_canSpin +func canSpin(i int) bool + +//go:linkname doSpin sync.runtime_doSpin +func doSpin() + +func goyield() { + // goyield is not available until Go 1.14. + runtime.Gosched() +} diff --git a/pkg/sync/spin_unsafe.go b/pkg/sync/spin_unsafe.go index cafb2d065..18e8fc743 100644 --- a/pkg/sync/spin_unsafe.go +++ b/pkg/sync/spin_unsafe.go @@ -3,7 +3,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build go1.13 +// +build go1.14 // +build !go1.17 // Check go:linkname function signatures when updating Go version. -- cgit v1.2.3