xref: /aosp_15_r20/bionic/libc/include/stdatomic.h (revision 8d67ca893c1523eb926b9080dbe4e2ffd2a27ba1)
1*8d67ca89SAndroid Build Coastguard Worker /*-
2*8d67ca89SAndroid Build Coastguard Worker  * Copyright (c) 2011 Ed Schouten <[email protected]>
3*8d67ca89SAndroid Build Coastguard Worker  *                    David Chisnall <[email protected]>
4*8d67ca89SAndroid Build Coastguard Worker  * All rights reserved.
5*8d67ca89SAndroid Build Coastguard Worker  *
6*8d67ca89SAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
7*8d67ca89SAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions
8*8d67ca89SAndroid Build Coastguard Worker  * are met:
9*8d67ca89SAndroid Build Coastguard Worker  * 1. Redistributions of source code must retain the above copyright
10*8d67ca89SAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer.
11*8d67ca89SAndroid Build Coastguard Worker  * 2. Redistributions in binary form must reproduce the above copyright
12*8d67ca89SAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer in the
13*8d67ca89SAndroid Build Coastguard Worker  *    documentation and/or other materials provided with the distribution.
14*8d67ca89SAndroid Build Coastguard Worker  *
15*8d67ca89SAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*8d67ca89SAndroid Build Coastguard Worker  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*8d67ca89SAndroid Build Coastguard Worker  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*8d67ca89SAndroid Build Coastguard Worker  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*8d67ca89SAndroid Build Coastguard Worker  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*8d67ca89SAndroid Build Coastguard Worker  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*8d67ca89SAndroid Build Coastguard Worker  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*8d67ca89SAndroid Build Coastguard Worker  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*8d67ca89SAndroid Build Coastguard Worker  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*8d67ca89SAndroid Build Coastguard Worker  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*8d67ca89SAndroid Build Coastguard Worker  * SUCH DAMAGE.
26*8d67ca89SAndroid Build Coastguard Worker  *
27*8d67ca89SAndroid Build Coastguard Worker  * $FreeBSD$
28*8d67ca89SAndroid Build Coastguard Worker  */
29*8d67ca89SAndroid Build Coastguard Worker 
30*8d67ca89SAndroid Build Coastguard Worker #ifndef _STDATOMIC_H_
31*8d67ca89SAndroid Build Coastguard Worker #define	_STDATOMIC_H_
32*8d67ca89SAndroid Build Coastguard Worker 
33*8d67ca89SAndroid Build Coastguard Worker #include <sys/cdefs.h>
34*8d67ca89SAndroid Build Coastguard Worker 
35*8d67ca89SAndroid Build Coastguard Worker #if defined(__cplusplus) && __cplusplus >= 201103L && __has_include(<atomic>)
36*8d67ca89SAndroid Build Coastguard Worker # if __has_feature(cxx_atomic)
37*8d67ca89SAndroid Build Coastguard Worker #  define _STDATOMIC_HAVE_ATOMIC
38*8d67ca89SAndroid Build Coastguard Worker # endif
39*8d67ca89SAndroid Build Coastguard Worker #endif
40*8d67ca89SAndroid Build Coastguard Worker 
41*8d67ca89SAndroid Build Coastguard Worker #ifdef _STDATOMIC_HAVE_ATOMIC
42*8d67ca89SAndroid Build Coastguard Worker 
43*8d67ca89SAndroid Build Coastguard Worker /* We have a usable C++ <atomic>; use it instead.  */
44*8d67ca89SAndroid Build Coastguard Worker 
45*8d67ca89SAndroid Build Coastguard Worker #include <atomic>
46*8d67ca89SAndroid Build Coastguard Worker 
47*8d67ca89SAndroid Build Coastguard Worker #undef _Atomic
48*8d67ca89SAndroid Build Coastguard Worker         /* Also defined by <atomic> for gcc.  But not used in macros. */
49*8d67ca89SAndroid Build Coastguard Worker         /* Also a clang intrinsic.                                    */
50*8d67ca89SAndroid Build Coastguard Worker         /* Should not be used by client code before this file is      */
51*8d67ca89SAndroid Build Coastguard Worker         /* included.  The definitions in <atomic> themselves see      */
52*8d67ca89SAndroid Build Coastguard Worker         /* the old definition, as they should.                        */
53*8d67ca89SAndroid Build Coastguard Worker         /* Client code sees the following definition.                 */
54*8d67ca89SAndroid Build Coastguard Worker 
55*8d67ca89SAndroid Build Coastguard Worker #define _Atomic(t) std::atomic<t>
56*8d67ca89SAndroid Build Coastguard Worker 
57*8d67ca89SAndroid Build Coastguard Worker using std::atomic_is_lock_free;
58*8d67ca89SAndroid Build Coastguard Worker using std::atomic_init;
59*8d67ca89SAndroid Build Coastguard Worker using std::atomic_store;
60*8d67ca89SAndroid Build Coastguard Worker using std::atomic_store_explicit;
61*8d67ca89SAndroid Build Coastguard Worker using std::atomic_load;
62*8d67ca89SAndroid Build Coastguard Worker using std::atomic_load_explicit;
63*8d67ca89SAndroid Build Coastguard Worker using std::atomic_exchange;
64*8d67ca89SAndroid Build Coastguard Worker using std::atomic_exchange_explicit;
65*8d67ca89SAndroid Build Coastguard Worker using std::atomic_compare_exchange_strong;
66*8d67ca89SAndroid Build Coastguard Worker using std::atomic_compare_exchange_strong_explicit;
67*8d67ca89SAndroid Build Coastguard Worker using std::atomic_compare_exchange_weak;
68*8d67ca89SAndroid Build Coastguard Worker using std::atomic_compare_exchange_weak_explicit;
69*8d67ca89SAndroid Build Coastguard Worker using std::atomic_fetch_add;
70*8d67ca89SAndroid Build Coastguard Worker using std::atomic_fetch_add_explicit;
71*8d67ca89SAndroid Build Coastguard Worker using std::atomic_fetch_sub;
72*8d67ca89SAndroid Build Coastguard Worker using std::atomic_fetch_sub_explicit;
73*8d67ca89SAndroid Build Coastguard Worker using std::atomic_fetch_or;
74*8d67ca89SAndroid Build Coastguard Worker using std::atomic_fetch_or_explicit;
75*8d67ca89SAndroid Build Coastguard Worker using std::atomic_fetch_xor;
76*8d67ca89SAndroid Build Coastguard Worker using std::atomic_fetch_xor_explicit;
77*8d67ca89SAndroid Build Coastguard Worker using std::atomic_fetch_and;
78*8d67ca89SAndroid Build Coastguard Worker using std::atomic_fetch_and_explicit;
79*8d67ca89SAndroid Build Coastguard Worker using std::atomic_thread_fence;
80*8d67ca89SAndroid Build Coastguard Worker using std::atomic_signal_fence;
81*8d67ca89SAndroid Build Coastguard Worker 
82*8d67ca89SAndroid Build Coastguard Worker using std::memory_order;
83*8d67ca89SAndroid Build Coastguard Worker using std::memory_order_relaxed;
84*8d67ca89SAndroid Build Coastguard Worker using std::memory_order_consume;
85*8d67ca89SAndroid Build Coastguard Worker using std::memory_order_acquire;
86*8d67ca89SAndroid Build Coastguard Worker using std::memory_order_release;
87*8d67ca89SAndroid Build Coastguard Worker using std::memory_order_acq_rel;
88*8d67ca89SAndroid Build Coastguard Worker using std::memory_order_seq_cst;
89*8d67ca89SAndroid Build Coastguard Worker 
90*8d67ca89SAndroid Build Coastguard Worker using std::atomic_bool;
91*8d67ca89SAndroid Build Coastguard Worker using std::atomic_char;
92*8d67ca89SAndroid Build Coastguard Worker using std::atomic_schar;
93*8d67ca89SAndroid Build Coastguard Worker using std::atomic_uchar;
94*8d67ca89SAndroid Build Coastguard Worker using std::atomic_short;
95*8d67ca89SAndroid Build Coastguard Worker using std::atomic_ushort;
96*8d67ca89SAndroid Build Coastguard Worker using std::atomic_int;
97*8d67ca89SAndroid Build Coastguard Worker using std::atomic_uint;
98*8d67ca89SAndroid Build Coastguard Worker using std::atomic_long;
99*8d67ca89SAndroid Build Coastguard Worker using std::atomic_ulong;
100*8d67ca89SAndroid Build Coastguard Worker using std::atomic_llong;
101*8d67ca89SAndroid Build Coastguard Worker using std::atomic_ullong;
102*8d67ca89SAndroid Build Coastguard Worker using std::atomic_char16_t;
103*8d67ca89SAndroid Build Coastguard Worker using std::atomic_char32_t;
104*8d67ca89SAndroid Build Coastguard Worker using std::atomic_wchar_t;
105*8d67ca89SAndroid Build Coastguard Worker using std::atomic_int_least8_t;
106*8d67ca89SAndroid Build Coastguard Worker using std::atomic_uint_least8_t;
107*8d67ca89SAndroid Build Coastguard Worker using std::atomic_int_least16_t;
108*8d67ca89SAndroid Build Coastguard Worker using std::atomic_uint_least16_t;
109*8d67ca89SAndroid Build Coastguard Worker using std::atomic_int_least32_t;
110*8d67ca89SAndroid Build Coastguard Worker using std::atomic_uint_least32_t;
111*8d67ca89SAndroid Build Coastguard Worker using std::atomic_int_least64_t;
112*8d67ca89SAndroid Build Coastguard Worker using std::atomic_uint_least64_t;
113*8d67ca89SAndroid Build Coastguard Worker using std::atomic_int_fast8_t;
114*8d67ca89SAndroid Build Coastguard Worker using std::atomic_uint_fast8_t;
115*8d67ca89SAndroid Build Coastguard Worker using std::atomic_int_fast16_t;
116*8d67ca89SAndroid Build Coastguard Worker using std::atomic_uint_fast16_t;
117*8d67ca89SAndroid Build Coastguard Worker using std::atomic_int_fast32_t;
118*8d67ca89SAndroid Build Coastguard Worker using std::atomic_uint_fast32_t;
119*8d67ca89SAndroid Build Coastguard Worker using std::atomic_int_fast64_t;
120*8d67ca89SAndroid Build Coastguard Worker using std::atomic_uint_fast64_t;
121*8d67ca89SAndroid Build Coastguard Worker using std::atomic_intptr_t;
122*8d67ca89SAndroid Build Coastguard Worker using std::atomic_uintptr_t;
123*8d67ca89SAndroid Build Coastguard Worker using std::atomic_size_t;
124*8d67ca89SAndroid Build Coastguard Worker using std::atomic_ptrdiff_t;
125*8d67ca89SAndroid Build Coastguard Worker using std::atomic_intmax_t;
126*8d67ca89SAndroid Build Coastguard Worker using std::atomic_uintmax_t;
127*8d67ca89SAndroid Build Coastguard Worker 
128*8d67ca89SAndroid Build Coastguard Worker #else /* <atomic> unavailable, possibly because this is C, not C++ */
129*8d67ca89SAndroid Build Coastguard Worker 
130*8d67ca89SAndroid Build Coastguard Worker /* Actual implementation is in bits/stdatomic.h since our test code is C++. */
131*8d67ca89SAndroid Build Coastguard Worker #include <bits/stdatomic.h>
132*8d67ca89SAndroid Build Coastguard Worker 
133*8d67ca89SAndroid Build Coastguard Worker #endif /* <atomic> unavailable */
134*8d67ca89SAndroid Build Coastguard Worker 
135*8d67ca89SAndroid Build Coastguard Worker #endif /* !_STDATOMIC_H_ */
136