v / thirdparty / stdatomic / nix / atomic_cpp.h
551 lines · 546 sloc · 20.45 KB · 06c6554480af709f8c6f6e5d562c6aa21aa9fe9f
Raw
1// Source: https://android.googlesource.com/platform/bionic/+/lollipop-release/libc/include/stdatomic.h
2/*-
3 * Copyright (c) 2011 Ed Schouten <[email protected]>
4 * David Chisnall <[email protected]>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * $FreeBSD$
29 */
30#ifndef _STDATOMIC_H_
31#define _STDATOMIC_H_
32#include <sys/cdefs.h>
33#if defined(__cplusplus)
34#ifdef __clang__
35#if __has_feature(cxx_atomic)
36#define _STDATOMIC_HAVE_ATOMIC
37#endif
38#else /* gcc */
39#if __GNUC_PREREQ(4, 7)
40#define _STDATOMIC_HAVE_ATOMIC
41#endif
42#endif
43#endif
44#ifdef _STDATOMIC_HAVE_ATOMIC
45
46#include "cpp/atomic.h"
47
48#undef _Atomic
49/* Also defined by <atomic> for gcc. But not used in macros. */
50/* Also a clang intrinsic. */
51/* Should not be used by client code before this file is */
52/* included. The definitions in <atomic> themselves see */
53/* the old definition, as they should. */
54/* Client code sees the following definition. */
55#define _Atomic(t) std::atomic<t>
56using std::atomic_bool;
57using std::atomic_char;
58using std::atomic_char16_t;
59using std::atomic_char32_t;
60using std::atomic_compare_exchange_strong;
61using std::atomic_compare_exchange_strong_explicit;
62using std::atomic_compare_exchange_weak;
63using std::atomic_compare_exchange_weak_explicit;
64using std::atomic_exchange;
65using std::atomic_exchange_explicit;
66using std::atomic_fetch_add;
67using std::atomic_fetch_add_explicit;
68using std::atomic_fetch_and;
69using std::atomic_fetch_and_explicit;
70using std::atomic_fetch_or;
71using std::atomic_fetch_or_explicit;
72using std::atomic_fetch_sub;
73using std::atomic_fetch_sub_explicit;
74using std::atomic_fetch_xor;
75using std::atomic_fetch_xor_explicit;
76using std::atomic_init;
77using std::atomic_int;
78using std::atomic_int_fast16_t;
79using std::atomic_int_fast32_t;
80using std::atomic_int_fast64_t;
81using std::atomic_int_fast8_t;
82using std::atomic_int_least16_t;
83using std::atomic_int_least32_t;
84using std::atomic_int_least64_t;
85using std::atomic_int_least8_t;
86using std::atomic_intmax_t;
87using std::atomic_intptr_t;
88using std::atomic_is_lock_free;
89using std::atomic_llong;
90using std::atomic_load;
91using std::atomic_load_explicit;
92using std::atomic_long;
93using std::atomic_ptrdiff_t;
94using std::atomic_schar;
95using std::atomic_short;
96using std::atomic_signal_fence;
97using std::atomic_size_t;
98using std::atomic_store;
99using std::atomic_store_explicit;
100using std::atomic_thread_fence;
101using std::atomic_uchar;
102using std::atomic_uint;
103using std::atomic_uint_fast16_t;
104using std::atomic_uint_fast32_t;
105using std::atomic_uint_fast64_t;
106using std::atomic_uint_fast8_t;
107using std::atomic_uint_least16_t;
108using std::atomic_uint_least32_t;
109using std::atomic_uint_least64_t;
110using std::atomic_uint_least8_t;
111using std::atomic_uintmax_t;
112using std::atomic_uintptr_t;
113using std::atomic_ullong;
114using std::atomic_ulong;
115using std::atomic_ushort;
116using std::atomic_wchar_t;
117using std::memory_order;
118using std::memory_order_acq_rel;
119using std::memory_order_consume;
120using std::memory_order_relaxed;
121using std::memory_order_release;
122using std::memory_order_seq_cst;
123
124#define memory_order_relaxed std::memory_order_relaxed
125#define memory_order_consume std::memory_order_consume
126#define memory_order_acquire std::memory_order_acquire
127#define memory_order_release std::memory_order_release
128#define memory_order_acq_rel std::memory_order_acq_rel
129#define memory_order_seq_cst std::memory_order_seq_cst
130
131#else /* <atomic> unavailable, possibly because this is C, not C++ */
132#include <sys/types.h>
133#include <stdbool.h>
134/*
135 * C: Do it ourselves.
136 * Note that the runtime representation defined here should be compatible
137 * with the C++ one, i.e. an _Atomic(T) needs to contain the same
138 * bits as a T.
139 */
140#include <stddef.h> /* For ptrdiff_t. */
141#include <stdint.h> /* TODO: Should pollute namespace less. */
142#if __STDC_VERSION__ >= 201112L
143#include <uchar.h> /* For char16_t and char32_t. */
144#endif
145#ifdef __clang__
146#if __has_extension(c_atomic) || __has_extension(cxx_atomic)
147#define __CLANG_ATOMICS
148#else
149#error "stdatomic.h does not support your compiler"
150#endif
151#if __has_builtin(__sync_swap)
152#define __HAS_BUILTIN_SYNC_SWAP
153#endif
154#else
155#if __GNUC_PREREQ(4, 7)
156#define __GNUC_ATOMICS
157#else
158#define __SYNC_ATOMICS
159#ifdef __cplusplus
160#define __ATOMICS_AVOID_DOT_INIT
161#endif
162#endif
163#endif
164/*
165 * 7.17.1 Atomic lock-free macros.
166 */
167#ifdef __GCC_ATOMIC_BOOL_LOCK_FREE
168#define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE
169#elif defined(__SYNC_ATOMICS)
170#define ATOMIC_BOOL_LOCK_FREE 2 /* For all modern platforms */
171#endif
172#ifdef __GCC_ATOMIC_CHAR_LOCK_FREE
173#define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE
174#elif defined(__SYNC_ATOMICS)
175#define ATOMIC_CHAR_LOCK_FREE 2
176#endif
177#ifdef __GCC_ATOMIC_CHAR16_T_LOCK_FREE
178#define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
179#elif defined(__SYNC_ATOMICS)
180#define ATOMIC_CHAR16_T_LOCK_FREE 2
181#endif
182#ifdef __GCC_ATOMIC_CHAR32_T_LOCK_FREE
183#define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
184#elif defined(__SYNC_ATOMICS)
185#define ATOMIC_CHAR32_T_LOCK_FREE 2
186#endif
187#ifdef __GCC_ATOMIC_WCHAR_T_LOCK_FREE
188#define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE
189#elif defined(__SYNC_ATOMICS)
190#define ATOMIC_WCHAR_T_LOCK_FREE 2
191#endif
192#ifdef __GCC_ATOMIC_SHORT_LOCK_FREE
193#define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
194#elif defined(__SYNC_ATOMICS)
195#define ATOMIC_SHORT_LOCK_FREE 2
196#endif
197#ifdef __GCC_ATOMIC_INT_LOCK_FREE
198#define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
199#elif defined(__SYNC_ATOMICS)
200#define ATOMIC_INT_LOCK_FREE 2
201#endif
202#ifdef __GCC_ATOMIC_LONG_LOCK_FREE
203#define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE
204#elif defined(__SYNC_ATOMICS)
205#define ATOMIC_LONG_LOCK_FREE 2
206#endif
207#ifdef __GCC_ATOMIC_LLONG_LOCK_FREE
208#define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
209#elif defined(__SYNC_ATOMICS)
210#define ATOMIC_LLONG_LOCK_FREE 1 /* maybe */
211#endif
212#ifdef __GCC_ATOMIC_POINTER_LOCK_FREE
213#define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE
214#elif defined(__SYNC_ATOMICS)
215#define ATOMIC_POINTER_LOCK_FREE 2
216#endif
217/*
218 * 7.17.2 Initialization.
219 */
220#if defined(__CLANG_ATOMICS)
221#define ATOMIC_VAR_INIT(value) (value)
222#define atomic_init(obj, value) __c11_atomic_init(obj, value)
223#else
224#ifdef __ATOMICS_AVOID_DOT_INIT
225#define ATOMIC_VAR_INIT(value) \
226 { \
227 value \
228 }
229#else
230#define ATOMIC_VAR_INIT(value) \
231 { \
232 .__val = (value) \
233 }
234#endif
235#define atomic_init(obj, value) ((void)((obj)->__val = (value)))
236#endif
237/*
238 * Clang and recent GCC both provide predefined macros for the memory
239 * orderings. If we are using a compiler that doesn't define them, use the
240 * clang values - these will be ignored in the fallback path.
241 */
242#ifndef __ATOMIC_RELAXED
243#define __ATOMIC_RELAXED 0
244#endif
245#ifndef __ATOMIC_CONSUME
246#define __ATOMIC_CONSUME 1
247#endif
248#ifndef __ATOMIC_ACQUIRE
249#define __ATOMIC_ACQUIRE 2
250#endif
251#ifndef __ATOMIC_RELEASE
252#define __ATOMIC_RELEASE 3
253#endif
254#ifndef __ATOMIC_ACQ_REL
255#define __ATOMIC_ACQ_REL 4
256#endif
257#ifndef __ATOMIC_SEQ_CST
258#define __ATOMIC_SEQ_CST 5
259#endif
260/*
261 * 7.17.3 Order and consistency.
262 *
263 * The memory_order_* constants that denote the barrier behaviour of the
264 * atomic operations.
265 * The enum values must be identical to those used by the
266 * C++ <atomic> header.
267 */
268typedef enum
269{
270 memory_order_relaxed = __ATOMIC_RELAXED,
271 memory_order_consume = __ATOMIC_CONSUME,
272 memory_order_acquire = __ATOMIC_ACQUIRE,
273 memory_order_release = __ATOMIC_RELEASE,
274 memory_order_acq_rel = __ATOMIC_ACQ_REL,
275 memory_order_seq_cst = __ATOMIC_SEQ_CST
276} memory_order;
277
278/*
279 * 7.17.4 Fences.
280 */
281static __inline void
282atomic_thread_fence(memory_order __order __attribute__((unused)))
283{
284#ifdef __CLANG_ATOMICS
285 __c11_atomic_thread_fence(__order);
286#elif defined(__GNUC_ATOMICS)
287 __atomic_thread_fence(__order);
288#else
289 __sync_synchronize();
290#endif
291}
292static __inline void
293atomic_signal_fence(memory_order __order __attribute__((unused)))
294{
295#ifdef __CLANG_ATOMICS
296 __c11_atomic_signal_fence(__order);
297#elif defined(__GNUC_ATOMICS)
298 __atomic_signal_fence(__order);
299#else
300 __asm volatile("" ::
301 : "memory");
302#endif
303}
304/*
305 * 7.17.5 Lock-free property.
306 */
307#if defined(_KERNEL)
308/* Atomics in kernelspace are always lock-free. */
309#define atomic_is_lock_free(obj) \
310 ((void)(obj), (_Bool)1)
311#elif defined(__CLANG_ATOMICS)
312#define atomic_is_lock_free(obj) \
313 __c11_atomic_is_lock_free(sizeof(*(obj)))
314#elif defined(__GNUC_ATOMICS)
315#define atomic_is_lock_free(obj) \
316 __atomic_is_lock_free(sizeof((obj)->__val), &(obj)->__val)
317#else
318#define atomic_is_lock_free(obj) \
319 ((void)(obj), sizeof((obj)->__val) <= sizeof(void *))
320#endif
321/*
322 * 7.17.6 Atomic integer types.
323 */
324#ifndef __CLANG_ATOMICS
325/*
326 * No native support for _Atomic(). Place object in structure to prevent
327 * most forms of direct non-atomic access.
328 */
329#define _Atomic(T) \
330 struct \
331 { \
332 T volatile __val; \
333 }
334#endif
335typedef _Atomic(bool) atomic_bool;
336typedef _Atomic(char) atomic_char;
337typedef _Atomic(signed char) atomic_schar;
338typedef _Atomic(unsigned char) atomic_uchar;
339typedef _Atomic(short) atomic_short;
340typedef _Atomic(unsigned short) atomic_ushort;
341typedef _Atomic(int) atomic_int;
342typedef _Atomic(unsigned int) atomic_uint;
343typedef _Atomic(long) atomic_long;
344typedef _Atomic(unsigned long) atomic_ulong;
345typedef _Atomic(long long) atomic_llong;
346typedef _Atomic(unsigned long long) atomic_ullong;
347#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L
348typedef _Atomic(char16_t) atomic_char16_t;
349typedef _Atomic(char32_t) atomic_char32_t;
350#endif
351typedef _Atomic(wchar_t) atomic_wchar_t;
352typedef _Atomic(int_least8_t) atomic_int_least8_t;
353typedef _Atomic(uint_least8_t) atomic_uint_least8_t;
354typedef _Atomic(int_least16_t) atomic_int_least16_t;
355typedef _Atomic(uint_least16_t) atomic_uint_least16_t;
356typedef _Atomic(int_least32_t) atomic_int_least32_t;
357typedef _Atomic(uint_least32_t) atomic_uint_least32_t;
358typedef _Atomic(int_least64_t) atomic_int_least64_t;
359typedef _Atomic(uint_least64_t) atomic_uint_least64_t;
360typedef _Atomic(int_fast8_t) atomic_int_fast8_t;
361typedef _Atomic(uint_fast8_t) atomic_uint_fast8_t;
362typedef _Atomic(int_fast16_t) atomic_int_fast16_t;
363typedef _Atomic(uint_fast16_t) atomic_uint_fast16_t;
364typedef _Atomic(int_fast32_t) atomic_int_fast32_t;
365typedef _Atomic(uint_fast32_t) atomic_uint_fast32_t;
366typedef _Atomic(int_fast64_t) atomic_int_fast64_t;
367typedef _Atomic(uint_fast64_t) atomic_uint_fast64_t;
368typedef _Atomic(intptr_t) atomic_intptr_t;
369typedef _Atomic(uintptr_t) atomic_uintptr_t;
370typedef _Atomic(size_t) atomic_size_t;
371typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t;
372typedef _Atomic(intmax_t) atomic_intmax_t;
373typedef _Atomic(uintmax_t) atomic_uintmax_t;
374/*
375 * 7.17.7 Operations on atomic types.
376 */
377/*
378 * Compiler-specific operations.
379 */
380#if defined(__CLANG_ATOMICS)
381#define atomic_compare_exchange_strong_explicit(object, expected, \
382 desired, success, failure) \
383 __c11_atomic_compare_exchange_strong(object, expected, desired, \
384 success, failure)
385#define atomic_compare_exchange_weak_explicit(object, expected, \
386 desired, success, failure) \
387 __c11_atomic_compare_exchange_weak(object, expected, desired, \
388 success, failure)
389#define atomic_exchange_explicit(object, desired, order) \
390 __c11_atomic_exchange(object, desired, order)
391#define atomic_fetch_add_explicit(object, operand, order) \
392 __c11_atomic_fetch_add(object, operand, order)
393#define atomic_fetch_and_explicit(object, operand, order) \
394 __c11_atomic_fetch_and(object, operand, order)
395#define atomic_fetch_or_explicit(object, operand, order) \
396 __c11_atomic_fetch_or(object, operand, order)
397#define atomic_fetch_sub_explicit(object, operand, order) \
398 __c11_atomic_fetch_sub(object, operand, order)
399#define atomic_fetch_xor_explicit(object, operand, order) \
400 __c11_atomic_fetch_xor(object, operand, order)
401#define atomic_load_explicit(object, order) \
402 __c11_atomic_load(object, order)
403#define atomic_store_explicit(object, desired, order) \
404 __c11_atomic_store(object, desired, order)
405#elif defined(__GNUC_ATOMICS)
406#define atomic_compare_exchange_strong_explicit(object, expected, \
407 desired, success, failure) \
408 __atomic_compare_exchange_n(&(object)->__val, expected, \
409 desired, 0, success, failure)
410#define atomic_compare_exchange_weak_explicit(object, expected, \
411 desired, success, failure) \
412 __atomic_compare_exchange_n(&(object)->__val, expected, \
413 desired, 1, success, failure)
414#define atomic_exchange_explicit(object, desired, order) \
415 __atomic_exchange_n(&(object)->__val, desired, order)
416#define atomic_fetch_add_explicit(object, operand, order) \
417 __atomic_fetch_add(&(object)->__val, operand, order)
418#define atomic_fetch_and_explicit(object, operand, order) \
419 __atomic_fetch_and(&(object)->__val, operand, order)
420#define atomic_fetch_or_explicit(object, operand, order) \
421 __atomic_fetch_or(&(object)->__val, operand, order)
422#define atomic_fetch_sub_explicit(object, operand, order) \
423 __atomic_fetch_sub(&(object)->__val, operand, order)
424#define atomic_fetch_xor_explicit(object, operand, order) \
425 __atomic_fetch_xor(&(object)->__val, operand, order)
426#define atomic_load_explicit(object, order) \
427 __atomic_load_n(&(object)->__val, order)
428#define atomic_store_explicit(object, desired, order) \
429 __atomic_store_n(&(object)->__val, desired, order)
430#else
431#define __atomic_apply_stride(object, operand) \
432 (((__typeof__((object)->__val))0) + (operand))
433#define atomic_compare_exchange_strong_explicit(object, expected, \
434 desired, success, failure) __extension__({ \
435 __typeof__(expected) __ep = (expected); \
436 __typeof__(*__ep) __e = *__ep; \
437 (void)(success); \
438 (void)(failure); \
439 (bool)((*__ep = __sync_val_compare_and_swap(&(object)->__val, \
440 __e, desired)) == __e); \
441})
442#define atomic_compare_exchange_weak_explicit(object, expected, \
443 desired, success, failure) \
444 atomic_compare_exchange_strong_explicit(object, expected, \
445 desired, success, failure)
446#ifdef __HAS_BUILTIN_SYNC_SWAP
447/* Clang provides a full-barrier atomic exchange - use it if available. */
448#define atomic_exchange_explicit(object, desired, order) \
449 ((void)(order), __sync_swap(&(object)->__val, desired))
450#else
451/*
452 * __sync_lock_test_and_set() is only an acquire barrier in theory (although in
453 * practice it is usually a full barrier) so we need an explicit barrier before
454 * it.
455 */
456#define atomic_exchange_explicit(object, desired, order) \
457 __extension__({ \
458 __typeof__(object) __o = (object); \
459 __typeof__(desired) __d = (desired); \
460 (void)(order); \
461 __sync_synchronize(); \
462 __sync_lock_test_and_set(&(__o)->__val, __d); \
463 })
464#endif
465#define atomic_fetch_add_explicit(object, operand, order) \
466 ((void)(order), __sync_fetch_and_add(&(object)->__val, \
467 __atomic_apply_stride(object, operand)))
468#define atomic_fetch_and_explicit(object, operand, order) \
469 ((void)(order), __sync_fetch_and_and(&(object)->__val, operand))
470#define atomic_fetch_or_explicit(object, operand, order) \
471 ((void)(order), __sync_fetch_and_or(&(object)->__val, operand))
472#define atomic_fetch_sub_explicit(object, operand, order) \
473 ((void)(order), __sync_fetch_and_sub(&(object)->__val, \
474 __atomic_apply_stride(object, operand)))
475#define atomic_fetch_xor_explicit(object, operand, order) \
476 ((void)(order), __sync_fetch_and_xor(&(object)->__val, operand))
477#define atomic_load_explicit(object, order) \
478 ((void)(order), __sync_fetch_and_add(&(object)->__val, 0))
479#define atomic_store_explicit(object, desired, order) \
480 ((void)atomic_exchange_explicit(object, desired, order))
481#endif
482/*
483 * Convenience functions.
484 *
485 * Don't provide these in kernel space. In kernel space, we should be
486 * disciplined enough to always provide explicit barriers.
487 */
488#ifndef _KERNEL
489#define atomic_compare_exchange_strong(object, expected, desired) \
490 atomic_compare_exchange_strong_explicit(object, expected, \
491 desired, memory_order_seq_cst, memory_order_seq_cst)
492#define atomic_compare_exchange_weak(object, expected, desired) \
493 atomic_compare_exchange_weak_explicit(object, expected, \
494 desired, memory_order_seq_cst, memory_order_seq_cst)
495#define atomic_exchange(object, desired) \
496 atomic_exchange_explicit(object, desired, memory_order_seq_cst)
497#define atomic_fetch_add(object, operand) \
498 atomic_fetch_add_explicit(object, operand, memory_order_seq_cst)
499#define atomic_fetch_and(object, operand) \
500 atomic_fetch_and_explicit(object, operand, memory_order_seq_cst)
501#define atomic_fetch_or(object, operand) \
502 atomic_fetch_or_explicit(object, operand, memory_order_seq_cst)
503#define atomic_fetch_sub(object, operand) \
504 atomic_fetch_sub_explicit(object, operand, memory_order_seq_cst)
505#define atomic_fetch_xor(object, operand) \
506 atomic_fetch_xor_explicit(object, operand, memory_order_seq_cst)
507#define atomic_load(object) \
508 atomic_load_explicit(object, memory_order_seq_cst)
509#define atomic_store(object, desired) \
510 atomic_store_explicit(object, desired, memory_order_seq_cst)
511#endif /* !_KERNEL */
512/*
513 * 7.17.8 Atomic flag type and operations.
514 *
515 * XXX: Assume atomic_bool can be used as an atomic_flag. Is there some
516 * kind of compiler built-in type we could use?
517 */
518typedef struct
519{
520 atomic_bool __flag;
521} atomic_flag;
522#define ATOMIC_FLAG_INIT \
523 { \
524 ATOMIC_VAR_INIT(false) \
525 }
526static __inline bool
527atomic_flag_test_and_set_explicit(volatile atomic_flag *__object,
528 memory_order __order)
529{
530 return (atomic_exchange_explicit(&__object->__flag, 1, __order));
531}
532static __inline void
533atomic_flag_clear_explicit(volatile atomic_flag *__object, memory_order __order)
534{
535 atomic_store_explicit(&__object->__flag, 0, __order);
536}
537#ifndef _KERNEL
538static __inline bool
539atomic_flag_test_and_set(volatile atomic_flag *__object)
540{
541 return (atomic_flag_test_and_set_explicit(__object,
542 memory_order_seq_cst));
543}
544static __inline void
545atomic_flag_clear(volatile atomic_flag *__object)
546{
547 atomic_flag_clear_explicit(__object, memory_order_seq_cst);
548}
549#endif /* !_KERNEL */
550#endif /* <atomic> unavailable */
551#endif /* !_STDATOMIC_H_ */
552