2014-11-11 15:09:09 -07:00
|
|
|
// 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 "unsafe"
|
|
|
|
|
|
|
|
// The calls to nop are to keep these functions from being inlined.
|
|
|
|
// If they are inlined we have no guarantee that later rewrites of the
|
|
|
|
// code by optimizers will preserve the relative order of memory accesses.
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func atomicload(ptr *uint32) uint32 {
|
|
|
|
nop()
|
|
|
|
return *ptr
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func atomicloadp(ptr unsafe.Pointer) unsafe.Pointer {
|
|
|
|
nop()
|
|
|
|
return *(*unsafe.Pointer)(ptr)
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:nosplit
|
|
|
|
func xadd64(ptr *uint64, delta int64) uint64 {
|
|
|
|
for {
|
|
|
|
old := *ptr
|
|
|
|
if cas64(ptr, old, old+uint64(delta)) {
|
|
|
|
return old + uint64(delta)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-16 15:32:18 -06:00
|
|
|
//go:noescape
|
|
|
|
//go:linkname xadduintptr runtime.xadd
|
|
|
|
func xadduintptr(ptr *uintptr, delta uintptr) uintptr
|
|
|
|
|
2014-11-11 15:09:09 -07:00
|
|
|
//go:nosplit
|
|
|
|
func xchg64(ptr *uint64, new uint64) uint64 {
|
|
|
|
for {
|
|
|
|
old := *ptr
|
|
|
|
if cas64(ptr, old, new) {
|
|
|
|
return old
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func xadd(ptr *uint32, delta int32) uint32
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func xchg(ptr *uint32, new uint32) uint32
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func xchguintptr(ptr *uintptr, new uintptr) uintptr
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func atomicload64(ptr *uint64) uint64
|
|
|
|
|
2015-03-19 17:42:16 -06:00
|
|
|
//go:noescape
|
|
|
|
func atomicand8(ptr *uint8, val uint8)
|
|
|
|
|
2014-11-11 15:09:09 -07:00
|
|
|
//go:noescape
|
|
|
|
func atomicor8(ptr *uint8, val uint8)
|
|
|
|
|
2015-03-19 17:42:16 -06:00
|
|
|
// NOTE: Do not add atomicxor8 (XOR is not idempotent).
|
|
|
|
|
2014-11-11 15:09:09 -07:00
|
|
|
//go:noescape
|
|
|
|
func cas64(ptr *uint64, old, new uint64) bool
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func atomicstore(ptr *uint32, val uint32)
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func atomicstore64(ptr *uint64, val uint64)
|
|
|
|
|
2014-12-22 20:50:42 -07:00
|
|
|
// NO go:noescape annotation; see atomic_pointer.go.
|
2014-11-11 15:09:09 -07:00
|
|
|
func atomicstorep1(ptr unsafe.Pointer, val unsafe.Pointer)
|