Move package sync to third_party

PiperOrigin-RevId: 231889261
Change-Id: I482f1df055bcedf4edb9fe3fe9b8e9c80085f1a0
This commit is contained in:
Michael Pratt
2019-01-31 17:49:14 -08:00
committed by Shentubot
parent 4e695adcd0
commit fe1369ac98
26 changed files with 124 additions and 200 deletions
+2 -2
View File
@@ -34,7 +34,7 @@ go_template_instance(
out = "seqatomic_taskgoroutineschedinfo.go",
package = "kernel",
suffix = "TaskGoroutineSchedInfo",
template = "//pkg/sync:generic_seqatomic",
template = "//third_party/gvsync:generic_seqatomic",
types = {
"Value": "TaskGoroutineSchedInfo",
},
@@ -183,12 +183,12 @@ go_library(
"//pkg/sentry/usermem",
"//pkg/state",
"//pkg/state/statefile",
"//pkg/sync",
"//pkg/syserr",
"//pkg/syserror",
"//pkg/tcpip",
"//pkg/tcpip/stack",
"//pkg/waiter",
"//third_party/gvsync",
],
)
+1 -1
View File
@@ -8,7 +8,7 @@ go_template_instance(
out = "atomicptr_bucket.go",
package = "futex",
suffix = "Bucket",
template = "//pkg/sync:generic_atomicptr",
template = "//third_party/gvsync:generic_atomicptr",
types = {
"Value": "bucket",
},
+2 -2
View File
@@ -34,7 +34,7 @@ import (
"gvisor.googlesource.com/gvisor/pkg/sentry/uniqueid"
"gvisor.googlesource.com/gvisor/pkg/sentry/usage"
"gvisor.googlesource.com/gvisor/pkg/sentry/usermem"
ssync "gvisor.googlesource.com/gvisor/pkg/sync"
"gvisor.googlesource.com/gvisor/third_party/gvsync"
)
// Task represents a thread of execution in the untrusted app. It
@@ -81,7 +81,7 @@ type Task struct {
//
// gosched is protected by goschedSeq. gosched is owned by the task
// goroutine.
goschedSeq ssync.SeqCount `state:"nosave"`
goschedSeq gvsync.SeqCount `state:"nosave"`
gosched TaskGoroutineSchedInfo
// yieldCount is the number of times the task goroutine has called
+1 -1
View File
@@ -116,9 +116,9 @@ go_library(
"//pkg/sentry/safemem",
"//pkg/sentry/usage",
"//pkg/sentry/usermem",
"//pkg/sync",
"//pkg/syserror",
"//pkg/tcpip/buffer",
"//third_party/gvsync",
],
)
+3 -3
View File
@@ -42,7 +42,7 @@ import (
"gvisor.googlesource.com/gvisor/pkg/sentry/platform"
"gvisor.googlesource.com/gvisor/pkg/sentry/safemem"
"gvisor.googlesource.com/gvisor/pkg/sentry/usermem"
ssync "gvisor.googlesource.com/gvisor/pkg/sync"
"gvisor.googlesource.com/gvisor/third_party/gvsync"
)
// MemoryManager implements a virtual address space.
@@ -84,7 +84,7 @@ type MemoryManager struct {
users int32
// mappingMu is analogous to Linux's struct mm_struct::mmap_sem.
mappingMu ssync.DowngradableRWMutex `state:"nosave"`
mappingMu gvsync.DowngradableRWMutex `state:"nosave"`
// vmas stores virtual memory areas. Since vmas are stored by value,
// clients should usually use vmaIterator.ValuePtr() instead of
@@ -121,7 +121,7 @@ type MemoryManager struct {
// activeMu is loosely analogous to Linux's struct
// mm_struct::page_table_lock.
activeMu ssync.DowngradableRWMutex `state:"nosave"`
activeMu gvsync.DowngradableRWMutex `state:"nosave"`
// pmas stores platform mapping areas used to implement vmas. Since pmas
// are stored by value, clients should usually use pmaIterator.ValuePtr()
+2 -2
View File
@@ -9,7 +9,7 @@ go_template_instance(
out = "seqatomic_parameters.go",
package = "time",
suffix = "Parameters",
template = "//pkg/sync:generic_seqatomic",
template = "//third_party/gvsync:generic_seqatomic",
types = {
"Value": "Parameters",
},
@@ -36,8 +36,8 @@ go_library(
deps = [
"//pkg/log",
"//pkg/metric",
"//pkg/sync",
"//pkg/syserror",
"//third_party/gvsync",
],
)
-40
View File
@@ -1,40 +0,0 @@
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package atomicptr
import (
"testing"
)
func newInt(val int) *int {
return &val
}
func TestAtomicPtr(t *testing.T) {
var p AtomicPtrInt
if got := p.Load(); got != nil {
t.Errorf("initial value is %p (%v), wanted nil", got, got)
}
want := newInt(42)
p.Store(want)
if got := p.Load(); got != want {
t.Errorf("wrong value: got %p (%v), wanted %p (%v)", got, got, want, want)
}
want = newInt(100)
p.Store(want)
if got := p.Load(); got != want {
t.Errorf("wrong value: got %p (%v), wanted %p (%v)", got, got, want, want)
}
}
-32
View File
@@ -1,32 +0,0 @@
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package sync
import (
"unsafe"
)
// Memmove is exported for SeqAtomicLoad/SeqAtomicTryLoad<T>, which can't
// define it because go_generics can't update the go:linkname annotation.
// Furthermore, go:linkname silently doesn't work if the local name is exported
// (this is of course undocumented), which is why this indirection is
// necessary.
func Memmove(to, from unsafe.Pointer, n uintptr) {
memmove(to, from, n)
}
//go:linkname memmove runtime.memmove
//go:noescape
func memmove(to, from unsafe.Pointer, n uintptr)
-16
View File
@@ -1,16 +0,0 @@
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package sync provides synchronization primitives.
package sync
+6 -6
View File
@@ -1,4 +1,4 @@
load("//tools/go_stateify:defs.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
package(
default_visibility = ["//:sandbox"],
@@ -27,24 +27,24 @@ go_template(
)
go_library(
name = "sync",
name = "gvsync",
srcs = [
"downgradable_rwmutex_unsafe.go",
"gvsync.go",
"memmove_unsafe.go",
"norace_unsafe.go",
"race_unsafe.go",
"seqcount.go",
"sync.go",
],
importpath = "gvisor.googlesource.com/gvisor/pkg/sync",
importpath = "gvisor.googlesource.com/gvisor/third_party/gvsync",
)
go_test(
name = "sync_test",
name = "gvsync_test",
size = "small",
srcs = [
"downgradable_rwmutex_test.go",
"seqcount_test.go",
],
embed = [":sync"],
embed = [":gvsync"],
)
View File
+3
View File
@@ -0,0 +1,3 @@
This package provides additional synchronization primitives not provided by the
Go stdlib 'sync' package. It is partially derived from the upstream 'sync'
package.
@@ -1,16 +1,7 @@
// Copyright 2018 Google LLC
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package template doesn't exist. This file must be instantiated using the
// go_template_instance rule in tools/go_generics/defs.bzl.
@@ -1,4 +1,4 @@
load("//tools/go_stateify:defs.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
package(licenses = ["notice"])
@@ -9,7 +9,7 @@ go_template_instance(
out = "atomicptr_int.go",
package = "atomicptr",
suffix = "Int",
template = "//pkg/sync:generic_atomicptr",
template = "//third_party/gvsync:generic_atomicptr",
types = {
"Value": "int",
},
@@ -18,7 +18,7 @@ go_template_instance(
go_library(
name = "atomicptr",
srcs = ["atomicptr_int.go"],
importpath = "gvisor.googlesource.com/gvisor/pkg/sync/atomicptr",
importpath = "gvisor.googlesource.com/gvisor/third_party/gvsync/atomicptr",
)
go_test(
+31
View File
@@ -0,0 +1,31 @@
// Copyright 2019 Google LLC
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package atomicptr
import (
"testing"
)
func newInt(val int) *int {
return &val
}
func TestAtomicPtr(t *testing.T) {
var p AtomicPtrInt
if got := p.Load(); got != nil {
t.Errorf("initial value is %p (%v), wanted nil", got, got)
}
want := newInt(42)
p.Store(want)
if got := p.Load(); got != want {
t.Errorf("wrong value: got %p (%v), wanted %p (%v)", got, got, want, want)
}
want = newInt(100)
p.Store(want)
if got := p.Load(); got != want {
t.Errorf("wrong value: got %p (%v), wanted %p (%v)", got, got, want, want)
}
}
@@ -1,4 +1,5 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Copyright 2019 Google LLC
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@@ -8,7 +9,7 @@
// addition of downgradingWriter and the renaming of num_iterations to
// numIterations to shut up Golint.
package sync
package gvsync
import (
"fmt"
@@ -1,4 +1,5 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Copyright 2019 Google LLC
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@@ -10,7 +11,7 @@
// - RUnlock -> Lock (via writerSem)
// - DowngradeLock -> RLock (via readerSem)
package sync
package gvsync
import (
"sync"
+7
View File
@@ -0,0 +1,7 @@
// Copyright 2019 Google LLC
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package gvsync provides synchronization primitives.
package gvsync
+23
View File
@@ -0,0 +1,23 @@
// Copyright 2019 Google LLC
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gvsync
import (
"unsafe"
)
// Memmove is exported for SeqAtomicLoad/SeqAtomicTryLoad<T>, which can't
// define it because go_generics can't update the go:linkname annotation.
// Furthermore, go:linkname silently doesn't work if the local name is exported
// (this is of course undocumented), which is why this indirection is
// necessary.
func Memmove(to, from unsafe.Pointer, n uintptr) {
memmove(to, from, n)
}
//go:linkname memmove runtime.memmove
//go:noescape
func memmove(to, from unsafe.Pointer, n uintptr)
@@ -1,20 +1,11 @@
// Copyright 2018 Google LLC
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !race
package sync
package gvsync
import (
"unsafe"

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