xref: /freebsd/contrib/llvm-project/libcxx/include/__cxx03/stdatomic.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1*700637cbSDimitry Andric // -*- C++ -*-
2*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
3*700637cbSDimitry Andric //
4*700637cbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*700637cbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
6*700637cbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*700637cbSDimitry Andric //
8*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
9*700637cbSDimitry Andric 
10*700637cbSDimitry Andric #ifndef _LIBCPP___CXX03_STDATOMIC_H
11*700637cbSDimitry Andric #define _LIBCPP___CXX03_STDATOMIC_H
12*700637cbSDimitry Andric 
13*700637cbSDimitry Andric /*
14*700637cbSDimitry Andric     stdatomic.h synopsis
15*700637cbSDimitry Andric 
16*700637cbSDimitry Andric template<class T>
17*700637cbSDimitry Andric   using std-atomic = std::atomic<T>;        // exposition only
18*700637cbSDimitry Andric 
19*700637cbSDimitry Andric #define _Atomic(T) std-atomic<T>
20*700637cbSDimitry Andric 
21*700637cbSDimitry Andric #define ATOMIC_BOOL_LOCK_FREE see below
22*700637cbSDimitry Andric #define ATOMIC_CHAR_LOCK_FREE see below
23*700637cbSDimitry Andric #define ATOMIC_CHAR16_T_LOCK_FREE see below
24*700637cbSDimitry Andric #define ATOMIC_CHAR32_T_LOCK_FREE see below
25*700637cbSDimitry Andric #define ATOMIC_WCHAR_T_LOCK_FREE see below
26*700637cbSDimitry Andric #define ATOMIC_SHORT_LOCK_FREE see below
27*700637cbSDimitry Andric #define ATOMIC_INT_LOCK_FREE see below
28*700637cbSDimitry Andric #define ATOMIC_LONG_LOCK_FREE see below
29*700637cbSDimitry Andric #define ATOMIC_LLONG_LOCK_FREE see below
30*700637cbSDimitry Andric #define ATOMIC_POINTER_LOCK_FREE see below
31*700637cbSDimitry Andric 
32*700637cbSDimitry Andric using std::memory_order                // see below
33*700637cbSDimitry Andric using std::memory_order_relaxed        // see below
34*700637cbSDimitry Andric using std::memory_order_consume        // see below
35*700637cbSDimitry Andric using std::memory_order_acquire        // see below
36*700637cbSDimitry Andric using std::memory_order_release        // see below
37*700637cbSDimitry Andric using std::memory_order_acq_rel        // see below
38*700637cbSDimitry Andric using std::memory_order_seq_cst        // see below
39*700637cbSDimitry Andric 
40*700637cbSDimitry Andric using std::atomic_flag                 // see below
41*700637cbSDimitry Andric 
42*700637cbSDimitry Andric using std::atomic_bool                 // see below
43*700637cbSDimitry Andric using std::atomic_char                 // see below
44*700637cbSDimitry Andric using std::atomic_schar                // see below
45*700637cbSDimitry Andric using std::atomic_uchar                // see below
46*700637cbSDimitry Andric using std::atomic_short                // see below
47*700637cbSDimitry Andric using std::atomic_ushort               // see below
48*700637cbSDimitry Andric using std::atomic_int                  // see below
49*700637cbSDimitry Andric using std::atomic_uint                 // see below
50*700637cbSDimitry Andric using std::atomic_long                 // see below
51*700637cbSDimitry Andric using std::atomic_ulong                // see below
52*700637cbSDimitry Andric using std::atomic_llong                // see below
53*700637cbSDimitry Andric using std::atomic_ullong               // see below
54*700637cbSDimitry Andric using std::atomic_char8_t              // see below
55*700637cbSDimitry Andric using std::atomic_char16_t             // see below
56*700637cbSDimitry Andric using std::atomic_char32_t             // see below
57*700637cbSDimitry Andric using std::atomic_wchar_t              // see below
58*700637cbSDimitry Andric using std::atomic_int8_t               // see below
59*700637cbSDimitry Andric using std::atomic_uint8_t              // see below
60*700637cbSDimitry Andric using std::atomic_int16_t              // see below
61*700637cbSDimitry Andric using std::atomic_uint16_t             // see below
62*700637cbSDimitry Andric using std::atomic_int32_t              // see below
63*700637cbSDimitry Andric using std::atomic_uint32_t             // see below
64*700637cbSDimitry Andric using std::atomic_int64_t              // see below
65*700637cbSDimitry Andric using std::atomic_uint64_t             // see below
66*700637cbSDimitry Andric using std::atomic_int_least8_t         // see below
67*700637cbSDimitry Andric using std::atomic_uint_least8_t        // see below
68*700637cbSDimitry Andric using std::atomic_int_least16_t        // see below
69*700637cbSDimitry Andric using std::atomic_uint_least16_t       // see below
70*700637cbSDimitry Andric using std::atomic_int_least32_t        // see below
71*700637cbSDimitry Andric using std::atomic_uint_least32_t       // see below
72*700637cbSDimitry Andric using std::atomic_int_least64_t        // see below
73*700637cbSDimitry Andric using std::atomic_uint_least64_t       // see below
74*700637cbSDimitry Andric using std::atomic_int_fast8_t          // see below
75*700637cbSDimitry Andric using std::atomic_uint_fast8_t         // see below
76*700637cbSDimitry Andric using std::atomic_int_fast16_t         // see below
77*700637cbSDimitry Andric using std::atomic_uint_fast16_t        // see below
78*700637cbSDimitry Andric using std::atomic_int_fast32_t         // see below
79*700637cbSDimitry Andric using std::atomic_uint_fast32_t        // see below
80*700637cbSDimitry Andric using std::atomic_int_fast64_t         // see below
81*700637cbSDimitry Andric using std::atomic_uint_fast64_t        // see below
82*700637cbSDimitry Andric using std::atomic_intptr_t             // see below
83*700637cbSDimitry Andric using std::atomic_uintptr_t            // see below
84*700637cbSDimitry Andric using std::atomic_size_t               // see below
85*700637cbSDimitry Andric using std::atomic_ptrdiff_t            // see below
86*700637cbSDimitry Andric using std::atomic_intmax_t             // see below
87*700637cbSDimitry Andric using std::atomic_uintmax_t            // see below
88*700637cbSDimitry Andric 
89*700637cbSDimitry Andric using std::atomic_is_lock_free                         // see below
90*700637cbSDimitry Andric using std::atomic_load                                 // see below
91*700637cbSDimitry Andric using std::atomic_load_explicit                        // see below
92*700637cbSDimitry Andric using std::atomic_store                                // see below
93*700637cbSDimitry Andric using std::atomic_store_explicit                       // see below
94*700637cbSDimitry Andric using std::atomic_exchange                             // see below
95*700637cbSDimitry Andric using std::atomic_exchange_explicit                    // see below
96*700637cbSDimitry Andric using std::atomic_compare_exchange_strong              // see below
97*700637cbSDimitry Andric using std::atomic_compare_exchange_strong_explicit     // see below
98*700637cbSDimitry Andric using std::atomic_compare_exchange_weak                // see below
99*700637cbSDimitry Andric using std::atomic_compare_exchange_weak_explicit       // see below
100*700637cbSDimitry Andric using std::atomic_fetch_add                            // see below
101*700637cbSDimitry Andric using std::atomic_fetch_add_explicit                   // see below
102*700637cbSDimitry Andric using std::atomic_fetch_sub                            // see below
103*700637cbSDimitry Andric using std::atomic_fetch_sub_explicit                   // see below
104*700637cbSDimitry Andric using std::atomic_fetch_or                             // see below
105*700637cbSDimitry Andric using std::atomic_fetch_or_explicit                    // see below
106*700637cbSDimitry Andric using std::atomic_fetch_and                            // see below
107*700637cbSDimitry Andric using std::atomic_fetch_and_explicit                   // see below
108*700637cbSDimitry Andric using std::atomic_flag_test_and_set                    // see below
109*700637cbSDimitry Andric using std::atomic_flag_test_and_set_explicit           // see below
110*700637cbSDimitry Andric using std::atomic_flag_clear                           // see below
111*700637cbSDimitry Andric using std::atomic_flag_clear_explicit                  // see below
112*700637cbSDimitry Andric 
113*700637cbSDimitry Andric using std::atomic_thread_fence                         // see below
114*700637cbSDimitry Andric using std::atomic_signal_fence                         // see below
115*700637cbSDimitry Andric 
116*700637cbSDimitry Andric */
117*700637cbSDimitry Andric 
118*700637cbSDimitry Andric #include <__cxx03/__config>
119*700637cbSDimitry Andric 
120*700637cbSDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
121*700637cbSDimitry Andric #  pragma GCC system_header
122*700637cbSDimitry Andric #endif
123*700637cbSDimitry Andric 
124*700637cbSDimitry Andric #if defined(__cplusplus) && false
125*700637cbSDimitry Andric 
126*700637cbSDimitry Andric #  include <__cxx03/atomic>
127*700637cbSDimitry Andric #  include <__cxx03/version>
128*700637cbSDimitry Andric 
129*700637cbSDimitry Andric #  ifdef _Atomic
130*700637cbSDimitry Andric #    undef _Atomic
131*700637cbSDimitry Andric #  endif
132*700637cbSDimitry Andric 
133*700637cbSDimitry Andric #  define _Atomic(_Tp) ::std::atomic<_Tp>
134*700637cbSDimitry Andric 
135*700637cbSDimitry Andric using std::memory_order _LIBCPP_USING_IF_EXISTS;
136*700637cbSDimitry Andric using std::memory_order_relaxed _LIBCPP_USING_IF_EXISTS;
137*700637cbSDimitry Andric using std::memory_order_consume _LIBCPP_USING_IF_EXISTS;
138*700637cbSDimitry Andric using std::memory_order_acquire _LIBCPP_USING_IF_EXISTS;
139*700637cbSDimitry Andric using std::memory_order_release _LIBCPP_USING_IF_EXISTS;
140*700637cbSDimitry Andric using std::memory_order_acq_rel _LIBCPP_USING_IF_EXISTS;
141*700637cbSDimitry Andric using std::memory_order_seq_cst _LIBCPP_USING_IF_EXISTS;
142*700637cbSDimitry Andric 
143*700637cbSDimitry Andric using std::atomic_flag _LIBCPP_USING_IF_EXISTS;
144*700637cbSDimitry Andric 
145*700637cbSDimitry Andric using std::atomic_bool _LIBCPP_USING_IF_EXISTS;
146*700637cbSDimitry Andric using std::atomic_char _LIBCPP_USING_IF_EXISTS;
147*700637cbSDimitry Andric using std::atomic_schar _LIBCPP_USING_IF_EXISTS;
148*700637cbSDimitry Andric using std::atomic_uchar _LIBCPP_USING_IF_EXISTS;
149*700637cbSDimitry Andric using std::atomic_short _LIBCPP_USING_IF_EXISTS;
150*700637cbSDimitry Andric using std::atomic_ushort _LIBCPP_USING_IF_EXISTS;
151*700637cbSDimitry Andric using std::atomic_int _LIBCPP_USING_IF_EXISTS;
152*700637cbSDimitry Andric using std::atomic_uint _LIBCPP_USING_IF_EXISTS;
153*700637cbSDimitry Andric using std::atomic_long _LIBCPP_USING_IF_EXISTS;
154*700637cbSDimitry Andric using std::atomic_ulong _LIBCPP_USING_IF_EXISTS;
155*700637cbSDimitry Andric using std::atomic_llong _LIBCPP_USING_IF_EXISTS;
156*700637cbSDimitry Andric using std::atomic_ullong _LIBCPP_USING_IF_EXISTS;
157*700637cbSDimitry Andric using std::atomic_char8_t _LIBCPP_USING_IF_EXISTS;
158*700637cbSDimitry Andric using std::atomic_char16_t _LIBCPP_USING_IF_EXISTS;
159*700637cbSDimitry Andric using std::atomic_char32_t _LIBCPP_USING_IF_EXISTS;
160*700637cbSDimitry Andric using std::atomic_wchar_t _LIBCPP_USING_IF_EXISTS;
161*700637cbSDimitry Andric 
162*700637cbSDimitry Andric using std::atomic_int8_t _LIBCPP_USING_IF_EXISTS;
163*700637cbSDimitry Andric using std::atomic_uint8_t _LIBCPP_USING_IF_EXISTS;
164*700637cbSDimitry Andric using std::atomic_int16_t _LIBCPP_USING_IF_EXISTS;
165*700637cbSDimitry Andric using std::atomic_uint16_t _LIBCPP_USING_IF_EXISTS;
166*700637cbSDimitry Andric using std::atomic_int32_t _LIBCPP_USING_IF_EXISTS;
167*700637cbSDimitry Andric using std::atomic_uint32_t _LIBCPP_USING_IF_EXISTS;
168*700637cbSDimitry Andric using std::atomic_int64_t _LIBCPP_USING_IF_EXISTS;
169*700637cbSDimitry Andric using std::atomic_uint64_t _LIBCPP_USING_IF_EXISTS;
170*700637cbSDimitry Andric 
171*700637cbSDimitry Andric using std::atomic_int_least8_t _LIBCPP_USING_IF_EXISTS;
172*700637cbSDimitry Andric using std::atomic_uint_least8_t _LIBCPP_USING_IF_EXISTS;
173*700637cbSDimitry Andric using std::atomic_int_least16_t _LIBCPP_USING_IF_EXISTS;
174*700637cbSDimitry Andric using std::atomic_uint_least16_t _LIBCPP_USING_IF_EXISTS;
175*700637cbSDimitry Andric using std::atomic_int_least32_t _LIBCPP_USING_IF_EXISTS;
176*700637cbSDimitry Andric using std::atomic_uint_least32_t _LIBCPP_USING_IF_EXISTS;
177*700637cbSDimitry Andric using std::atomic_int_least64_t _LIBCPP_USING_IF_EXISTS;
178*700637cbSDimitry Andric using std::atomic_uint_least64_t _LIBCPP_USING_IF_EXISTS;
179*700637cbSDimitry Andric 
180*700637cbSDimitry Andric using std::atomic_int_fast8_t _LIBCPP_USING_IF_EXISTS;
181*700637cbSDimitry Andric using std::atomic_uint_fast8_t _LIBCPP_USING_IF_EXISTS;
182*700637cbSDimitry Andric using std::atomic_int_fast16_t _LIBCPP_USING_IF_EXISTS;
183*700637cbSDimitry Andric using std::atomic_uint_fast16_t _LIBCPP_USING_IF_EXISTS;
184*700637cbSDimitry Andric using std::atomic_int_fast32_t _LIBCPP_USING_IF_EXISTS;
185*700637cbSDimitry Andric using std::atomic_uint_fast32_t _LIBCPP_USING_IF_EXISTS;
186*700637cbSDimitry Andric using std::atomic_int_fast64_t _LIBCPP_USING_IF_EXISTS;
187*700637cbSDimitry Andric using std::atomic_uint_fast64_t _LIBCPP_USING_IF_EXISTS;
188*700637cbSDimitry Andric 
189*700637cbSDimitry Andric using std::atomic_intptr_t _LIBCPP_USING_IF_EXISTS;
190*700637cbSDimitry Andric using std::atomic_uintptr_t _LIBCPP_USING_IF_EXISTS;
191*700637cbSDimitry Andric using std::atomic_size_t _LIBCPP_USING_IF_EXISTS;
192*700637cbSDimitry Andric using std::atomic_ptrdiff_t _LIBCPP_USING_IF_EXISTS;
193*700637cbSDimitry Andric using std::atomic_intmax_t _LIBCPP_USING_IF_EXISTS;
194*700637cbSDimitry Andric using std::atomic_uintmax_t _LIBCPP_USING_IF_EXISTS;
195*700637cbSDimitry Andric 
196*700637cbSDimitry Andric using std::atomic_compare_exchange_strong _LIBCPP_USING_IF_EXISTS;
197*700637cbSDimitry Andric using std::atomic_compare_exchange_strong_explicit _LIBCPP_USING_IF_EXISTS;
198*700637cbSDimitry Andric using std::atomic_compare_exchange_weak _LIBCPP_USING_IF_EXISTS;
199*700637cbSDimitry Andric using std::atomic_compare_exchange_weak_explicit _LIBCPP_USING_IF_EXISTS;
200*700637cbSDimitry Andric using std::atomic_exchange _LIBCPP_USING_IF_EXISTS;
201*700637cbSDimitry Andric using std::atomic_exchange_explicit _LIBCPP_USING_IF_EXISTS;
202*700637cbSDimitry Andric using std::atomic_fetch_add _LIBCPP_USING_IF_EXISTS;
203*700637cbSDimitry Andric using std::atomic_fetch_add_explicit _LIBCPP_USING_IF_EXISTS;
204*700637cbSDimitry Andric using std::atomic_fetch_and _LIBCPP_USING_IF_EXISTS;
205*700637cbSDimitry Andric using std::atomic_fetch_and_explicit _LIBCPP_USING_IF_EXISTS;
206*700637cbSDimitry Andric using std::atomic_fetch_or _LIBCPP_USING_IF_EXISTS;
207*700637cbSDimitry Andric using std::atomic_fetch_or_explicit _LIBCPP_USING_IF_EXISTS;
208*700637cbSDimitry Andric using std::atomic_fetch_sub _LIBCPP_USING_IF_EXISTS;
209*700637cbSDimitry Andric using std::atomic_fetch_sub_explicit _LIBCPP_USING_IF_EXISTS;
210*700637cbSDimitry Andric using std::atomic_flag_clear _LIBCPP_USING_IF_EXISTS;
211*700637cbSDimitry Andric using std::atomic_flag_clear_explicit _LIBCPP_USING_IF_EXISTS;
212*700637cbSDimitry Andric using std::atomic_flag_test_and_set _LIBCPP_USING_IF_EXISTS;
213*700637cbSDimitry Andric using std::atomic_flag_test_and_set_explicit _LIBCPP_USING_IF_EXISTS;
214*700637cbSDimitry Andric using std::atomic_is_lock_free _LIBCPP_USING_IF_EXISTS;
215*700637cbSDimitry Andric using std::atomic_load _LIBCPP_USING_IF_EXISTS;
216*700637cbSDimitry Andric using std::atomic_load_explicit _LIBCPP_USING_IF_EXISTS;
217*700637cbSDimitry Andric using std::atomic_store _LIBCPP_USING_IF_EXISTS;
218*700637cbSDimitry Andric using std::atomic_store_explicit _LIBCPP_USING_IF_EXISTS;
219*700637cbSDimitry Andric 
220*700637cbSDimitry Andric using std::atomic_signal_fence _LIBCPP_USING_IF_EXISTS;
221*700637cbSDimitry Andric using std::atomic_thread_fence _LIBCPP_USING_IF_EXISTS;
222*700637cbSDimitry Andric 
223*700637cbSDimitry Andric #elif defined(_LIBCPP_COMPILER_CLANG_BASED)
224*700637cbSDimitry Andric 
225*700637cbSDimitry Andric // Before C++23, we include the next <stdatomic.h> on the path to avoid hijacking
226*700637cbSDimitry Andric // the header. We do this because Clang has historically shipped a <stdatomic.h>
227*700637cbSDimitry Andric // header that would be available in all Standard modes, and we don't want to
228*700637cbSDimitry Andric // break that use case.
229*700637cbSDimitry Andric #  if __has_include_next(<stdatomic.h>)
230*700637cbSDimitry Andric #    include_next <stdatomic.h>
231*700637cbSDimitry Andric #  endif
232*700637cbSDimitry Andric 
233*700637cbSDimitry Andric #endif // defined(__cplusplus) && false
234*700637cbSDimitry Andric 
235*700637cbSDimitry Andric #endif // _LIBCPP___CXX03_STDATOMIC_H
236