github.com/hbdrawn/golang@v0.0.0-20141214014649-6b835209aba2/src/runtime/atomic_amd64x.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build amd64 amd64p32 6 7 package runtime 8 9 import "unsafe" 10 11 // The calls to nop are to keep these functions from being inlined. 12 // If they are inlined we have no guarantee that later rewrites of the 13 // code by optimizers will preserve the relative order of memory accesses. 14 15 //go:nosplit 16 func atomicload(ptr *uint32) uint32 { 17 nop() 18 return *ptr 19 } 20 21 //go:nosplit 22 func atomicloadp(ptr unsafe.Pointer) unsafe.Pointer { 23 nop() 24 return *(*unsafe.Pointer)(ptr) 25 } 26 27 //go:nosplit 28 func atomicload64(ptr *uint64) uint64 { 29 nop() 30 return *ptr 31 } 32 33 //go:noescape 34 func xadd(ptr *uint32, delta int32) uint32 35 36 //go:noescape 37 func xadd64(ptr *uint64, delta int64) uint64 38 39 //go:noescape 40 func xchg(ptr *uint32, new uint32) uint32 41 42 //go:noescape 43 func xchg64(ptr *uint64, new uint64) uint64 44 45 // xchgp cannot have a go:noescape annotation, because 46 // while ptr does not escape, new does. If new is marked as 47 // not escaping, the compiler will make incorrect escape analysis 48 // decisions about the value being xchg'ed. 49 // Instead, make xchgp a wrapper around the actual atomic. 50 // When calling the wrapper we mark ptr as noescape explicitly. 51 52 //go:nosplit 53 func xchgp(ptr unsafe.Pointer, new unsafe.Pointer) unsafe.Pointer { 54 return xchgp1(noescape(ptr), new) 55 } 56 57 func xchgp1(ptr unsafe.Pointer, new unsafe.Pointer) unsafe.Pointer 58 59 //go:noescape 60 func xchguintptr(ptr *uintptr, new uintptr) uintptr 61 62 //go:noescape 63 func atomicor8(ptr *uint8, val uint8) 64 65 //go:noescape 66 func cas64(ptr *uint64, old, new uint64) bool 67 68 //go:noescape 69 func atomicstore(ptr *uint32, val uint32) 70 71 //go:noescape 72 func atomicstore64(ptr *uint64, val uint64) 73 74 // atomicstorep cannot have a go:noescape annotation. 75 // See comment above for xchgp. 76 77 //go:nosplit 78 func atomicstorep(ptr unsafe.Pointer, new unsafe.Pointer) { 79 atomicstorep1(noescape(ptr), new) 80 } 81 82 func atomicstorep1(ptr unsafe.Pointer, val unsafe.Pointer)