summaryrefslogtreecommitdiffhomepage
path: root/pkg/sync/seqatomic_unsafe.go
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2019-01-31 17:47:24 -0800
committerShentubot <shentubot@google.com>2019-01-31 17:49:14 -0800
commitfe1369ac98a4f1d8af5e8be6da71165339e52034 (patch)
tree89c1e4553a375b57e9999278613eb37f104e30a6 /pkg/sync/seqatomic_unsafe.go
parent4e695adcd0c739101c3d50431ca18b1b911c9238 (diff)
Move package sync to third_party
PiperOrigin-RevId: 231889261 Change-Id: I482f1df055bcedf4edb9fe3fe9b8e9c80085f1a0
Diffstat (limited to 'pkg/sync/seqatomic_unsafe.go')
-rw-r--r--pkg/sync/seqatomic_unsafe.go81
1 files changed, 0 insertions, 81 deletions
diff --git a/pkg/sync/seqatomic_unsafe.go b/pkg/sync/seqatomic_unsafe.go
deleted file mode 100644
index bea31adc5..000000000
--- a/pkg/sync/seqatomic_unsafe.go
+++ /dev/null
@@ -1,81 +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 template doesn't exist. This file must be instantiated using the
-// go_template_instance rule in tools/go_generics/defs.bzl.
-package template
-
-import (
- "fmt"
- "reflect"
- "strings"
- "unsafe"
-
- ssync "gvisor.googlesource.com/gvisor/pkg/sync"
-)
-
-// Value is a required type parameter.
-//
-// Value must not contain any pointers, including interface objects, function
-// objects, slices, maps, channels, unsafe.Pointer, and arrays or structs
-// containing any of the above. An init() function will panic if this property
-// does not hold.
-type Value struct{}
-
-// SeqAtomicLoad returns a copy of *ptr, ensuring that the read does not race
-// with any writer critical sections in sc.
-func SeqAtomicLoad(sc *ssync.SeqCount, ptr *Value) Value {
- // This function doesn't use SeqAtomicTryLoad because doing so is
- // measurably, significantly (~20%) slower; Go is awful at inlining.
- var val Value
- for {
- epoch := sc.BeginRead()
- if ssync.RaceEnabled {
- // runtime.RaceDisable() doesn't actually stop the race detector,
- // so it can't help us here. Instead, call runtime.memmove
- // directly, which is not instrumented by the race detector.
- ssync.Memmove(unsafe.Pointer(&val), unsafe.Pointer(ptr), unsafe.Sizeof(val))
- } else {
- // This is ~40% faster for short reads than going through memmove.
- val = *ptr
- }
- if sc.ReadOk(epoch) {
- break
- }
- }
- return val
-}
-
-// SeqAtomicTryLoad returns a copy of *ptr while in a reader critical section
-// in sc initiated by a call to sc.BeginRead() that returned epoch. If the read
-// would race with a writer critical section, SeqAtomicTryLoad returns
-// (unspecified, false).
-func SeqAtomicTryLoad(sc *ssync.SeqCount, epoch ssync.SeqCountEpoch, ptr *Value) (Value, bool) {
- var val Value
- if ssync.RaceEnabled {
- ssync.Memmove(unsafe.Pointer(&val), unsafe.Pointer(ptr), unsafe.Sizeof(val))
- } else {
- val = *ptr
- }
- return val, sc.ReadOk(epoch)
-}
-
-func init() {
- var val Value
- typ := reflect.TypeOf(val)
- name := typ.Name()
- if ptrs := ssync.PointersInType(typ, name); len(ptrs) != 0 {
- panic(fmt.Sprintf("SeqAtomicLoad<%s> is invalid since values %s of type %s contain pointers:\n%s", typ, name, typ, strings.Join(ptrs, "\n")))
- }
-}