4f4a855d82
Reviewed-on: https://go-review.googlesource.com/c/158019 gotools/: * Makefile.am (go_cmd_vet_files): Update for Go1.12beta2 release. (GOTOOLS_TEST_TIMEOUT): Increase to 600. (check-runtime): Export LD_LIBRARY_PATH before computing GOARCH and GOOS. (check-vet): Copy golang.org/x/tools into check-vet-dir. * Makefile.in: Regenerate. gcc/testsuite/: * go.go-torture/execute/names-1.go: Stop using debug/xcoff, which is no longer externally visible. From-SVN: r268084
78 lines
2.6 KiB
Go
78 lines
2.6 KiB
Go
// 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 (
|
|
"runtime/internal/atomic"
|
|
"unsafe"
|
|
)
|
|
|
|
// 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:nosplit
|
|
func atomicwb(ptr *unsafe.Pointer, new unsafe.Pointer) {
|
|
slot := (*uintptr)(unsafe.Pointer(ptr))
|
|
if !getg().m.p.ptr().wbBuf.putFast(*slot, uintptr(new)) {
|
|
wbBufFlush(slot, uintptr(new))
|
|
}
|
|
}
|
|
|
|
// atomicstorep performs *ptr = new atomically and invokes a write barrier.
|
|
//
|
|
//go:nosplit
|
|
func atomicstorep(ptr unsafe.Pointer, new unsafe.Pointer) {
|
|
if writeBarrier.enabled {
|
|
atomicwb((*unsafe.Pointer)(ptr), new)
|
|
}
|
|
atomic.StorepNoWB(noescape(ptr), 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.
|
|
|
|
//go:linkname sync_atomic_StoreUintptr sync..z2fatomic.StoreUintptr
|
|
func sync_atomic_StoreUintptr(ptr *uintptr, new uintptr)
|
|
|
|
//go:linkname sync_atomic_StorePointer sync..z2fatomic.StorePointer
|
|
//go:nosplit
|
|
func sync_atomic_StorePointer(ptr *unsafe.Pointer, new unsafe.Pointer) {
|
|
if writeBarrier.enabled {
|
|
atomicwb(ptr, new)
|
|
}
|
|
sync_atomic_StoreUintptr((*uintptr)(unsafe.Pointer(ptr)), uintptr(new))
|
|
}
|
|
|
|
//go:linkname sync_atomic_SwapUintptr sync..z2fatomic.SwapUintptr
|
|
func sync_atomic_SwapUintptr(ptr *uintptr, new uintptr) uintptr
|
|
|
|
//go:linkname sync_atomic_SwapPointer sync..z2fatomic.SwapPointer
|
|
//go:nosplit
|
|
func sync_atomic_SwapPointer(ptr *unsafe.Pointer, new unsafe.Pointer) unsafe.Pointer {
|
|
if writeBarrier.enabled {
|
|
atomicwb(ptr, new)
|
|
}
|
|
old := unsafe.Pointer(sync_atomic_SwapUintptr((*uintptr)(noescape(unsafe.Pointer(ptr))), uintptr(new)))
|
|
return old
|
|
}
|
|
|
|
//go:linkname sync_atomic_CompareAndSwapUintptr sync..z2fatomic.CompareAndSwapUintptr
|
|
func sync_atomic_CompareAndSwapUintptr(ptr *uintptr, old, new uintptr) bool
|
|
|
|
//go:linkname sync_atomic_CompareAndSwapPointer sync..z2fatomic.CompareAndSwapPointer
|
|
//go:nosplit
|
|
func sync_atomic_CompareAndSwapPointer(ptr *unsafe.Pointer, old, new unsafe.Pointer) bool {
|
|
if writeBarrier.enabled {
|
|
atomicwb(ptr, new)
|
|
}
|
|
return sync_atomic_CompareAndSwapUintptr((*uintptr)(noescape(unsafe.Pointer(ptr))), uintptr(old), uintptr(new))
|
|
}
|