summaryrefslogtreecommitdiffhomepage
path: root/third_party/gvsync/downgradable_rwmutex_unsafe.go
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2019-05-30 12:01:41 -0700
committerShentubot <shentubot@google.com>2019-05-30 12:09:39 -0700
commit38de91b028639ef5f4a4c8874b3ee23503fd2f3a (patch)
tree8d58a49107c491688a89c805336690ca493bf008 /third_party/gvsync/downgradable_rwmutex_unsafe.go
parente3c5fa3345139a38b380e14067640931ce885288 (diff)
Add build guard to files using go:linkname
Funcion signatures are not validated during compilation. Since they are not exported, they can change at any time. The guard ensures that they are verified at least on every version upgrade. PiperOrigin-RevId: 250733742
Diffstat (limited to 'third_party/gvsync/downgradable_rwmutex_unsafe.go')
-rw-r--r--third_party/gvsync/downgradable_rwmutex_unsafe.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/third_party/gvsync/downgradable_rwmutex_unsafe.go b/third_party/gvsync/downgradable_rwmutex_unsafe.go
index 4d43eb765..069939033 100644
--- a/third_party/gvsync/downgradable_rwmutex_unsafe.go
+++ b/third_party/gvsync/downgradable_rwmutex_unsafe.go
@@ -3,6 +3,11 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// +build go1.12
+// +build !go1.14
+
+// Check go:linkname function signatures when updating Go version.
+
// This is mostly copied from the standard library's sync/rwmutex.go.
//
// Happens-before relationships indicated to the race detector:
@@ -19,6 +24,9 @@ import (
"unsafe"
)
+//go:linkname runtimeSemacquire sync.runtime_Semacquire
+func runtimeSemacquire(s *uint32)
+
// DowngradableRWMutex is identical to sync.RWMutex, but adds the DowngradeLock
// method.
type DowngradableRWMutex struct {
@@ -62,7 +70,7 @@ func (rw *DowngradableRWMutex) RUnlock() {
// A writer is pending.
if atomic.AddInt32(&rw.readerWait, -1) == 0 {
// The last reader unblocks the writer.
- runtimeSemrelease(&rw.writerSem, false)
+ runtimeSemrelease(&rw.writerSem, false, 0)
}
}
if RaceEnabled {
@@ -103,7 +111,7 @@ func (rw *DowngradableRWMutex) Unlock() {
}
// Unblock blocked readers, if any.
for i := 0; i < int(r); i++ {
- runtimeSemrelease(&rw.readerSem, false)
+ runtimeSemrelease(&rw.readerSem, false, 0)
}
// Allow other writers to proceed.
rw.w.Unlock()
@@ -126,7 +134,7 @@ func (rw *DowngradableRWMutex) DowngradeLock() {
// Unblock blocked readers, if any. Note that this loop starts as 1 since r
// includes this goroutine.
for i := 1; i < int(r); i++ {
- runtimeSemrelease(&rw.readerSem, false)
+ runtimeSemrelease(&rw.readerSem, false, 0)
}
// Allow other writers to proceed to rw.w.Lock(). Note that they will still
// block on rw.writerSem since at least this reader exists, such that
@@ -136,9 +144,3 @@ func (rw *DowngradableRWMutex) DowngradeLock() {
RaceEnable()
}
}
-
-//go:linkname runtimeSemacquire sync.runtime_Semacquire
-func runtimeSemacquire(s *uint32)
-
-//go:linkname runtimeSemrelease sync.runtime_Semrelease
-func runtimeSemrelease(s *uint32, handoff bool)