| 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 |
package atomic |
| 6 |
|
| 7 |
import "unsafe" |
| 8 |
|
| 9 |
// Export some functions via linkname to assembly in sync/atomic. |
| 10 |
// |
| 11 |
//go:linkname Load |
| 12 |
//go:linkname Loadp |
| 13 |
//go:linkname Load64 |
| 14 |
|
| 15 |
//go:nosplit |
| 16 |
//go:noinline |
| 17 |
func Load(ptr *uint32) uint32 { |
| 18 |
return *ptr |
| 19 |
} |
| 20 |
|
| 21 |
//go:nosplit |
| 22 |
//go:noinline |
| 23 |
func Loadp(ptr unsafe.Pointer) unsafe.Pointer { |
| 24 |
return *(*unsafe.Pointer)(ptr) |
| 25 |
} |
| 26 |
|
| 27 |
//go:nosplit |
| 28 |
//go:noinline |
| 29 |
func Load64(ptr *uint64) uint64 { |
| 30 |
return *ptr |
| 31 |
} |
| 32 |
|
| 33 |
//go:nosplit |
| 34 |
//go:noinline |
| 35 |
func LoadAcq(ptr *uint32) uint32 { |
| 36 |
return *ptr |
| 37 |
} |
| 38 |
|
| 39 |
//go:nosplit |
| 40 |
//go:noinline |
| 41 |
func LoadAcq64(ptr *uint64) uint64 { |
| 42 |
return *ptr |
| 43 |
} |
| 44 |
|
| 45 |
//go:nosplit |
| 46 |
//go:noinline |
| 47 |
func LoadAcquintptr(ptr *uintptr) uintptr { |
| 48 |
return *ptr |
| 49 |
} |
| 50 |
|
| 51 |
//go:noescape |
| 52 |
func Xadd(ptr *uint32, delta int32) uint32 |
| 53 |
|
| 54 |
//go:noescape |
| 55 |
func Xadd64(ptr *uint64, delta int64) uint64 |
| 56 |
|
| 57 |
//go:noescape |
| 58 |
func Xadduintptr(ptr *uintptr, delta uintptr) uintptr |
| 59 |
|
| 60 |
//go:noescape |
| 61 |
func Xchg8(ptr *uint8, new uint8) uint8 |
| 62 |
|
| 63 |
//go:noescape |
| 64 |
func Xchg(ptr *uint32, new uint32) uint32 |
| 65 |
|
| 66 |
//go:noescape |
| 67 |
func Xchg64(ptr *uint64, new uint64) uint64 |
| 68 |
|
| 69 |
//go:noescape |
| 70 |
func Xchguintptr(ptr *uintptr, new uintptr) uintptr |
| 71 |
|
| 72 |
//go:nosplit |
| 73 |
//go:noinline |
| 74 |
func Load8(ptr *uint8) uint8 { |
| 75 |
return *ptr |
| 76 |
} |
| 77 |
|
| 78 |
//go:noescape |
| 79 |
func And8(ptr *uint8, val uint8) |
| 80 |
|
| 81 |
//go:noescape |
| 82 |
func Or8(ptr *uint8, val uint8) |
| 83 |
|
| 84 |
//go:noescape |
| 85 |
func And(ptr *uint32, val uint32) |
| 86 |
|
| 87 |
//go:noescape |
| 88 |
func Or(ptr *uint32, val uint32) |
| 89 |
|
| 90 |
//go:noescape |
| 91 |
func And32(ptr *uint32, val uint32) uint32 |
| 92 |
|
| 93 |
//go:noescape |
| 94 |
func Or32(ptr *uint32, val uint32) uint32 |
| 95 |
|
| 96 |
//go:noescape |
| 97 |
func And64(ptr *uint64, val uint64) uint64 |
| 98 |
|
| 99 |
//go:noescape |
| 100 |
func Or64(ptr *uint64, val uint64) uint64 |
| 101 |
|
| 102 |
//go:noescape |
| 103 |
func Anduintptr(ptr *uintptr, val uintptr) uintptr |
| 104 |
|
| 105 |
//go:noescape |
| 106 |
func Oruintptr(ptr *uintptr, val uintptr) uintptr |
| 107 |
|
| 108 |
// NOTE: Do not add atomicxor8 (XOR is not idempotent). |
| 109 |
|
| 110 |
//go:noescape |
| 111 |
func Cas64(ptr *uint64, old, new uint64) bool |
| 112 |
|
| 113 |
//go:noescape |
| 114 |
func CasRel(ptr *uint32, old, new uint32) bool |
| 115 |
|
| 116 |
//go:noescape |
| 117 |
func Store(ptr *uint32, val uint32) |
| 118 |
|
| 119 |
//go:noescape |
| 120 |
func Store8(ptr *uint8, val uint8) |
| 121 |
|
| 122 |
//go:noescape |
| 123 |
func Store64(ptr *uint64, val uint64) |
| 124 |
|
| 125 |
//go:noescape |
| 126 |
func StoreRel(ptr *uint32, val uint32) |
| 127 |
|
| 128 |
//go:noescape |
| 129 |
func StoreRel64(ptr *uint64, val uint64) |
| 130 |
|
| 131 |
//go:noescape |
| 132 |
func StoreReluintptr(ptr *uintptr, val uintptr) |
| 133 |
|
| 134 |
// StorepNoWB performs *ptr = val atomically and without a write |
| 135 |
// barrier. |
| 136 |
// |
| 137 |
// NO go:noescape annotation; see atomic_pointer.go. |
| 138 |
func StorepNoWB(ptr unsafe.Pointer, val unsafe.Pointer) |