// 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".////go:nosplitfunc atomicwb( *unsafe.Pointer, unsafe.Pointer) { := (*uintptr)(unsafe.Pointer())if !getg().m.p.ptr().wbBuf.putFast(*, uintptr()) {wbBufFlush(, uintptr()) }}// atomicstorep performs *ptr = new atomically and invokes a write barrier.////go:nosplitfunc atomicstorep( unsafe.Pointer, unsafe.Pointer) {ifwriteBarrier.enabled {atomicwb((*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 runtime/internal/atomic.storePointerfunc atomic_storePointer( *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 runtime/internal/atomic.casPointerfunc atomic_casPointer( *unsafe.Pointer, , unsafe.Pointer) bool {ifwriteBarrier.enabled {atomicwb(, ) }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(, ) }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(, ) } := 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(, ) }returnsync_atomic_CompareAndSwapUintptr((*uintptr)(noescape(unsafe.Pointer())), uintptr(), uintptr())}
The pages are generated with Goldsv0.6.4. (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 @Go100and1 (reachable from the left QR code) to get the latest news of Golds.