// 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 runtimeimport ()// 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:nosplitfunc atomicwb( *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:nosplitfunc atomicstorep( unsafe.Pointer, unsafe.Pointer) {ifwriteBarrier.enabled {atomicwb((*unsafe.Pointer)(), ) }ifgoexperiment.CgoCheck2 {cgoCheckPtrWrite((*unsafe.Pointer)(), ) }atomic.StorepNoWB(noescape(), )}// atomic_storePointer is the implementation of internal/runtime/atomic.UnsafePointer.Store// (like StoreNoWB but with the write barrier).////go:nosplit//go:linkname atomic_storePointer internal/runtime/atomic.storePointerfunc atomic_storePointer( *unsafe.Pointer, unsafe.Pointer) {atomicstorep(unsafe.Pointer(), )}// atomic_casPointer is the implementation of internal/runtime/atomic.UnsafePointer.CompareAndSwap// (like CompareAndSwapNoWB but with the write barrier).////go:nosplit//go:linkname atomic_casPointer internal/runtime/atomic.casPointerfunc atomic_casPointer( *unsafe.Pointer, , unsafe.Pointer) bool {ifwriteBarrier.enabled {atomicwb(, ) }ifgoexperiment.CgoCheck2 {cgoCheckPtrWrite(, ) }returnatomic.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.StoreUintptrfunc sync_atomic_StoreUintptr( *uintptr, uintptr)//go:linkname sync_atomic_StorePointer sync/atomic.StorePointer//go:nosplitfunc sync_atomic_StorePointer( *unsafe.Pointer, unsafe.Pointer) {ifwriteBarrier.enabled {atomicwb(, ) }ifgoexperiment.CgoCheck2 {cgoCheckPtrWrite(, ) }sync_atomic_StoreUintptr((*uintptr)(unsafe.Pointer()), uintptr())}//go:linkname sync_atomic_SwapUintptr sync/atomic.SwapUintptrfunc sync_atomic_SwapUintptr( *uintptr, uintptr) uintptr//go:linkname sync_atomic_SwapPointer sync/atomic.SwapPointer//go:nosplitfunc sync_atomic_SwapPointer( *unsafe.Pointer, unsafe.Pointer) unsafe.Pointer {ifwriteBarrier.enabled {atomicwb(, ) }ifgoexperiment.CgoCheck2 {cgoCheckPtrWrite(, ) } := unsafe.Pointer(sync_atomic_SwapUintptr((*uintptr)(noescape(unsafe.Pointer())), uintptr()))return}//go:linkname sync_atomic_CompareAndSwapUintptr sync/atomic.CompareAndSwapUintptrfunc sync_atomic_CompareAndSwapUintptr( *uintptr, , uintptr) bool//go:linkname sync_atomic_CompareAndSwapPointer sync/atomic.CompareAndSwapPointer//go:nosplitfunc sync_atomic_CompareAndSwapPointer( *unsafe.Pointer, , unsafe.Pointer) bool {ifwriteBarrier.enabled {atomicwb(, ) }ifgoexperiment.CgoCheck2 {cgoCheckPtrWrite(, ) }returnsync_atomic_CompareAndSwapUintptr((*uintptr)(noescape(unsafe.Pointer())), uintptr(), uintptr())}
The pages are generated with Goldsv0.7.7-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.