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