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