github.com/sean-/go@v0.0.0-20151219100004-97f854cd7bb6/src/runtime/internal/atomic/atomic_386.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 386 6 7 package atomic 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 Load(ptr *uint32) uint32 { 17 nop() 18 return *ptr 19 } 20 21 //go:nosplit 22 func Loadp(ptr unsafe.Pointer) unsafe.Pointer { 23 nop() 24 return *(*unsafe.Pointer)(ptr) 25 } 26 27 //go:nosplit 28 func Xadd64(ptr *uint64, delta int64) uint64 { 29 for { 30 old := *ptr 31 if Cas64(ptr, old, old+uint64(delta)) { 32 return old + uint64(delta) 33 } 34 } 35 } 36 37 //go:noescape 38 func Xadduintptr(ptr *uintptr, delta uintptr) uintptr 39 40 //go:nosplit 41 func Xchg64(ptr *uint64, new uint64) uint64 { 42 for { 43 old := *ptr 44 if Cas64(ptr, old, new) { 45 return old 46 } 47 } 48 } 49 50 //go:noescape 51 func Xadd(ptr *uint32, delta int32) uint32 52 53 //go:noescape 54 func Xchg(ptr *uint32, new uint32) uint32 55 56 //go:noescape 57 func Xchguintptr(ptr *uintptr, new uintptr) uintptr 58 59 //go:noescape 60 func Load64(ptr *uint64) uint64 61 62 //go:noescape 63 func And8(ptr *uint8, val uint8) 64 65 //go:noescape 66 func Or8(ptr *uint8, val uint8) 67 68 // NOTE: Do not add atomicxor8 (XOR is not idempotent). 69 70 //go:noescape 71 func Cas64(ptr *uint64, old, new uint64) bool 72 73 //go:noescape 74 func Store(ptr *uint32, val uint32) 75 76 //go:noescape 77 func Store64(ptr *uint64, val uint64) 78 79 // NO go:noescape annotation; see atomic_pointer.go. 80 func Storep1(ptr unsafe.Pointer, val unsafe.Pointer)