aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/atomic_pointer.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2022-10-17 15:33:29 -0400
committerGopher Robot <gobot@golang.org>2022-10-18 14:48:54 +0000
commit9fedc481ea09a0539cd2669312429ef5416a8949 (patch)
treed8762969f7f124d6a38e20d22e1f759f1fab717e /src/runtime/atomic_pointer.go
parent26b48442569102226baba1d9b4a83aaee3d06611 (diff)
downloadgo-9fedc481ea09a0539cd2669312429ef5416a8949.tar.xz
runtime/internal/atomic: add write barrier-enabled pointer atomics
UnsafePointer.Store, UnsafePointer.CompareAndSwap were missing, although .StoreNoWB and .CompareAndSwapNoWB existed. Same for Pointer[T}. Do the linkname tricks necessary to add those methods. Change-Id: I925ee27673288accb15ebe93898f9eb01ab46a98 Reviewed-on: https://go-review.googlesource.com/c/go/+/443379 Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/runtime/atomic_pointer.go')
-rw-r--r--src/runtime/atomic_pointer.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/runtime/atomic_pointer.go b/src/runtime/atomic_pointer.go
index b8f0c22c63..25e0e651b4 100644
--- a/src/runtime/atomic_pointer.go
+++ b/src/runtime/atomic_pointer.go
@@ -35,6 +35,27 @@ func atomicstorep(ptr unsafe.Pointer, new unsafe.Pointer) {
atomic.StorepNoWB(noescape(ptr), new)
}
+// atomic_storePointer is the implementation of runtime/internal/UnsafePointer.Store
+// (like StoreNoWB but with the write barrier).
+//
+//go:nosplit
+//go:linkname atomic_storePointer runtime/internal/atomic.storePointer
+func atomic_storePointer(ptr *unsafe.Pointer, new unsafe.Pointer) {
+ atomicstorep(unsafe.Pointer(ptr), new)
+}
+
+// atomic_casPointer is the implementation of runtime/internal/UnsafePointer.CompareAndSwap
+// (like CompareAndSwapNoWB but with the write barrier).
+//
+//go:nosplit
+//go:linkname atomic_casPointer runtime/internal/atomic.casPointer
+func atomic_casPointer(ptr *unsafe.Pointer, old, new unsafe.Pointer) bool {
+ if writeBarrier.enabled {
+ atomicwb(ptr, new)
+ }
+ return atomic.Casp1(ptr, old, new)
+}
+
// Like above, but implement in terms of sync/atomic's uintptr operations.
// We cannot just call the runtime routines, because the race detector expects
// to be able to intercept the sync/atomic forms but not the runtime forms.