Source File
atomic_pointer.go
Belonging Package
runtime
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package runtime
import (
)
// These functions cannot have go:noescape annotations,
// because while ptr does not escape, new does.
// If new is marked as not escaping, the compiler will make incorrect
// escape analysis decisions about the pointer value being stored.
// atomicwb performs a write barrier before an atomic pointer write.
// The caller should guard the call with "if writeBarrier.enabled".
//
// atomicwb should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/bytedance/gopkg
// - github.com/songzhibin97/gkit
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname atomicwb
//go:nosplit
func ( *unsafe.Pointer, unsafe.Pointer) {
:= (*uintptr)(unsafe.Pointer())
:= getg().m.p.ptr().wbBuf.get2()
[0] = *
[1] = uintptr()
}
// atomicstorep performs *ptr = new atomically and invokes a write barrier.
//
//go:nosplit
func ( unsafe.Pointer, unsafe.Pointer) {
if writeBarrier.enabled {
atomicwb((*unsafe.Pointer)(), )
}
if goexperiment.CgoCheck2 {
cgoCheckPtrWrite((*unsafe.Pointer)(), )
}
atomic.StorepNoWB(noescape(), )
}
// atomic_storePointer is the implementation of runtime/internal/UnsafePointer.Store
// (like StoreNoWB but with the write barrier).
//
//go:nosplit
//go:linkname atomic_storePointer internal/runtime/atomic.storePointer
func ( *unsafe.Pointer, unsafe.Pointer) {
atomicstorep(unsafe.Pointer(), )
}
// atomic_casPointer is the implementation of runtime/internal/UnsafePointer.CompareAndSwap
// (like CompareAndSwapNoWB but with the write barrier).
//
//go:nosplit
//go:linkname atomic_casPointer internal/runtime/atomic.casPointer
func ( *unsafe.Pointer, , unsafe.Pointer) bool {
if writeBarrier.enabled {
atomicwb(, )
}
if goexperiment.CgoCheck2 {
cgoCheckPtrWrite(, )
}
return atomic.Casp1(, , )
}
// 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.
//go:linkname sync_atomic_StoreUintptr sync/atomic.StoreUintptr
func ( *uintptr, uintptr)
//go:linkname sync_atomic_StorePointer sync/atomic.StorePointer
//go:nosplit
func ( *unsafe.Pointer, unsafe.Pointer) {
if writeBarrier.enabled {
atomicwb(, )
}
if goexperiment.CgoCheck2 {
cgoCheckPtrWrite(, )
}
sync_atomic_StoreUintptr((*uintptr)(unsafe.Pointer()), uintptr())
}
//go:linkname sync_atomic_SwapUintptr sync/atomic.SwapUintptr
func ( *uintptr, uintptr) uintptr
//go:linkname sync_atomic_SwapPointer sync/atomic.SwapPointer
//go:nosplit
func ( *unsafe.Pointer, unsafe.Pointer) unsafe.Pointer {
if writeBarrier.enabled {
atomicwb(, )
}
if goexperiment.CgoCheck2 {
cgoCheckPtrWrite(, )
}
:= unsafe.Pointer(sync_atomic_SwapUintptr((*uintptr)(noescape(unsafe.Pointer())), uintptr()))
return
}
//go:linkname sync_atomic_CompareAndSwapUintptr sync/atomic.CompareAndSwapUintptr
func ( *uintptr, , uintptr) bool
//go:linkname sync_atomic_CompareAndSwapPointer sync/atomic.CompareAndSwapPointer
//go:nosplit
func ( *unsafe.Pointer, , unsafe.Pointer) bool {
if writeBarrier.enabled {
atomicwb(, )
}
if goexperiment.CgoCheck2 {
cgoCheckPtrWrite(, )
}
return sync_atomic_CompareAndSwapUintptr((*uintptr)(noescape(unsafe.Pointer())), uintptr(), uintptr())
}
The pages are generated with Golds v0.7.6. (GOOS=linux GOARCH=amd64)