Skip to content

Commit 0bd4710

Browse files
committed
sync/atomic: hint users of old API to use new type-based API instead
Fixes #56495 Change-Id: Ib2f39273da68e3056688306aa0d5e274b5507bf4 Reviewed-on: https://go-review.googlesource.com/c/go/+/449237 Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Sean Liao <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent b74aaa1 commit 0bd4710

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

src/sync/atomic/doc.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,98 +56,137 @@ import (
5656
//
5757
// On ARM, 386, and 32-bit MIPS, it is the caller's responsibility to arrange
5858
// for 64-bit alignment of 64-bit words accessed atomically via the primitive
59-
// atomic functions (types Int64 and Uint64 are automatically aligned).
59+
// atomic functions (types [Int64] and [Uint64] are automatically aligned).
6060
// The first word in an allocated struct, array, or slice; in a global
6161
// variable; or in a local variable (because the subject of all atomic operations
6262
// will escape to the heap) can be relied upon to be 64-bit aligned.
6363

6464
// SwapInt32 atomically stores new into *addr and returns the previous *addr value.
65+
// Consider using the more ergonomic and less error-prone [Int32.Swap] instead.
6566
func SwapInt32(addr *int32, new int32) (old int32)
6667

6768
// SwapInt64 atomically stores new into *addr and returns the previous *addr value.
69+
// Consider using the more ergonomic and less error-prone [Int64.Swap] instead
70+
// (particularly if you target 32-bit platforms; see the bugs section).
6871
func SwapInt64(addr *int64, new int64) (old int64)
6972

7073
// SwapUint32 atomically stores new into *addr and returns the previous *addr value.
74+
// Consider using the more ergonomic and less error-prone [Uint32.Swap] instead.
7175
func SwapUint32(addr *uint32, new uint32) (old uint32)
7276

7377
// SwapUint64 atomically stores new into *addr and returns the previous *addr value.
78+
// Consider using the more ergonomic and less error-prone [Uint64.Swap] instead
79+
// (particularly if you target 32-bit platforms; see the bugs section).
7480
func SwapUint64(addr *uint64, new uint64) (old uint64)
7581

7682
// SwapUintptr atomically stores new into *addr and returns the previous *addr value.
83+
// Consider using the more ergonomic and less error-prone [Uintptr.Swap] instead.
7784
func SwapUintptr(addr *uintptr, new uintptr) (old uintptr)
7885

7986
// SwapPointer atomically stores new into *addr and returns the previous *addr value.
87+
// Consider using the more ergonomic and less error-prone [Pointer.Swap] instead.
8088
func SwapPointer(addr *unsafe.Pointer, new unsafe.Pointer) (old unsafe.Pointer)
8189

8290
// CompareAndSwapInt32 executes the compare-and-swap operation for an int32 value.
91+
// Consider using the more ergonomic and less error-prone [Int32.CompareAndSwap] instead.
8392
func CompareAndSwapInt32(addr *int32, old, new int32) (swapped bool)
8493

8594
// CompareAndSwapInt64 executes the compare-and-swap operation for an int64 value.
95+
// Consider using the more ergonomic and less error-prone [Int64.CompareAndSwap] instead
96+
// (particularly if you target 32-bit platforms; see the bugs section).
8697
func CompareAndSwapInt64(addr *int64, old, new int64) (swapped bool)
8798

8899
// CompareAndSwapUint32 executes the compare-and-swap operation for a uint32 value.
100+
// Consider using the more ergonomic and less error-prone [Uint32.CompareAndSwap] instead.
89101
func CompareAndSwapUint32(addr *uint32, old, new uint32) (swapped bool)
90102

91103
// CompareAndSwapUint64 executes the compare-and-swap operation for a uint64 value.
104+
// Consider using the more ergonomic and less error-prone [Uint64.CompareAndSwap] instead
105+
// (particularly if you target 32-bit platforms; see the bugs section).
92106
func CompareAndSwapUint64(addr *uint64, old, new uint64) (swapped bool)
93107

94108
// CompareAndSwapUintptr executes the compare-and-swap operation for a uintptr value.
109+
// Consider using the more ergonomic and less error-prone [Uintptr.CompareAndSwap] instead.
95110
func CompareAndSwapUintptr(addr *uintptr, old, new uintptr) (swapped bool)
96111

97112
// CompareAndSwapPointer executes the compare-and-swap operation for a unsafe.Pointer value.
113+
// Consider using the more ergonomic and less error-prone [Pointer.CompareAndSwap] instead.
98114
func CompareAndSwapPointer(addr *unsafe.Pointer, old, new unsafe.Pointer) (swapped bool)
99115

100116
// AddInt32 atomically adds delta to *addr and returns the new value.
117+
// Consider using the more ergonomic and less error-prone [Int32.Add] instead.
101118
func AddInt32(addr *int32, delta int32) (new int32)
102119

103120
// AddUint32 atomically adds delta to *addr and returns the new value.
104121
// To subtract a signed positive constant value c from x, do AddUint32(&x, ^uint32(c-1)).
105122
// In particular, to decrement x, do AddUint32(&x, ^uint32(0)).
123+
// Consider using the more ergonomic and less error-prone [Uint32.Add] instead.
106124
func AddUint32(addr *uint32, delta uint32) (new uint32)
107125

108126
// AddInt64 atomically adds delta to *addr and returns the new value.
127+
// Consider using the more ergonomic and less error-prone [Int64.Add] instead
128+
// (particularly if you target 32-bit platforms; see the bugs section).
109129
func AddInt64(addr *int64, delta int64) (new int64)
110130

111131
// AddUint64 atomically adds delta to *addr and returns the new value.
112132
// To subtract a signed positive constant value c from x, do AddUint64(&x, ^uint64(c-1)).
113133
// In particular, to decrement x, do AddUint64(&x, ^uint64(0)).
134+
// Consider using the more ergonomic and less error-prone [Uint64.Add] instead
135+
// (particularly if you target 32-bit platforms; see the bugs section).
114136
func AddUint64(addr *uint64, delta uint64) (new uint64)
115137

116138
// AddUintptr atomically adds delta to *addr and returns the new value.
139+
// Consider using the more ergonomic and less error-prone [Uintptr.Add] instead.
117140
func AddUintptr(addr *uintptr, delta uintptr) (new uintptr)
118141

119142
// LoadInt32 atomically loads *addr.
143+
// Consider using the more ergonomic and less error-prone [Int32.Load] instead.
120144
func LoadInt32(addr *int32) (val int32)
121145

122146
// LoadInt64 atomically loads *addr.
147+
// Consider using the more ergonomic and less error-prone [Int64.Load] instead
148+
// (particularly if you target 32-bit platforms; see the bugs section).
123149
func LoadInt64(addr *int64) (val int64)
124150

125151
// LoadUint32 atomically loads *addr.
152+
// Consider using the more ergonomic and less error-prone [Uint32.Load] instead.
126153
func LoadUint32(addr *uint32) (val uint32)
127154

128155
// LoadUint64 atomically loads *addr.
156+
// Consider using the more ergonomic and less error-prone [Uint64.Load] instead
157+
// (particularly if you target 32-bit platforms; see the bugs section).
129158
func LoadUint64(addr *uint64) (val uint64)
130159

131160
// LoadUintptr atomically loads *addr.
161+
// Consider using the more ergonomic and less error-prone [Uintptr.Load] instead.
132162
func LoadUintptr(addr *uintptr) (val uintptr)
133163

134164
// LoadPointer atomically loads *addr.
165+
// Consider using the more ergonomic and less error-prone [Pointer.Load] instead.
135166
func LoadPointer(addr *unsafe.Pointer) (val unsafe.Pointer)
136167

137168
// StoreInt32 atomically stores val into *addr.
169+
// Consider using the more ergonomic and less error-prone [Int32.Store] instead.
138170
func StoreInt32(addr *int32, val int32)
139171

140172
// StoreInt64 atomically stores val into *addr.
173+
// Consider using the more ergonomic and less error-prone [Int64.Store] instead
174+
// (particularly if you target 32-bit platforms; see the bugs section).
141175
func StoreInt64(addr *int64, val int64)
142176

143177
// StoreUint32 atomically stores val into *addr.
178+
// Consider using the more ergonomic and less error-prone [Uint32.Store] instead.
144179
func StoreUint32(addr *uint32, val uint32)
145180

146181
// StoreUint64 atomically stores val into *addr.
182+
// Consider using the more ergonomic and less error-prone [Uint64.Store] instead
183+
// (particularly if you target 32-bit platforms; see the bugs section).
147184
func StoreUint64(addr *uint64, val uint64)
148185

149186
// StoreUintptr atomically stores val into *addr.
187+
// Consider using the more ergonomic and less error-prone [Uintptr.Store] instead.
150188
func StoreUintptr(addr *uintptr, val uintptr)
151189

152190
// StorePointer atomically stores val into *addr.
191+
// Consider using the more ergonomic and less error-prone [Pointer.Store] instead.
153192
func StorePointer(addr *unsafe.Pointer, val unsafe.Pointer)

0 commit comments

Comments
 (0)