1 // Copyright 2011 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.
7 // Package atomic provides low-level atomic memory primitives
8 // useful for implementing synchronization algorithms.
10 // These functions require great care to be used correctly.
11 // Except for special, low-level applications, synchronization is better
12 // done with channels or the facilities of the sync package.
13 // Share memory by communicating;
14 // don't communicate by sharing memory.
16 // The compare-and-swap operation, implemented by the CompareAndSwapT
17 // functions, is the atomic equivalent of:
25 // The add operation, implemented by the AddT functions, is the atomic
31 // The load and store operations, implemented by the LoadT and StoreT
32 // functions, are the atomic equivalents of "return *addr" and
41 // BUG(rsc): On x86-32, the 64-bit functions use instructions unavailable before the Pentium MMX.
43 // On both ARM and x86-32, it is the caller's responsibility to arrange for 64-bit
44 // alignment of 64-bit words accessed atomically. The first word in a global
45 // variable or in an allocated struct or slice can be relied upon to be
48 // CompareAndSwapInt32 executes the compare-and-swap operation for an int32 value.
49 func CompareAndSwapInt32(addr *int32, old, new int32) (swapped bool)
51 // CompareAndSwapInt64 executes the compare-and-swap operation for an int64 value.
52 func CompareAndSwapInt64(addr *int64, old, new int64) (swapped bool)
54 // CompareAndSwapUint32 executes the compare-and-swap operation for a uint32 value.
55 func CompareAndSwapUint32(addr *uint32, old, new uint32) (swapped bool)
57 // CompareAndSwapUint64 executes the compare-and-swap operation for a uint64 value.
58 func CompareAndSwapUint64(addr *uint64, old, new uint64) (swapped bool)
60 // CompareAndSwapUintptr executes the compare-and-swap operation for a uintptr value.
61 func CompareAndSwapUintptr(addr *uintptr, old, new uintptr) (swapped bool)
63 // CompareAndSwapPointer executes the compare-and-swap operation for a unsafe.Pointer value.
64 func CompareAndSwapPointer(addr *unsafe.Pointer, old, new unsafe.Pointer) (swapped bool)
66 // AddInt32 atomically adds delta to *addr and returns the new value.
67 func AddInt32(addr *int32, delta int32) (new int32)
69 // AddUint32 atomically adds delta to *addr and returns the new value.
70 func AddUint32(addr *uint32, delta uint32) (new uint32)
72 // AddInt64 atomically adds delta to *addr and returns the new value.
73 func AddInt64(addr *int64, delta int64) (new int64)
75 // AddUint64 atomically adds delta to *addr and returns the new value.
76 func AddUint64(addr *uint64, delta uint64) (new uint64)
78 // AddUintptr atomically adds delta to *addr and returns the new value.
79 func AddUintptr(addr *uintptr, delta uintptr) (new uintptr)
81 // LoadInt32 atomically loads *addr.
82 func LoadInt32(addr *int32) (val int32)
84 // LoadInt64 atomically loads *addr.
85 func LoadInt64(addr *int64) (val int64)
87 // LoadUint32 atomically loads *addr.
88 func LoadUint32(addr *uint32) (val uint32)
90 // LoadUint64 atomically loads *addr.
91 func LoadUint64(addr *uint64) (val uint64)
93 // LoadUintptr atomically loads *addr.
94 func LoadUintptr(addr *uintptr) (val uintptr)
96 // LoadPointer atomically loads *addr.
97 func LoadPointer(addr *unsafe.Pointer) (val unsafe.Pointer)
99 // StoreInt32 atomically stores val into *addr.
100 func StoreInt32(addr *int32, val int32)
102 // StoreInt64 atomically stores val into *addr.
103 func StoreInt64(addr *int64, val int64)
105 // StoreUint32 atomically stores val into *addr.
106 func StoreUint32(addr *uint32, val uint32)
108 // StoreUint64 atomically stores val into *addr.
109 func StoreUint64(addr *uint64, val uint64)
111 // StoreUintptr atomically stores val into *addr.
112 func StoreUintptr(addr *uintptr, val uintptr)
114 // StorePointer atomically stores val into *addr.
115 func StorePointer(addr *unsafe.Pointer, val unsafe.Pointer)
117 // Helper for ARM. Linker will discard on other systems
119 panic("sync/atomic: broken 64-bit atomic operations (buggy QEMU)")