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