1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 package atomic
40
41 import "unsafe"
42
43
44
45 func Load(ptr *uint32) uint32 {
46 return *ptr
47 }
48
49
50
51 func Loadp(ptr unsafe.Pointer) unsafe.Pointer {
52 return *(*unsafe.Pointer)(ptr)
53 }
54
55
56
57 func LoadAcq(ptr *uint32) uint32 {
58 return *ptr
59 }
60
61
62
63 func LoadAcq64(ptr *uint64) uint64 {
64 return *ptr
65 }
66
67
68
69 func LoadAcquintptr(ptr *uintptr) uintptr {
70 return *ptr
71 }
72
73
74
75 func Load8(ptr *uint8) uint8 {
76 return *ptr
77 }
78
79
80
81 func Load64(ptr *uint64) uint64 {
82 return *ptr
83 }
84
85
86
87 func Xadd(ptr *uint32, delta int32) uint32 {
88 new := *ptr + uint32(delta)
89 *ptr = new
90 return new
91 }
92
93
94
95 func Xadd64(ptr *uint64, delta int64) uint64 {
96 new := *ptr + uint64(delta)
97 *ptr = new
98 return new
99 }
100
101
102
103 func Xadduintptr(ptr *uintptr, delta uintptr) uintptr {
104 new := *ptr + delta
105 *ptr = new
106 return new
107 }
108
109
110
111 func Xchg(ptr *uint32, new uint32) uint32 {
112 old := *ptr
113 *ptr = new
114 return old
115 }
116
117
118
119 func Xchg64(ptr *uint64, new uint64) uint64 {
120 old := *ptr
121 *ptr = new
122 return old
123 }
124
125
126
127 func Xchgint32(ptr *int32, new int32) int32 {
128 old := *ptr
129 *ptr = new
130 return old
131 }
132
133
134
135 func Xchgint64(ptr *int64, new int64) int64 {
136 old := *ptr
137 *ptr = new
138 return old
139 }
140
141
142
143 func Xchguintptr(ptr *uintptr, new uintptr) uintptr {
144 old := *ptr
145 *ptr = new
146 return old
147 }
148
149
150
151 func And8(ptr *uint8, val uint8) {
152 *ptr = *ptr & val
153 }
154
155
156
157 func Or8(ptr *uint8, val uint8) {
158 *ptr = *ptr | val
159 }
160
161
162
163
164
165 func And(ptr *uint32, val uint32) {
166 *ptr = *ptr & val
167 }
168
169
170
171 func Or(ptr *uint32, val uint32) {
172 *ptr = *ptr | val
173 }
174
175
176
177 func Cas64(ptr *uint64, old, new uint64) bool {
178 if *ptr == old {
179 *ptr = new
180 return true
181 }
182 return false
183 }
184
185
186
187 func Store(ptr *uint32, val uint32) {
188 *ptr = val
189 }
190
191
192
193 func StoreRel(ptr *uint32, val uint32) {
194 *ptr = val
195 }
196
197
198
199 func StoreRel64(ptr *uint64, val uint64) {
200 *ptr = val
201 }
202
203
204
205 func StoreReluintptr(ptr *uintptr, val uintptr) {
206 *ptr = val
207 }
208
209
210
211 func Store8(ptr *uint8, val uint8) {
212 *ptr = val
213 }
214
215
216
217 func Store64(ptr *uint64, val uint64) {
218 *ptr = val
219 }
220
221
222
223
224
225 func StorepNoWB(ptr unsafe.Pointer, val unsafe.Pointer)
226
227
228
229 func Casint32(ptr *int32, old, new int32) bool {
230 if *ptr == old {
231 *ptr = new
232 return true
233 }
234 return false
235 }
236
237
238
239 func Casint64(ptr *int64, old, new int64) bool {
240 if *ptr == old {
241 *ptr = new
242 return true
243 }
244 return false
245 }
246
247
248
249 func Cas(ptr *uint32, old, new uint32) bool {
250 if *ptr == old {
251 *ptr = new
252 return true
253 }
254 return false
255 }
256
257
258
259 func Casp1(ptr *unsafe.Pointer, old, new unsafe.Pointer) bool {
260 if *ptr == old {
261 *ptr = new
262 return true
263 }
264 return false
265 }
266
267
268
269 func Casuintptr(ptr *uintptr, old, new uintptr) bool {
270 if *ptr == old {
271 *ptr = new
272 return true
273 }
274 return false
275 }
276
277
278
279 func CasRel(ptr *uint32, old, new uint32) bool {
280 if *ptr == old {
281 *ptr = new
282 return true
283 }
284 return false
285 }
286
287
288
289 func Storeint32(ptr *int32, new int32) {
290 *ptr = new
291 }
292
293
294
295 func Storeint64(ptr *int64, new int64) {
296 *ptr = new
297 }
298
299
300
301 func Storeuintptr(ptr *uintptr, new uintptr) {
302 *ptr = new
303 }
304
305
306
307 func Loaduintptr(ptr *uintptr) uintptr {
308 return *ptr
309 }
310
311
312
313 func Loaduint(ptr *uint) uint {
314 return *ptr
315 }
316
317
318
319 func Loadint32(ptr *int32) int32 {
320 return *ptr
321 }
322
323
324
325 func Loadint64(ptr *int64) int64 {
326 return *ptr
327 }
328
329
330
331 func Xaddint32(ptr *int32, delta int32) int32 {
332 new := *ptr + delta
333 *ptr = new
334 return new
335 }
336
337
338
339 func Xaddint64(ptr *int64, delta int64) int64 {
340 new := *ptr + delta
341 *ptr = new
342 return new
343 }
344
View as plain text