New sync package.

* Rename syncutil to sync.
* Add aliases to sync types.
* Replace existing usage of standard library sync package.

This will make it easier to swap out synchronization primitives. For example,
this will allow us to use primitives from github.com/sasha-s/go-deadlock to
check for lock ordering violations.

Updates #1472

PiperOrigin-RevId: 289033387
This commit is contained in:
Ian Gudger
2020-01-09 22:02:24 -08:00
committed by gVisor bot
parent b08da42285
commit 27500d529f
286 changed files with 406 additions and 267 deletions
+1
View File
@@ -15,4 +15,5 @@ go_test(
size = "small",
srcs = ["amutex_test.go"],
embed = [":amutex"],
deps = ["//pkg/sync"],
)
+2 -1
View File
@@ -15,9 +15,10 @@
package amutex
import (
"sync"
"testing"
"time"
"gvisor.dev/gvisor/pkg/sync"
)
type sleeper struct {
+1
View File
@@ -20,4 +20,5 @@ go_test(
size = "small",
srcs = ["atomic_bitops_test.go"],
embed = [":atomicbitops"],
deps = ["//pkg/sync"],
)
+2 -1
View File
@@ -16,8 +16,9 @@ package atomicbitops
import (
"runtime"
"sync"
"testing"
"gvisor.dev/gvisor/pkg/sync"
)
const iterations = 100
+4 -1
View File
@@ -8,7 +8,10 @@ go_library(
srcs = ["compressio.go"],
importpath = "gvisor.dev/gvisor/pkg/compressio",
visibility = ["//:sandbox"],
deps = ["//pkg/binary"],
deps = [
"//pkg/binary",
"//pkg/sync",
],
)
go_test(
+1 -1
View File
@@ -52,9 +52,9 @@ import (
"hash"
"io"
"runtime"
"sync"
"gvisor.dev/gvisor/pkg/binary"
"gvisor.dev/gvisor/pkg/sync"
)
var bufPool = sync.Pool{
+1
View File
@@ -9,6 +9,7 @@ go_library(
visibility = ["//:sandbox"],
deps = [
"//pkg/log",
"//pkg/sync",
"//pkg/unet",
"//pkg/urpc",
],
+1 -1
View File
@@ -22,9 +22,9 @@ package server
import (
"os"
"sync"
"gvisor.dev/gvisor/pkg/log"
"gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/unet"
"gvisor.dev/gvisor/pkg/urpc"
)
+2
View File
@@ -15,6 +15,7 @@ go_library(
deps = [
":eventchannel_go_proto",
"//pkg/log",
"//pkg/sync",
"//pkg/unet",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_golang_protobuf//ptypes:go_default_library_gen",
@@ -40,6 +41,7 @@ go_test(
srcs = ["event_test.go"],
embed = [":eventchannel"],
deps = [
"//pkg/sync",
"@com_github_golang_protobuf//proto:go_default_library",
],
)
+1 -1
View File
@@ -22,13 +22,13 @@ package eventchannel
import (
"encoding/binary"
"fmt"
"sync"
"syscall"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
pb "gvisor.dev/gvisor/pkg/eventchannel/eventchannel_go_proto"
"gvisor.dev/gvisor/pkg/log"
"gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/unet"
)
+1 -1
View File
@@ -16,11 +16,11 @@ package eventchannel
import (
"fmt"
"sync"
"testing"
"time"
"github.com/golang/protobuf/proto"
"gvisor.dev/gvisor/pkg/sync"
)
// testEmitter is an emitter that can be used in tests. It records all events
+1
View File
@@ -15,4 +15,5 @@ go_test(
size = "small",
srcs = ["fdchannel_test.go"],
embed = [":fdchannel"],
deps = ["//pkg/sync"],
)
+2 -1
View File
@@ -17,10 +17,11 @@ package fdchannel
import (
"io/ioutil"
"os"
"sync"
"syscall"
"testing"
"time"
"gvisor.dev/gvisor/pkg/sync"
)
func TestSendRecvFD(t *testing.T) {
+1
View File
@@ -11,6 +11,7 @@ go_library(
importpath = "gvisor.dev/gvisor/pkg/fdnotifier",
visibility = ["//:sandbox"],
deps = [
"//pkg/sync",
"//pkg/waiter",
"@org_golang_x_sys//unix:go_default_library",
],
+1 -1
View File
@@ -22,10 +22,10 @@ package fdnotifier
import (
"fmt"
"sync"
"syscall"
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/waiter"
)
+2 -1
View File
@@ -19,7 +19,7 @@ go_library(
"//pkg/abi/linux",
"//pkg/log",
"//pkg/memutil",
"//pkg/syncutil",
"//pkg/sync",
],
)
@@ -31,4 +31,5 @@ go_test(
"flipcall_test.go",
],
embed = [":flipcall"],
deps = ["//pkg/sync"],
)
+2 -1
View File
@@ -17,7 +17,8 @@ package flipcall
import (
"bytes"
"fmt"
"sync"
"gvisor.dev/gvisor/pkg/sync"
)
func Example() {
+2 -1
View File
@@ -16,9 +16,10 @@ package flipcall
import (
"runtime"
"sync"
"testing"
"time"
"gvisor.dev/gvisor/pkg/sync"
)
var testPacketWindowSize = pageSize
+5 -5
View File
@@ -18,7 +18,7 @@ import (
"reflect"
"unsafe"
"gvisor.dev/gvisor/pkg/syncutil"
"gvisor.dev/gvisor/pkg/sync"
)
// Packets consist of a 16-byte header followed by an arbitrarily-sized
@@ -75,13 +75,13 @@ func (ep *Endpoint) Data() []byte {
var ioSync int64
func raceBecomeActive() {
if syncutil.RaceEnabled {
syncutil.RaceAcquire((unsafe.Pointer)(&ioSync))
if sync.RaceEnabled {
sync.RaceAcquire((unsafe.Pointer)(&ioSync))
}
}
func raceBecomeInactive() {
if syncutil.RaceEnabled {
syncutil.RaceReleaseMerge((unsafe.Pointer)(&ioSync))
if sync.RaceEnabled {
sync.RaceReleaseMerge((unsafe.Pointer)(&ioSync))
}
}
+1
View File
@@ -19,5 +19,6 @@ go_test(
],
deps = [
":gate",
"//pkg/sync",
],
)

Some files were not shown because too many files have changed in this diff Show More