/src/cpython-install/include/python3.16/cpython/pyatomic_gcc.h
Line | Count | Source |
1 | | // This is the implementation of Python atomic operations using GCC's built-in |
2 | | // functions that match the C+11 memory model. This implementation is preferred |
3 | | // for GCC compatible compilers, such as Clang. These functions are available |
4 | | // in GCC 4.8+ without needing to compile with --std=c11 or --std=gnu11. |
5 | | |
6 | | #ifndef Py_ATOMIC_GCC_H |
7 | | # error "this header file must not be included directly" |
8 | | #endif |
9 | | |
10 | | |
11 | | // --- _Py_atomic_add -------------------------------------------------------- |
12 | | |
13 | | static inline int |
14 | | _Py_atomic_add_int(int *obj, int value) |
15 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); } |
16 | | |
17 | | static inline int8_t |
18 | | _Py_atomic_add_int8(int8_t *obj, int8_t value) |
19 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); } |
20 | | |
21 | | static inline int16_t |
22 | | _Py_atomic_add_int16(int16_t *obj, int16_t value) |
23 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); } |
24 | | |
25 | | static inline int32_t |
26 | | _Py_atomic_add_int32(int32_t *obj, int32_t value) |
27 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); } |
28 | | |
29 | | static inline int64_t |
30 | | _Py_atomic_add_int64(int64_t *obj, int64_t value) |
31 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); } |
32 | | |
33 | | static inline intptr_t |
34 | | _Py_atomic_add_intptr(intptr_t *obj, intptr_t value) |
35 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); } |
36 | | |
37 | | static inline unsigned int |
38 | | _Py_atomic_add_uint(unsigned int *obj, unsigned int value) |
39 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); } |
40 | | |
41 | | static inline uint8_t |
42 | | _Py_atomic_add_uint8(uint8_t *obj, uint8_t value) |
43 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); } |
44 | | |
45 | | static inline uint16_t |
46 | | _Py_atomic_add_uint16(uint16_t *obj, uint16_t value) |
47 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); } |
48 | | |
49 | | static inline uint32_t |
50 | | _Py_atomic_add_uint32(uint32_t *obj, uint32_t value) |
51 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); } |
52 | | |
53 | | static inline uint64_t |
54 | | _Py_atomic_add_uint64(uint64_t *obj, uint64_t value) |
55 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); } |
56 | | |
57 | | static inline uintptr_t |
58 | | _Py_atomic_add_uintptr(uintptr_t *obj, uintptr_t value) |
59 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); } |
60 | | |
61 | | static inline Py_ssize_t |
62 | | _Py_atomic_add_ssize(Py_ssize_t *obj, Py_ssize_t value) |
63 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); } |
64 | | |
65 | | |
66 | | // --- _Py_atomic_add_relaxed ------------------------------------------------ |
67 | | |
68 | | static inline int |
69 | | _Py_atomic_add_int_relaxed(int *obj, int value) |
70 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_RELAXED); } |
71 | | |
72 | | static inline int8_t |
73 | | _Py_atomic_add_int8_relaxed(int8_t *obj, int8_t value) |
74 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_RELAXED); } |
75 | | |
76 | | static inline int16_t |
77 | | _Py_atomic_add_int16_relaxed(int16_t *obj, int16_t value) |
78 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_RELAXED); } |
79 | | |
80 | | static inline int32_t |
81 | | _Py_atomic_add_int32_relaxed(int32_t *obj, int32_t value) |
82 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_RELAXED); } |
83 | | |
84 | | static inline int64_t |
85 | | _Py_atomic_add_int64_relaxed(int64_t *obj, int64_t value) |
86 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_RELAXED); } |
87 | | |
88 | | static inline intptr_t |
89 | | _Py_atomic_add_intptr_relaxed(intptr_t *obj, intptr_t value) |
90 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_RELAXED); } |
91 | | |
92 | | static inline unsigned int |
93 | | _Py_atomic_add_uint_relaxed(unsigned int *obj, unsigned int value) |
94 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_RELAXED); } |
95 | | |
96 | | static inline uint8_t |
97 | | _Py_atomic_add_uint8_relaxed(uint8_t *obj, uint8_t value) |
98 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_RELAXED); } |
99 | | |
100 | | static inline uint16_t |
101 | | _Py_atomic_add_uint16_relaxed(uint16_t *obj, uint16_t value) |
102 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_RELAXED); } |
103 | | |
104 | | static inline uint32_t |
105 | | _Py_atomic_add_uint32_relaxed(uint32_t *obj, uint32_t value) |
106 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_RELAXED); } |
107 | | |
108 | | static inline uint64_t |
109 | | _Py_atomic_add_uint64_relaxed(uint64_t *obj, uint64_t value) |
110 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_RELAXED); } |
111 | | |
112 | | static inline uintptr_t |
113 | | _Py_atomic_add_uintptr_relaxed(uintptr_t *obj, uintptr_t value) |
114 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_RELAXED); } |
115 | | |
116 | | static inline Py_ssize_t |
117 | | _Py_atomic_add_ssize_relaxed(Py_ssize_t *obj, Py_ssize_t value) |
118 | 0 | { return __atomic_fetch_add(obj, value, __ATOMIC_RELAXED); } |
119 | | |
120 | | |
121 | | // --- _Py_atomic_compare_exchange ------------------------------------------- |
122 | | |
123 | | static inline int |
124 | | _Py_atomic_compare_exchange_int(int *obj, int *expected, int desired) |
125 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
126 | 0 | __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); } |
127 | | |
128 | | static inline int |
129 | | _Py_atomic_compare_exchange_int8(int8_t *obj, int8_t *expected, int8_t desired) |
130 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
131 | 0 | __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); } |
132 | | |
133 | | static inline int |
134 | | _Py_atomic_compare_exchange_int16(int16_t *obj, int16_t *expected, int16_t desired) |
135 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
136 | 0 | __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); } |
137 | | |
138 | | static inline int |
139 | | _Py_atomic_compare_exchange_int32(int32_t *obj, int32_t *expected, int32_t desired) |
140 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
141 | 0 | __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); } |
142 | | |
143 | | static inline int |
144 | | _Py_atomic_compare_exchange_int64(int64_t *obj, int64_t *expected, int64_t desired) |
145 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
146 | 0 | __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); } |
147 | | |
148 | | static inline int |
149 | | _Py_atomic_compare_exchange_intptr(intptr_t *obj, intptr_t *expected, intptr_t desired) |
150 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
151 | 0 | __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); } |
152 | | |
153 | | static inline int |
154 | | _Py_atomic_compare_exchange_uint(unsigned int *obj, unsigned int *expected, unsigned int desired) |
155 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
156 | 0 | __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); } |
157 | | |
158 | | static inline int |
159 | | _Py_atomic_compare_exchange_uint8(uint8_t *obj, uint8_t *expected, uint8_t desired) |
160 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
161 | 0 | __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); } |
162 | | |
163 | | static inline int |
164 | | _Py_atomic_compare_exchange_uint16(uint16_t *obj, uint16_t *expected, uint16_t desired) |
165 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
166 | 0 | __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); } |
167 | | |
168 | | static inline int |
169 | | _Py_atomic_compare_exchange_uint32(uint32_t *obj, uint32_t *expected, uint32_t desired) |
170 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
171 | 0 | __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); } |
172 | | |
173 | | static inline int |
174 | | _Py_atomic_compare_exchange_uint64(uint64_t *obj, uint64_t *expected, uint64_t desired) |
175 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
176 | 0 | __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); } |
177 | | |
178 | | static inline int |
179 | | _Py_atomic_compare_exchange_uintptr(uintptr_t *obj, uintptr_t *expected, uintptr_t desired) |
180 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
181 | 0 | __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); } |
182 | | |
183 | | static inline int |
184 | | _Py_atomic_compare_exchange_ssize(Py_ssize_t *obj, Py_ssize_t *expected, Py_ssize_t desired) |
185 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
186 | 0 | __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); } |
187 | | |
188 | | static inline int |
189 | | _Py_atomic_compare_exchange_ptr(void *obj, void *expected, void *desired) |
190 | 0 | { return __atomic_compare_exchange_n((void **)obj, (void **)expected, desired, 0, |
191 | 0 | __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); } |
192 | | |
193 | | |
194 | | // --- _Py_atomic_compare_exchange_relaxed ----------------------------------- |
195 | | |
196 | | static inline int |
197 | | _Py_atomic_compare_exchange_int_relaxed(int *obj, int *expected, int desired) |
198 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
199 | 0 | __ATOMIC_RELAXED, __ATOMIC_RELAXED); } |
200 | | |
201 | | static inline int |
202 | | _Py_atomic_compare_exchange_int8_relaxed(int8_t *obj, int8_t *expected, int8_t desired) |
203 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
204 | 0 | __ATOMIC_RELAXED, __ATOMIC_RELAXED); } |
205 | | |
206 | | static inline int |
207 | | _Py_atomic_compare_exchange_int16_relaxed(int16_t *obj, int16_t *expected, int16_t desired) |
208 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
209 | 0 | __ATOMIC_RELAXED, __ATOMIC_RELAXED); } |
210 | | |
211 | | static inline int |
212 | | _Py_atomic_compare_exchange_int32_relaxed(int32_t *obj, int32_t *expected, int32_t desired) |
213 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
214 | 0 | __ATOMIC_RELAXED, __ATOMIC_RELAXED); } |
215 | | |
216 | | static inline int |
217 | | _Py_atomic_compare_exchange_int64_relaxed(int64_t *obj, int64_t *expected, int64_t desired) |
218 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
219 | 0 | __ATOMIC_RELAXED, __ATOMIC_RELAXED); } |
220 | | |
221 | | static inline int |
222 | | _Py_atomic_compare_exchange_intptr_relaxed(intptr_t *obj, intptr_t *expected, intptr_t desired) |
223 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
224 | 0 | __ATOMIC_RELAXED, __ATOMIC_RELAXED); } |
225 | | |
226 | | static inline int |
227 | | _Py_atomic_compare_exchange_uint_relaxed(unsigned int *obj, unsigned int *expected, unsigned int desired) |
228 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
229 | 0 | __ATOMIC_RELAXED, __ATOMIC_RELAXED); } |
230 | | |
231 | | static inline int |
232 | | _Py_atomic_compare_exchange_uint8_relaxed(uint8_t *obj, uint8_t *expected, uint8_t desired) |
233 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
234 | 0 | __ATOMIC_RELAXED, __ATOMIC_RELAXED); } |
235 | | |
236 | | static inline int |
237 | | _Py_atomic_compare_exchange_uint16_relaxed(uint16_t *obj, uint16_t *expected, uint16_t desired) |
238 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
239 | 0 | __ATOMIC_RELAXED, __ATOMIC_RELAXED); } |
240 | | |
241 | | static inline int |
242 | | _Py_atomic_compare_exchange_uint32_relaxed(uint32_t *obj, uint32_t *expected, uint32_t desired) |
243 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
244 | 0 | __ATOMIC_RELAXED, __ATOMIC_RELAXED); } |
245 | | |
246 | | static inline int |
247 | | _Py_atomic_compare_exchange_uint64_relaxed(uint64_t *obj, uint64_t *expected, uint64_t desired) |
248 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
249 | 0 | __ATOMIC_RELAXED, __ATOMIC_RELAXED); } |
250 | | |
251 | | static inline int |
252 | | _Py_atomic_compare_exchange_uintptr_relaxed(uintptr_t *obj, uintptr_t *expected, uintptr_t desired) |
253 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
254 | 0 | __ATOMIC_RELAXED, __ATOMIC_RELAXED); } |
255 | | |
256 | | static inline int |
257 | | _Py_atomic_compare_exchange_ssize_relaxed(Py_ssize_t *obj, Py_ssize_t *expected, Py_ssize_t desired) |
258 | 0 | { return __atomic_compare_exchange_n(obj, expected, desired, 0, |
259 | 0 | __ATOMIC_RELAXED, __ATOMIC_RELAXED); } |
260 | | |
261 | | static inline int |
262 | | _Py_atomic_compare_exchange_ptr_relaxed(void *obj, void *expected, void *desired) |
263 | 0 | { return __atomic_compare_exchange_n((void **)obj, (void **)expected, desired, 0, |
264 | 0 | __ATOMIC_RELAXED, __ATOMIC_RELAXED); } |
265 | | |
266 | | |
267 | | // --- _Py_atomic_exchange --------------------------------------------------- |
268 | | |
269 | | static inline int |
270 | | _Py_atomic_exchange_int(int *obj, int value) |
271 | 0 | { return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); } |
272 | | |
273 | | static inline int8_t |
274 | | _Py_atomic_exchange_int8(int8_t *obj, int8_t value) |
275 | 0 | { return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); } |
276 | | |
277 | | static inline int16_t |
278 | | _Py_atomic_exchange_int16(int16_t *obj, int16_t value) |
279 | 0 | { return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); } |
280 | | |
281 | | static inline int32_t |
282 | | _Py_atomic_exchange_int32(int32_t *obj, int32_t value) |
283 | 0 | { return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); } |
284 | | |
285 | | static inline int64_t |
286 | | _Py_atomic_exchange_int64(int64_t *obj, int64_t value) |
287 | 0 | { return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); } |
288 | | |
289 | | static inline intptr_t |
290 | | _Py_atomic_exchange_intptr(intptr_t *obj, intptr_t value) |
291 | 0 | { return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); } |
292 | | |
293 | | static inline unsigned int |
294 | | _Py_atomic_exchange_uint(unsigned int *obj, unsigned int value) |
295 | 0 | { return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); } |
296 | | |
297 | | static inline uint8_t |
298 | | _Py_atomic_exchange_uint8(uint8_t *obj, uint8_t value) |
299 | 0 | { return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); } |
300 | | |
301 | | static inline uint16_t |
302 | | _Py_atomic_exchange_uint16(uint16_t *obj, uint16_t value) |
303 | 0 | { return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); } |
304 | | |
305 | | static inline uint32_t |
306 | | _Py_atomic_exchange_uint32(uint32_t *obj, uint32_t value) |
307 | 0 | { return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); } |
308 | | |
309 | | static inline uint64_t |
310 | | _Py_atomic_exchange_uint64(uint64_t *obj, uint64_t value) |
311 | 0 | { return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); } |
312 | | |
313 | | static inline uintptr_t |
314 | | _Py_atomic_exchange_uintptr(uintptr_t *obj, uintptr_t value) |
315 | 0 | { return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); } |
316 | | |
317 | | static inline Py_ssize_t |
318 | | _Py_atomic_exchange_ssize(Py_ssize_t *obj, Py_ssize_t value) |
319 | 0 | { return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); } |
320 | | |
321 | | static inline void * |
322 | | _Py_atomic_exchange_ptr(void *obj, void *value) |
323 | 0 | { return __atomic_exchange_n((void **)obj, value, __ATOMIC_SEQ_CST); } |
324 | | |
325 | | |
326 | | // --- _Py_atomic_and -------------------------------------------------------- |
327 | | |
328 | | static inline uint8_t |
329 | | _Py_atomic_and_uint8(uint8_t *obj, uint8_t value) |
330 | 0 | { return __atomic_fetch_and(obj, value, __ATOMIC_SEQ_CST); } |
331 | | |
332 | | static inline uint16_t |
333 | | _Py_atomic_and_uint16(uint16_t *obj, uint16_t value) |
334 | 0 | { return __atomic_fetch_and(obj, value, __ATOMIC_SEQ_CST); } |
335 | | |
336 | | static inline uint32_t |
337 | | _Py_atomic_and_uint32(uint32_t *obj, uint32_t value) |
338 | 0 | { return __atomic_fetch_and(obj, value, __ATOMIC_SEQ_CST); } |
339 | | |
340 | | static inline uint64_t |
341 | | _Py_atomic_and_uint64(uint64_t *obj, uint64_t value) |
342 | 0 | { return __atomic_fetch_and(obj, value, __ATOMIC_SEQ_CST); } |
343 | | |
344 | | static inline uintptr_t |
345 | | _Py_atomic_and_uintptr(uintptr_t *obj, uintptr_t value) |
346 | 0 | { return __atomic_fetch_and(obj, value, __ATOMIC_SEQ_CST); } |
347 | | |
348 | | |
349 | | // --- _Py_atomic_or --------------------------------------------------------- |
350 | | |
351 | | static inline uint8_t |
352 | | _Py_atomic_or_uint8(uint8_t *obj, uint8_t value) |
353 | 0 | { return __atomic_fetch_or(obj, value, __ATOMIC_SEQ_CST); } |
354 | | |
355 | | static inline uint16_t |
356 | | _Py_atomic_or_uint16(uint16_t *obj, uint16_t value) |
357 | 0 | { return __atomic_fetch_or(obj, value, __ATOMIC_SEQ_CST); } |
358 | | |
359 | | static inline uint32_t |
360 | | _Py_atomic_or_uint32(uint32_t *obj, uint32_t value) |
361 | 0 | { return __atomic_fetch_or(obj, value, __ATOMIC_SEQ_CST); } |
362 | | |
363 | | static inline uint64_t |
364 | | _Py_atomic_or_uint64(uint64_t *obj, uint64_t value) |
365 | 0 | { return __atomic_fetch_or(obj, value, __ATOMIC_SEQ_CST); } |
366 | | |
367 | | static inline uintptr_t |
368 | | _Py_atomic_or_uintptr(uintptr_t *obj, uintptr_t value) |
369 | 0 | { return __atomic_fetch_or(obj, value, __ATOMIC_SEQ_CST); } |
370 | | |
371 | | |
372 | | // --- _Py_atomic_load ------------------------------------------------------- |
373 | | |
374 | | static inline int |
375 | | _Py_atomic_load_int(const int *obj) |
376 | 0 | { return __atomic_load_n(obj, __ATOMIC_SEQ_CST); } |
377 | | |
378 | | static inline int8_t |
379 | | _Py_atomic_load_int8(const int8_t *obj) |
380 | 0 | { return __atomic_load_n(obj, __ATOMIC_SEQ_CST); } |
381 | | |
382 | | static inline int16_t |
383 | | _Py_atomic_load_int16(const int16_t *obj) |
384 | 0 | { return __atomic_load_n(obj, __ATOMIC_SEQ_CST); } |
385 | | |
386 | | static inline int32_t |
387 | | _Py_atomic_load_int32(const int32_t *obj) |
388 | 0 | { return __atomic_load_n(obj, __ATOMIC_SEQ_CST); } |
389 | | |
390 | | static inline int64_t |
391 | | _Py_atomic_load_int64(const int64_t *obj) |
392 | 0 | { return __atomic_load_n(obj, __ATOMIC_SEQ_CST); } |
393 | | |
394 | | static inline intptr_t |
395 | | _Py_atomic_load_intptr(const intptr_t *obj) |
396 | 0 | { return __atomic_load_n(obj, __ATOMIC_SEQ_CST); } |
397 | | |
398 | | static inline uint8_t |
399 | | _Py_atomic_load_uint8(const uint8_t *obj) |
400 | 0 | { return __atomic_load_n(obj, __ATOMIC_SEQ_CST); } |
401 | | |
402 | | static inline uint16_t |
403 | | _Py_atomic_load_uint16(const uint16_t *obj) |
404 | 0 | { return __atomic_load_n(obj, __ATOMIC_SEQ_CST); } |
405 | | |
406 | | static inline uint32_t |
407 | | _Py_atomic_load_uint32(const uint32_t *obj) |
408 | 0 | { return __atomic_load_n(obj, __ATOMIC_SEQ_CST); } |
409 | | |
410 | | static inline uint64_t |
411 | | _Py_atomic_load_uint64(const uint64_t *obj) |
412 | 0 | { return __atomic_load_n(obj, __ATOMIC_SEQ_CST); } |
413 | | |
414 | | static inline uintptr_t |
415 | | _Py_atomic_load_uintptr(const uintptr_t *obj) |
416 | 0 | { return __atomic_load_n(obj, __ATOMIC_SEQ_CST); } |
417 | | |
418 | | static inline unsigned int |
419 | | _Py_atomic_load_uint(const unsigned int *obj) |
420 | 0 | { return __atomic_load_n(obj, __ATOMIC_SEQ_CST); } |
421 | | |
422 | | static inline Py_ssize_t |
423 | | _Py_atomic_load_ssize(const Py_ssize_t *obj) |
424 | 0 | { return __atomic_load_n(obj, __ATOMIC_SEQ_CST); } |
425 | | |
426 | | static inline void * |
427 | | _Py_atomic_load_ptr(const void *obj) |
428 | 0 | { return (void *)__atomic_load_n((void * const *)obj, __ATOMIC_SEQ_CST); } |
429 | | |
430 | | |
431 | | // --- _Py_atomic_load_relaxed ----------------------------------------------- |
432 | | |
433 | | static inline int |
434 | | _Py_atomic_load_int_relaxed(const int *obj) |
435 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
436 | | |
437 | | static inline char |
438 | | _Py_atomic_load_char_relaxed(const char *obj) |
439 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
440 | | |
441 | | static inline unsigned char |
442 | | _Py_atomic_load_uchar_relaxed(const unsigned char *obj) |
443 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
444 | | |
445 | | static inline short |
446 | | _Py_atomic_load_short_relaxed(const short *obj) |
447 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
448 | | |
449 | | static inline unsigned short |
450 | | _Py_atomic_load_ushort_relaxed(const unsigned short *obj) |
451 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
452 | | |
453 | | static inline long |
454 | | _Py_atomic_load_long_relaxed(const long *obj) |
455 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
456 | | |
457 | | static inline float |
458 | | _Py_atomic_load_float_relaxed(const float *obj) |
459 | 0 | { float ret; __atomic_load(obj, &ret, __ATOMIC_RELAXED); return ret; } |
460 | | |
461 | | static inline double |
462 | | _Py_atomic_load_double_relaxed(const double *obj) |
463 | 0 | { double ret; __atomic_load(obj, &ret, __ATOMIC_RELAXED); return ret; } |
464 | | |
465 | | static inline int8_t |
466 | | _Py_atomic_load_int8_relaxed(const int8_t *obj) |
467 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
468 | | |
469 | | static inline int16_t |
470 | | _Py_atomic_load_int16_relaxed(const int16_t *obj) |
471 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
472 | | |
473 | | static inline int32_t |
474 | | _Py_atomic_load_int32_relaxed(const int32_t *obj) |
475 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
476 | | |
477 | | static inline int64_t |
478 | | _Py_atomic_load_int64_relaxed(const int64_t *obj) |
479 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
480 | | |
481 | | static inline intptr_t |
482 | | _Py_atomic_load_intptr_relaxed(const intptr_t *obj) |
483 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
484 | | |
485 | | static inline uint8_t |
486 | | _Py_atomic_load_uint8_relaxed(const uint8_t *obj) |
487 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
488 | | |
489 | | static inline uint16_t |
490 | | _Py_atomic_load_uint16_relaxed(const uint16_t *obj) |
491 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
492 | | |
493 | | static inline uint32_t |
494 | | _Py_atomic_load_uint32_relaxed(const uint32_t *obj) |
495 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
496 | | |
497 | | static inline uint64_t |
498 | | _Py_atomic_load_uint64_relaxed(const uint64_t *obj) |
499 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
500 | | |
501 | | static inline uintptr_t |
502 | | _Py_atomic_load_uintptr_relaxed(const uintptr_t *obj) |
503 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
504 | | |
505 | | static inline unsigned int |
506 | | _Py_atomic_load_uint_relaxed(const unsigned int *obj) |
507 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
508 | | |
509 | | static inline Py_ssize_t |
510 | | _Py_atomic_load_ssize_relaxed(const Py_ssize_t *obj) |
511 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
512 | | |
513 | | static inline void * |
514 | | _Py_atomic_load_ptr_relaxed(const void *obj) |
515 | 0 | { return (void *)__atomic_load_n((void * const *)obj, __ATOMIC_RELAXED); } |
516 | | |
517 | | static inline unsigned long long |
518 | | _Py_atomic_load_ullong_relaxed(const unsigned long long *obj) |
519 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
520 | | |
521 | | static inline long long |
522 | | _Py_atomic_load_llong_relaxed(const long long *obj) |
523 | 0 | { return __atomic_load_n(obj, __ATOMIC_RELAXED); } |
524 | | |
525 | | |
526 | | // --- _Py_atomic_store ------------------------------------------------------ |
527 | | |
528 | | static inline void |
529 | | _Py_atomic_store_int(int *obj, int value) |
530 | 0 | { __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); } |
531 | | |
532 | | static inline void |
533 | | _Py_atomic_store_int8(int8_t *obj, int8_t value) |
534 | 0 | { __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); } |
535 | | |
536 | | static inline void |
537 | | _Py_atomic_store_int16(int16_t *obj, int16_t value) |
538 | 0 | { __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); } |
539 | | |
540 | | static inline void |
541 | | _Py_atomic_store_int32(int32_t *obj, int32_t value) |
542 | 0 | { __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); } |
543 | | |
544 | | static inline void |
545 | | _Py_atomic_store_int64(int64_t *obj, int64_t value) |
546 | 0 | { __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); } |
547 | | |
548 | | static inline void |
549 | | _Py_atomic_store_intptr(intptr_t *obj, intptr_t value) |
550 | 0 | { __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); } |
551 | | |
552 | | static inline void |
553 | | _Py_atomic_store_uint8(uint8_t *obj, uint8_t value) |
554 | 0 | { __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); } |
555 | | |
556 | | static inline void |
557 | | _Py_atomic_store_uint16(uint16_t *obj, uint16_t value) |
558 | 0 | { __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); } |
559 | | |
560 | | static inline void |
561 | | _Py_atomic_store_uint32(uint32_t *obj, uint32_t value) |
562 | 0 | { __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); } |
563 | | |
564 | | static inline void |
565 | | _Py_atomic_store_uint64(uint64_t *obj, uint64_t value) |
566 | 0 | { __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); } |
567 | | |
568 | | static inline void |
569 | | _Py_atomic_store_uintptr(uintptr_t *obj, uintptr_t value) |
570 | 0 | { __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); } |
571 | | |
572 | | static inline void |
573 | | _Py_atomic_store_uint(unsigned int *obj, unsigned int value) |
574 | 0 | { __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); } |
575 | | |
576 | | static inline void |
577 | | _Py_atomic_store_ptr(void *obj, void *value) |
578 | 0 | { __atomic_store_n((void **)obj, value, __ATOMIC_SEQ_CST); } |
579 | | |
580 | | static inline void |
581 | | _Py_atomic_store_ssize(Py_ssize_t *obj, Py_ssize_t value) |
582 | 0 | { __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); } |
583 | | |
584 | | |
585 | | // --- _Py_atomic_store_relaxed ---------------------------------------------- |
586 | | |
587 | | static inline void |
588 | | _Py_atomic_store_int_relaxed(int *obj, int value) |
589 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
590 | | |
591 | | static inline void |
592 | | _Py_atomic_store_int8_relaxed(int8_t *obj, int8_t value) |
593 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
594 | | |
595 | | static inline void |
596 | | _Py_atomic_store_int16_relaxed(int16_t *obj, int16_t value) |
597 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
598 | | |
599 | | static inline void |
600 | | _Py_atomic_store_int32_relaxed(int32_t *obj, int32_t value) |
601 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
602 | | |
603 | | static inline void |
604 | | _Py_atomic_store_int64_relaxed(int64_t *obj, int64_t value) |
605 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
606 | | |
607 | | static inline void |
608 | | _Py_atomic_store_intptr_relaxed(intptr_t *obj, intptr_t value) |
609 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
610 | | |
611 | | static inline void |
612 | | _Py_atomic_store_uint8_relaxed(uint8_t *obj, uint8_t value) |
613 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
614 | | |
615 | | static inline void |
616 | | _Py_atomic_store_uint16_relaxed(uint16_t *obj, uint16_t value) |
617 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
618 | | |
619 | | static inline void |
620 | | _Py_atomic_store_uint32_relaxed(uint32_t *obj, uint32_t value) |
621 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
622 | | |
623 | | static inline void |
624 | | _Py_atomic_store_uint64_relaxed(uint64_t *obj, uint64_t value) |
625 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
626 | | |
627 | | static inline void |
628 | | _Py_atomic_store_uintptr_relaxed(uintptr_t *obj, uintptr_t value) |
629 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
630 | | |
631 | | static inline void |
632 | | _Py_atomic_store_uint_relaxed(unsigned int *obj, unsigned int value) |
633 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
634 | | |
635 | | static inline void |
636 | | _Py_atomic_store_ptr_relaxed(void *obj, void *value) |
637 | 0 | { __atomic_store_n((void **)obj, value, __ATOMIC_RELAXED); } |
638 | | |
639 | | static inline void |
640 | | _Py_atomic_store_ssize_relaxed(Py_ssize_t *obj, Py_ssize_t value) |
641 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
642 | | |
643 | | static inline void |
644 | | _Py_atomic_store_ullong_relaxed(unsigned long long *obj, |
645 | | unsigned long long value) |
646 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
647 | | |
648 | | static inline void |
649 | | _Py_atomic_store_char_relaxed(char *obj, char value) |
650 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
651 | | |
652 | | static inline void |
653 | | _Py_atomic_store_uchar_relaxed(unsigned char *obj, unsigned char value) |
654 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
655 | | |
656 | | static inline void |
657 | | _Py_atomic_store_short_relaxed(short *obj, short value) |
658 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
659 | | |
660 | | static inline void |
661 | | _Py_atomic_store_ushort_relaxed(unsigned short *obj, unsigned short value) |
662 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
663 | | |
664 | | static inline void |
665 | | _Py_atomic_store_long_relaxed(long *obj, long value) |
666 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
667 | | |
668 | | static inline void |
669 | | _Py_atomic_store_float_relaxed(float *obj, float value) |
670 | 0 | { __atomic_store(obj, &value, __ATOMIC_RELAXED); } |
671 | | |
672 | | static inline void |
673 | | _Py_atomic_store_double_relaxed(double *obj, double value) |
674 | 0 | { __atomic_store(obj, &value, __ATOMIC_RELAXED); } |
675 | | |
676 | | static inline void |
677 | | _Py_atomic_store_llong_relaxed(long long *obj, long long value) |
678 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELAXED); } |
679 | | |
680 | | |
681 | | // --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------ |
682 | | |
683 | | static inline void * |
684 | | _Py_atomic_load_ptr_acquire(const void *obj) |
685 | 0 | { return (void *)__atomic_load_n((void * const *)obj, __ATOMIC_ACQUIRE); } |
686 | | |
687 | | static inline uintptr_t |
688 | | _Py_atomic_load_uintptr_acquire(const uintptr_t *obj) |
689 | 0 | { return (uintptr_t)__atomic_load_n(obj, __ATOMIC_ACQUIRE); } |
690 | | |
691 | | static inline void |
692 | | _Py_atomic_store_ptr_release(void *obj, void *value) |
693 | 0 | { __atomic_store_n((void **)obj, value, __ATOMIC_RELEASE); } |
694 | | |
695 | | static inline void |
696 | | _Py_atomic_store_uintptr_release(uintptr_t *obj, uintptr_t value) |
697 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELEASE); } |
698 | | |
699 | | static inline void |
700 | | _Py_atomic_store_int_release(int *obj, int value) |
701 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELEASE); } |
702 | | |
703 | | static inline void |
704 | | _Py_atomic_store_int8_release(int8_t *obj, int8_t value) |
705 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELEASE); } |
706 | | |
707 | | static inline void |
708 | | _Py_atomic_store_uint8_release(uint8_t *obj, uint8_t value) |
709 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELEASE); } |
710 | | |
711 | | static inline void |
712 | | _Py_atomic_store_ssize_release(Py_ssize_t *obj, Py_ssize_t value) |
713 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELEASE); } |
714 | | |
715 | | static inline void |
716 | | _Py_atomic_store_uint_release(unsigned int *obj, unsigned int value) |
717 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELEASE); } |
718 | | |
719 | | static inline int |
720 | | _Py_atomic_load_int_acquire(const int *obj) |
721 | 0 | { return __atomic_load_n(obj, __ATOMIC_ACQUIRE); } |
722 | | |
723 | | static inline void |
724 | | _Py_atomic_store_uint32_release(uint32_t *obj, uint32_t value) |
725 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELEASE); } |
726 | | |
727 | | static inline void |
728 | | _Py_atomic_store_uint64_release(uint64_t *obj, uint64_t value) |
729 | 0 | { __atomic_store_n(obj, value, __ATOMIC_RELEASE); } |
730 | | |
731 | | static inline uint64_t |
732 | | _Py_atomic_load_uint64_acquire(const uint64_t *obj) |
733 | 0 | { return __atomic_load_n(obj, __ATOMIC_ACQUIRE); } |
734 | | |
735 | | static inline uint32_t |
736 | | _Py_atomic_load_uint32_acquire(const uint32_t *obj) |
737 | 0 | { return __atomic_load_n(obj, __ATOMIC_ACQUIRE); } |
738 | | |
739 | | static inline Py_ssize_t |
740 | | _Py_atomic_load_ssize_acquire(const Py_ssize_t *obj) |
741 | 0 | { return __atomic_load_n(obj, __ATOMIC_ACQUIRE); } |
742 | | |
743 | | // --- _Py_atomic_fence ------------------------------------------------------ |
744 | | |
745 | | static inline void |
746 | | _Py_atomic_fence_seq_cst(void) |
747 | 0 | { __atomic_thread_fence(__ATOMIC_SEQ_CST); } |
748 | | |
749 | | static inline void |
750 | | _Py_atomic_fence_acquire(void) |
751 | 0 | { __atomic_thread_fence(__ATOMIC_ACQUIRE); } |
752 | | |
753 | | static inline void |
754 | | _Py_atomic_fence_release(void) |
755 | 0 | { __atomic_thread_fence(__ATOMIC_RELEASE); } |