| 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_ATOMIC |
| 11 | #define _LIBCPP_ATOMIC |
| 12 | |
| 13 | /* |
| 14 | atomic synopsis |
| 15 | |
| 16 | namespace std |
| 17 | { |
| 18 | |
| 19 | // feature test macro [version.syn] |
| 20 | |
| 21 | #define __cpp_lib_atomic_is_always_lock_free |
| 22 | #define __cpp_lib_atomic_flag_test |
| 23 | #define __cpp_lib_atomic_lock_free_type_aliases |
| 24 | #define __cpp_lib_atomic_wait |
| 25 | |
| 26 | // order and consistency |
| 27 | |
| 28 | enum memory_order: unspecified // enum class in C++20 |
| 29 | { |
| 30 | relaxed, |
| 31 | consume, // load-consume |
| 32 | acquire, // load-acquire |
| 33 | release, // store-release |
| 34 | acq_rel, // store-release load-acquire |
| 35 | seq_cst // store-release load-acquire |
| 36 | }; |
| 37 | |
| 38 | inline constexpr auto memory_order_relaxed = memory_order::relaxed; |
| 39 | inline constexpr auto memory_order_consume = memory_order::consume; |
| 40 | inline constexpr auto memory_order_acquire = memory_order::acquire; |
| 41 | inline constexpr auto memory_order_release = memory_order::release; |
| 42 | inline constexpr auto memory_order_acq_rel = memory_order::acq_rel; |
| 43 | inline constexpr auto memory_order_seq_cst = memory_order::seq_cst; |
| 44 | |
| 45 | template <class T> T kill_dependency(T y) noexcept; |
| 46 | |
| 47 | // lock-free property |
| 48 | |
| 49 | #define ATOMIC_BOOL_LOCK_FREE unspecified |
| 50 | #define ATOMIC_CHAR_LOCK_FREE unspecified |
| 51 | #define ATOMIC_CHAR8_T_LOCK_FREE unspecified // C++20 |
| 52 | #define ATOMIC_CHAR16_T_LOCK_FREE unspecified |
| 53 | #define ATOMIC_CHAR32_T_LOCK_FREE unspecified |
| 54 | #define ATOMIC_WCHAR_T_LOCK_FREE unspecified |
| 55 | #define ATOMIC_SHORT_LOCK_FREE unspecified |
| 56 | #define ATOMIC_INT_LOCK_FREE unspecified |
| 57 | #define ATOMIC_LONG_LOCK_FREE unspecified |
| 58 | #define ATOMIC_LLONG_LOCK_FREE unspecified |
| 59 | #define ATOMIC_POINTER_LOCK_FREE unspecified |
| 60 | |
| 61 | template <class T> |
| 62 | struct atomic |
| 63 | { |
| 64 | using value_type = T; |
| 65 | |
| 66 | static constexpr bool is_always_lock_free; |
| 67 | bool is_lock_free() const volatile noexcept; |
| 68 | bool is_lock_free() const noexcept; |
| 69 | |
| 70 | atomic() noexcept = default; // until C++20 |
| 71 | constexpr atomic() noexcept(is_nothrow_default_constructible_v<T>); // since C++20 |
| 72 | constexpr atomic(T desr) noexcept; |
| 73 | atomic(const atomic&) = delete; |
| 74 | atomic& operator=(const atomic&) = delete; |
| 75 | atomic& operator=(const atomic&) volatile = delete; |
| 76 | |
| 77 | T load(memory_order m = memory_order_seq_cst) const volatile noexcept; |
| 78 | T load(memory_order m = memory_order_seq_cst) const noexcept; |
| 79 | operator T() const volatile noexcept; |
| 80 | operator T() const noexcept; |
| 81 | void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 82 | void store(T desr, memory_order m = memory_order_seq_cst) noexcept; |
| 83 | T operator=(T) volatile noexcept; |
| 84 | T operator=(T) noexcept; |
| 85 | |
| 86 | T exchange(T desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 87 | T exchange(T desr, memory_order m = memory_order_seq_cst) noexcept; |
| 88 | bool compare_exchange_weak(T& expc, T desr, |
| 89 | memory_order s, memory_order f) volatile noexcept; |
| 90 | bool compare_exchange_weak(T& expc, T desr, memory_order s, memory_order f) noexcept; |
| 91 | bool compare_exchange_strong(T& expc, T desr, |
| 92 | memory_order s, memory_order f) volatile noexcept; |
| 93 | bool compare_exchange_strong(T& expc, T desr, |
| 94 | memory_order s, memory_order f) noexcept; |
| 95 | bool compare_exchange_weak(T& expc, T desr, |
| 96 | memory_order m = memory_order_seq_cst) volatile noexcept; |
| 97 | bool compare_exchange_weak(T& expc, T desr, |
| 98 | memory_order m = memory_order_seq_cst) noexcept; |
| 99 | bool compare_exchange_strong(T& expc, T desr, |
| 100 | memory_order m = memory_order_seq_cst) volatile noexcept; |
| 101 | bool compare_exchange_strong(T& expc, T desr, |
| 102 | memory_order m = memory_order_seq_cst) noexcept; |
| 103 | |
| 104 | void wait(T, memory_order = memory_order::seq_cst) const volatile noexcept; // since C++20 |
| 105 | void wait(T, memory_order = memory_order::seq_cst) const noexcept; // since C++20 |
| 106 | void notify_one() volatile noexcept; // since C++20 |
| 107 | void notify_one() noexcept; // since C++20 |
| 108 | void notify_all() volatile noexcept; // since C++20 |
| 109 | void notify_all() noexcept; // since C++20 |
| 110 | }; |
| 111 | |
| 112 | template <> |
| 113 | struct atomic<integral> |
| 114 | { |
| 115 | using value_type = integral; |
| 116 | using difference_type = value_type; |
| 117 | |
| 118 | static constexpr bool is_always_lock_free; |
| 119 | bool is_lock_free() const volatile noexcept; |
| 120 | bool is_lock_free() const noexcept; |
| 121 | |
| 122 | atomic() noexcept = default; |
| 123 | constexpr atomic(integral desr) noexcept; |
| 124 | atomic(const atomic&) = delete; |
| 125 | atomic& operator=(const atomic&) = delete; |
| 126 | atomic& operator=(const atomic&) volatile = delete; |
| 127 | |
| 128 | integral load(memory_order m = memory_order_seq_cst) const volatile noexcept; |
| 129 | integral load(memory_order m = memory_order_seq_cst) const noexcept; |
| 130 | operator integral() const volatile noexcept; |
| 131 | operator integral() const noexcept; |
| 132 | void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 133 | void store(integral desr, memory_order m = memory_order_seq_cst) noexcept; |
| 134 | integral operator=(integral desr) volatile noexcept; |
| 135 | integral operator=(integral desr) noexcept; |
| 136 | |
| 137 | integral exchange(integral desr, |
| 138 | memory_order m = memory_order_seq_cst) volatile noexcept; |
| 139 | integral exchange(integral desr, memory_order m = memory_order_seq_cst) noexcept; |
| 140 | bool compare_exchange_weak(integral& expc, integral desr, |
| 141 | memory_order s, memory_order f) volatile noexcept; |
| 142 | bool compare_exchange_weak(integral& expc, integral desr, |
| 143 | memory_order s, memory_order f) noexcept; |
| 144 | bool compare_exchange_strong(integral& expc, integral desr, |
| 145 | memory_order s, memory_order f) volatile noexcept; |
| 146 | bool compare_exchange_strong(integral& expc, integral desr, |
| 147 | memory_order s, memory_order f) noexcept; |
| 148 | bool compare_exchange_weak(integral& expc, integral desr, |
| 149 | memory_order m = memory_order_seq_cst) volatile noexcept; |
| 150 | bool compare_exchange_weak(integral& expc, integral desr, |
| 151 | memory_order m = memory_order_seq_cst) noexcept; |
| 152 | bool compare_exchange_strong(integral& expc, integral desr, |
| 153 | memory_order m = memory_order_seq_cst) volatile noexcept; |
| 154 | bool compare_exchange_strong(integral& expc, integral desr, |
| 155 | memory_order m = memory_order_seq_cst) noexcept; |
| 156 | |
| 157 | integral fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 158 | integral fetch_add(integral op, memory_order m = memory_order_seq_cst) noexcept; |
| 159 | integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 160 | integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) noexcept; |
| 161 | integral fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 162 | integral fetch_and(integral op, memory_order m = memory_order_seq_cst) noexcept; |
| 163 | integral fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 164 | integral fetch_or(integral op, memory_order m = memory_order_seq_cst) noexcept; |
| 165 | integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 166 | integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) noexcept; |
| 167 | integral fetch_max(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 168 | integral fetch_max(integral op, memory_order m = memory_order_seq_cst) noexcept; |
| 169 | integral fetch_min(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 170 | integral fetch_min(integral op, memory_order m = memory_order_seq_cst) noexcept; |
| 171 | |
| 172 | integral operator++(int) volatile noexcept; |
| 173 | integral operator++(int) noexcept; |
| 174 | integral operator--(int) volatile noexcept; |
| 175 | integral operator--(int) noexcept; |
| 176 | integral operator++() volatile noexcept; |
| 177 | integral operator++() noexcept; |
| 178 | integral operator--() volatile noexcept; |
| 179 | integral operator--() noexcept; |
| 180 | integral operator+=(integral op) volatile noexcept; |
| 181 | integral operator+=(integral op) noexcept; |
| 182 | integral operator-=(integral op) volatile noexcept; |
| 183 | integral operator-=(integral op) noexcept; |
| 184 | integral operator&=(integral op) volatile noexcept; |
| 185 | integral operator&=(integral op) noexcept; |
| 186 | integral operator|=(integral op) volatile noexcept; |
| 187 | integral operator|=(integral op) noexcept; |
| 188 | integral operator^=(integral op) volatile noexcept; |
| 189 | integral operator^=(integral op) noexcept; |
| 190 | |
| 191 | void wait(integral, memory_order = memory_order::seq_cst) const volatile noexcept; // since C++20 |
| 192 | void wait(integral, memory_order = memory_order::seq_cst) const noexcept; // since C++20 |
| 193 | void notify_one() volatile noexcept; // since C++20 |
| 194 | void notify_one() noexcept; // since C++20 |
| 195 | void notify_all() volatile noexcept; // since C++20 |
| 196 | void notify_all() noexcept; // since C++20 |
| 197 | }; |
| 198 | |
| 199 | template <class T> |
| 200 | struct atomic<T*> |
| 201 | { |
| 202 | using value_type = T*; |
| 203 | using difference_type = ptrdiff_t; |
| 204 | |
| 205 | static constexpr bool is_always_lock_free; |
| 206 | bool is_lock_free() const volatile noexcept; |
| 207 | bool is_lock_free() const noexcept; |
| 208 | |
| 209 | atomic() noexcept = default; // until C++20 |
| 210 | constexpr atomic() noexcept; // since C++20 |
| 211 | constexpr atomic(T* desr) noexcept; |
| 212 | atomic(const atomic&) = delete; |
| 213 | atomic& operator=(const atomic&) = delete; |
| 214 | atomic& operator=(const atomic&) volatile = delete; |
| 215 | |
| 216 | T* load(memory_order m = memory_order_seq_cst) const volatile noexcept; |
| 217 | T* load(memory_order m = memory_order_seq_cst) const noexcept; |
| 218 | operator T*() const volatile noexcept; |
| 219 | operator T*() const noexcept; |
| 220 | void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 221 | void store(T* desr, memory_order m = memory_order_seq_cst) noexcept; |
| 222 | T* operator=(T*) volatile noexcept; |
| 223 | T* operator=(T*) noexcept; |
| 224 | |
| 225 | T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 226 | T* exchange(T* desr, memory_order m = memory_order_seq_cst) noexcept; |
| 227 | bool compare_exchange_weak(T*& expc, T* desr, |
| 228 | memory_order s, memory_order f) volatile noexcept; |
| 229 | bool compare_exchange_weak(T*& expc, T* desr, |
| 230 | memory_order s, memory_order f) noexcept; |
| 231 | bool compare_exchange_strong(T*& expc, T* desr, |
| 232 | memory_order s, memory_order f) volatile noexcept; |
| 233 | bool compare_exchange_strong(T*& expc, T* desr, |
| 234 | memory_order s, memory_order f) noexcept; |
| 235 | bool compare_exchange_weak(T*& expc, T* desr, |
| 236 | memory_order m = memory_order_seq_cst) volatile noexcept; |
| 237 | bool compare_exchange_weak(T*& expc, T* desr, |
| 238 | memory_order m = memory_order_seq_cst) noexcept; |
| 239 | bool compare_exchange_strong(T*& expc, T* desr, |
| 240 | memory_order m = memory_order_seq_cst) volatile noexcept; |
| 241 | bool compare_exchange_strong(T*& expc, T* desr, |
| 242 | memory_order m = memory_order_seq_cst) noexcept; |
| 243 | T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 244 | T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept; |
| 245 | T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 246 | T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept; |
| 247 | T* fetch_max(T*, memory_order = memory_order_seq_cst) volatile noexcept; |
| 248 | T* fetch_max(T*, memory_order = memory_order_seq_cst) noexcept; |
| 249 | T* fetch_min(T*, memory_order = memory_order_seq_cst) volatile noexcept; |
| 250 | T* fetch_min(T*, memory_order = memory_order_seq_cst) noexcept; |
| 251 | |
| 252 | T* operator++(int) volatile noexcept; |
| 253 | T* operator++(int) noexcept; |
| 254 | T* operator--(int) volatile noexcept; |
| 255 | T* operator--(int) noexcept; |
| 256 | T* operator++() volatile noexcept; |
| 257 | T* operator++() noexcept; |
| 258 | T* operator--() volatile noexcept; |
| 259 | T* operator--() noexcept; |
| 260 | T* operator+=(ptrdiff_t op) volatile noexcept; |
| 261 | T* operator+=(ptrdiff_t op) noexcept; |
| 262 | T* operator-=(ptrdiff_t op) volatile noexcept; |
| 263 | T* operator-=(ptrdiff_t op) noexcept; |
| 264 | |
| 265 | void wait(T*, memory_order = memory_order::seq_cst) const volatile noexcept; // since C++20 |
| 266 | void wait(T*, memory_order = memory_order::seq_cst) const noexcept; // since C++20 |
| 267 | void notify_one() volatile noexcept; // since C++20 |
| 268 | void notify_one() noexcept; // since C++20 |
| 269 | void notify_all() volatile noexcept; // since C++20 |
| 270 | void notify_all() noexcept; // since C++20 |
| 271 | }; |
| 272 | |
| 273 | template<> |
| 274 | struct atomic<floating-point-type> { // since C++20 |
| 275 | using value_type = floating-point-type; |
| 276 | using difference_type = value_type; |
| 277 | |
| 278 | static constexpr bool is_always_lock_free = implementation-defined; |
| 279 | bool is_lock_free() const volatile noexcept; |
| 280 | bool is_lock_free() const noexcept; |
| 281 | |
| 282 | constexpr atomic() noexcept; |
| 283 | constexpr atomic(floating-point-type) noexcept; |
| 284 | atomic(const atomic&) = delete; |
| 285 | atomic& operator=(const atomic&) = delete; |
| 286 | atomic& operator=(const atomic&) volatile = delete; |
| 287 | |
| 288 | void store(floating-point-type, memory_order = memory_order::seq_cst) volatile noexcept; |
| 289 | void store(floating-point-type, memory_order = memory_order::seq_cst) noexcept; |
| 290 | floating-point-type operator=(floating-point-type) volatile noexcept; |
| 291 | floating-point-type operator=(floating-point-type) noexcept; |
| 292 | floating-point-type load(memory_order = memory_order::seq_cst) volatile noexcept; |
| 293 | floating-point-type load(memory_order = memory_order::seq_cst) noexcept; |
| 294 | operator floating-point-type() volatile noexcept; |
| 295 | operator floating-point-type() noexcept; |
| 296 | |
| 297 | floating-point-type exchange(floating-point-type, |
| 298 | memory_order = memory_order::seq_cst) volatile noexcept; |
| 299 | floating-point-type exchange(floating-point-type, |
| 300 | memory_order = memory_order::seq_cst) noexcept; |
| 301 | bool compare_exchange_weak(floating-point-type&, floating-point-type, |
| 302 | memory_order, memory_order) volatile noexcept; |
| 303 | bool compare_exchange_weak(floating-point-type&, floating-point-type, |
| 304 | memory_order, memory_order) noexcept; |
| 305 | bool compare_exchange_strong(floating-point-type&, floating-point-type, |
| 306 | memory_order, memory_order) volatile noexcept; |
| 307 | bool compare_exchange_strong(floating-point-type&, floating-point-type, |
| 308 | memory_order, memory_order) noexcept; |
| 309 | bool compare_exchange_weak(floating-point-type&, floating-point-type, |
| 310 | memory_order = memory_order::seq_cst) volatile noexcept; |
| 311 | bool compare_exchange_weak(floating-point-type&, floating-point-type, |
| 312 | memory_order = memory_order::seq_cst) noexcept; |
| 313 | bool compare_exchange_strong(floating-point-type&, floating-point-type, |
| 314 | memory_order = memory_order::seq_cst) volatile noexcept; |
| 315 | bool compare_exchange_strong(floating-point-type&, floating-point-type, |
| 316 | memory_order = memory_order::seq_cst) noexcept; |
| 317 | |
| 318 | floating-point-type fetch_add(floating-point-type, |
| 319 | memory_order = memory_order::seq_cst) volatile noexcept; |
| 320 | floating-point-type fetch_add(floating-point-type, |
| 321 | memory_order = memory_order::seq_cst) noexcept; |
| 322 | floating-point-type fetch_sub(floating-point-type, |
| 323 | memory_order = memory_order::seq_cst) volatile noexcept; |
| 324 | floating-point-type fetch_sub(floating-point-type, |
| 325 | memory_order = memory_order::seq_cst) noexcept; |
| 326 | |
| 327 | floating-point-type operator+=(floating-point-type) volatile noexcept; |
| 328 | floating-point-type operator+=(floating-point-type) noexcept; |
| 329 | floating-point-type operator-=(floating-point-type) volatile noexcept; |
| 330 | floating-point-type operator-=(floating-point-type) noexcept; |
| 331 | |
| 332 | void wait(floating-point-type, memory_order = memory_order::seq_cst) const volatile noexcept; // since C++20 |
| 333 | void wait(floating-point-type, memory_order = memory_order::seq_cst) const noexcept; // since C++20 |
| 334 | void notify_one() volatile noexcept; // since C++20 |
| 335 | void notify_one() noexcept; // since C++20 |
| 336 | void notify_all() volatile noexcept; // since C++20 |
| 337 | void notify_all() noexcept; // since C++20 |
| 338 | }; |
| 339 | |
| 340 | // [atomics.nonmembers], non-member functions |
| 341 | template<class T> |
| 342 | bool atomic_is_lock_free(const volatile atomic<T>*) noexcept; |
| 343 | template<class T> |
| 344 | bool atomic_is_lock_free(const atomic<T>*) noexcept; |
| 345 | template<class T> |
| 346 | void atomic_store(volatile atomic<T>*, atomic<T>::value_type) noexcept; |
| 347 | template<class T> |
| 348 | void atomic_store(atomic<T>*, atomic<T>::value_type) noexcept; |
| 349 | template<class T> |
| 350 | void atomic_store_explicit(volatile atomic<T>*, atomic<T>::value_type, |
| 351 | memory_order) noexcept; |
| 352 | template<class T> |
| 353 | void atomic_store_explicit(atomic<T>*, atomic<T>::value_type, |
| 354 | memory_order) noexcept; |
| 355 | template<class T> |
| 356 | T atomic_load(const volatile atomic<T>*) noexcept; |
| 357 | template<class T> |
| 358 | T atomic_load(const atomic<T>*) noexcept; |
| 359 | template<class T> |
| 360 | T atomic_load_explicit(const volatile atomic<T>*, memory_order) noexcept; |
| 361 | template<class T> |
| 362 | T atomic_load_explicit(const atomic<T>*, memory_order) noexcept; |
| 363 | template<class T> |
| 364 | T atomic_exchange(volatile atomic<T>*, atomic<T>::value_type) noexcept; |
| 365 | template<class T> |
| 366 | T atomic_exchange(atomic<T>*, atomic<T>::value_type) noexcept; |
| 367 | template<class T> |
| 368 | T atomic_exchange_explicit(volatile atomic<T>*, atomic<T>::value_type, |
| 369 | memory_order) noexcept; |
| 370 | template<class T> |
| 371 | T atomic_exchange_explicit(atomic<T>*, atomic<T>::value_type, |
| 372 | memory_order) noexcept; |
| 373 | template<class T> |
| 374 | bool atomic_compare_exchange_weak(volatile atomic<T>*, atomic<T>::value_type*, |
| 375 | atomic<T>::value_type) noexcept; |
| 376 | template<class T> |
| 377 | bool atomic_compare_exchange_weak(atomic<T>*, atomic<T>::value_type*, |
| 378 | atomic<T>::value_type) noexcept; |
| 379 | template<class T> |
| 380 | bool atomic_compare_exchange_strong(volatile atomic<T>*, atomic<T>::value_type*, |
| 381 | atomic<T>::value_type) noexcept; |
| 382 | template<class T> |
| 383 | bool atomic_compare_exchange_strong(atomic<T>*, atomic<T>::value_type*, |
| 384 | atomic<T>::value_type) noexcept; |
| 385 | template<class T> |
| 386 | bool atomic_compare_exchange_weak_explicit(volatile atomic<T>*, atomic<T>::value_type*, |
| 387 | atomic<T>::value_type, |
| 388 | memory_order, memory_order) noexcept; |
| 389 | template<class T> |
| 390 | bool atomic_compare_exchange_weak_explicit(atomic<T>*, atomic<T>::value_type*, |
| 391 | atomic<T>::value_type, |
| 392 | memory_order, memory_order) noexcept; |
| 393 | template<class T> |
| 394 | bool atomic_compare_exchange_strong_explicit(volatile atomic<T>*, atomic<T>::value_type*, |
| 395 | atomic<T>::value_type, |
| 396 | memory_order, memory_order) noexcept; |
| 397 | template<class T> |
| 398 | bool atomic_compare_exchange_strong_explicit(atomic<T>*, atomic<T>::value_type*, |
| 399 | atomic<T>::value_type, |
| 400 | memory_order, memory_order) noexcept; |
| 401 | |
| 402 | template<class T> |
| 403 | T atomic_fetch_add(volatile atomic<T>*, atomic<T>::difference_type) noexcept; |
| 404 | template<class T> |
| 405 | T atomic_fetch_add(atomic<T>*, atomic<T>::difference_type) noexcept; |
| 406 | template<class T> |
| 407 | T atomic_fetch_add_explicit(volatile atomic<T>*, atomic<T>::difference_type, |
| 408 | memory_order) noexcept; |
| 409 | template<class T> |
| 410 | T atomic_fetch_add_explicit(atomic<T>*, atomic<T>::difference_type, |
| 411 | memory_order) noexcept; |
| 412 | template<class T> |
| 413 | T atomic_fetch_sub(volatile atomic<T>*, atomic<T>::difference_type) noexcept; |
| 414 | template<class T> |
| 415 | T atomic_fetch_sub(atomic<T>*, atomic<T>::difference_type) noexcept; |
| 416 | template<class T> |
| 417 | T atomic_fetch_sub_explicit(volatile atomic<T>*, atomic<T>::difference_type, |
| 418 | memory_order) noexcept; |
| 419 | template<class T> |
| 420 | T atomic_fetch_sub_explicit(atomic<T>*, atomic<T>::difference_type, |
| 421 | memory_order) noexcept; |
| 422 | template<class T> |
| 423 | T atomic_fetch_and(volatile atomic<T>*, atomic<T>::value_type) noexcept; |
| 424 | template<class T> |
| 425 | T atomic_fetch_and(atomic<T>*, atomic<T>::value_type) noexcept; |
| 426 | template<class T> |
| 427 | T atomic_fetch_and_explicit(volatile atomic<T>*, atomic<T>::value_type, |
| 428 | memory_order) noexcept; |
| 429 | template<class T> |
| 430 | T atomic_fetch_and_explicit(atomic<T>*, atomic<T>::value_type, |
| 431 | memory_order) noexcept; |
| 432 | template<class T> |
| 433 | T atomic_fetch_or(volatile atomic<T>*, atomic<T>::value_type) noexcept; |
| 434 | template<class T> |
| 435 | T atomic_fetch_or(atomic<T>*, atomic<T>::value_type) noexcept; |
| 436 | template<class T> |
| 437 | T atomic_fetch_or_explicit(volatile atomic<T>*, atomic<T>::value_type, |
| 438 | memory_order) noexcept; |
| 439 | template<class T> |
| 440 | T atomic_fetch_or_explicit(atomic<T>*, atomic<T>::value_type, |
| 441 | memory_order) noexcept; |
| 442 | template<class T> |
| 443 | T atomic_fetch_xor(volatile atomic<T>*, atomic<T>::value_type) noexcept; |
| 444 | template<class T> |
| 445 | T atomic_fetch_xor(atomic<T>*, atomic<T>::value_type) noexcept; |
| 446 | template<class T> |
| 447 | T atomic_fetch_xor_explicit(volatile atomic<T>*, atomic<T>::value_type, |
| 448 | memory_order) noexcept; |
| 449 | template<class T> |
| 450 | T atomic_fetch_xor_explicit(atomic<T>*, atomic<T>::value_type, |
| 451 | memory_order) noexcept; |
| 452 | template<class T> |
| 453 | T atomic_fetch_max(volatile atomic<T>*, atomic<T>::value_type) noexcept; |
| 454 | template<class T> |
| 455 | T atomic_fetch_max(atomic<T>*, atomic<T>::value_type) noexcept; |
| 456 | template<class T> |
| 457 | T atomic_fetch_max_explicit(volatile atomic<T>*, atomic<T>::value_type, |
| 458 | memory_order) noexcept; |
| 459 | template<class T> |
| 460 | T atomic_fetch_max_explicit(atomic<T>*, atomic<T>::value_type, |
| 461 | memory_order) noexcept; |
| 462 | template<class T> |
| 463 | T atomic_fetch_min(volatile atomic<T>*, atomic<T>::value_type) noexcept; |
| 464 | template<class T> |
| 465 | T atomic_fetch_min(atomic<T>*, atomic<T>::value_type) noexcept; |
| 466 | template<class T> |
| 467 | T atomic_fetch_min_explicit(volatile atomic<T>*, atomic<T>::value_type, |
| 468 | memory_order) noexcept; |
| 469 | template<class T> |
| 470 | T atomic_fetch_min_explicit(atomic<T>*, atomic<T>::value_type, |
| 471 | memory_order) noexcept; |
| 472 | |
| 473 | template<class T> |
| 474 | void atomic_wait(const volatile atomic<T>*, atomic<T>::value_type) noexcept; // since C++20 |
| 475 | template<class T> |
| 476 | void atomic_wait(const atomic<T>*, atomic<T>::value_type) noexcept; // since C++20 |
| 477 | template<class T> |
| 478 | void atomic_wait_explicit(const volatile atomic<T>*, atomic<T>::value_type, // since C++20 |
| 479 | memory_order) noexcept; |
| 480 | template<class T> |
| 481 | void atomic_wait_explicit(const atomic<T>*, atomic<T>::value_type, // since C++20 |
| 482 | memory_order) noexcept; |
| 483 | template<class T> |
| 484 | void atomic_notify_one(volatile atomic<T>*) noexcept; // since C++20 |
| 485 | template<class T> |
| 486 | void atomic_notify_one(atomic<T>*) noexcept; // since C++20 |
| 487 | template<class T> |
| 488 | void atomic_notify_all(volatile atomic<T>*) noexcept; // since C++20 |
| 489 | template<class T> |
| 490 | void atomic_notify_all(atomic<T>*) noexcept; // since C++20 |
| 491 | |
| 492 | // Atomics for standard typedef types |
| 493 | |
| 494 | typedef atomic<bool> atomic_bool; |
| 495 | typedef atomic<char> atomic_char; |
| 496 | typedef atomic<signed char> atomic_schar; |
| 497 | typedef atomic<unsigned char> atomic_uchar; |
| 498 | typedef atomic<short> atomic_short; |
| 499 | typedef atomic<unsigned short> atomic_ushort; |
| 500 | typedef atomic<int> atomic_int; |
| 501 | typedef atomic<unsigned int> atomic_uint; |
| 502 | typedef atomic<long> atomic_long; |
| 503 | typedef atomic<unsigned long> atomic_ulong; |
| 504 | typedef atomic<long long> atomic_llong; |
| 505 | typedef atomic<unsigned long long> atomic_ullong; |
| 506 | typedef atomic<char8_t> atomic_char8_t; // C++20 |
| 507 | typedef atomic<char16_t> atomic_char16_t; |
| 508 | typedef atomic<char32_t> atomic_char32_t; |
| 509 | typedef atomic<wchar_t> atomic_wchar_t; |
| 510 | |
| 511 | typedef atomic<int_least8_t> atomic_int_least8_t; |
| 512 | typedef atomic<uint_least8_t> atomic_uint_least8_t; |
| 513 | typedef atomic<int_least16_t> atomic_int_least16_t; |
| 514 | typedef atomic<uint_least16_t> atomic_uint_least16_t; |
| 515 | typedef atomic<int_least32_t> atomic_int_least32_t; |
| 516 | typedef atomic<uint_least32_t> atomic_uint_least32_t; |
| 517 | typedef atomic<int_least64_t> atomic_int_least64_t; |
| 518 | typedef atomic<uint_least64_t> atomic_uint_least64_t; |
| 519 | |
| 520 | typedef atomic<int_fast8_t> atomic_int_fast8_t; |
| 521 | typedef atomic<uint_fast8_t> atomic_uint_fast8_t; |
| 522 | typedef atomic<int_fast16_t> atomic_int_fast16_t; |
| 523 | typedef atomic<uint_fast16_t> atomic_uint_fast16_t; |
| 524 | typedef atomic<int_fast32_t> atomic_int_fast32_t; |
| 525 | typedef atomic<uint_fast32_t> atomic_uint_fast32_t; |
| 526 | typedef atomic<int_fast64_t> atomic_int_fast64_t; |
| 527 | typedef atomic<uint_fast64_t> atomic_uint_fast64_t; |
| 528 | |
| 529 | typedef atomic<int8_t> atomic_int8_t; |
| 530 | typedef atomic<uint8_t> atomic_uint8_t; |
| 531 | typedef atomic<int16_t> atomic_int16_t; |
| 532 | typedef atomic<uint16_t> atomic_uint16_t; |
| 533 | typedef atomic<int32_t> atomic_int32_t; |
| 534 | typedef atomic<uint32_t> atomic_uint32_t; |
| 535 | typedef atomic<int64_t> atomic_int64_t; |
| 536 | typedef atomic<uint64_t> atomic_uint64_t; |
| 537 | |
| 538 | typedef atomic<intptr_t> atomic_intptr_t; |
| 539 | typedef atomic<uintptr_t> atomic_uintptr_t; |
| 540 | typedef atomic<size_t> atomic_size_t; |
| 541 | typedef atomic<ptrdiff_t> atomic_ptrdiff_t; |
| 542 | typedef atomic<intmax_t> atomic_intmax_t; |
| 543 | typedef atomic<uintmax_t> atomic_uintmax_t; |
| 544 | |
| 545 | typedef see-below atomic_signed_lock_free; // since C++20 |
| 546 | typedef see-below atomic_unsigned_lock_free; // since C++20 |
| 547 | |
| 548 | // flag type and operations |
| 549 | |
| 550 | typedef struct atomic_flag |
| 551 | { |
| 552 | atomic_flag() noexcept = default; // until C++20 |
| 553 | constexpr atomic_flag() noexcept; // since C++20 |
| 554 | atomic_flag(const atomic_flag&) = delete; |
| 555 | atomic_flag& operator=(const atomic_flag&) = delete; |
| 556 | atomic_flag& operator=(const atomic_flag&) volatile = delete; |
| 557 | |
| 558 | bool test(memory_order m = memory_order_seq_cst) volatile noexcept; |
| 559 | bool test(memory_order m = memory_order_seq_cst) noexcept; |
| 560 | bool test_and_set(memory_order m = memory_order_seq_cst) volatile noexcept; |
| 561 | bool test_and_set(memory_order m = memory_order_seq_cst) noexcept; |
| 562 | void clear(memory_order m = memory_order_seq_cst) volatile noexcept; |
| 563 | void clear(memory_order m = memory_order_seq_cst) noexcept; |
| 564 | |
| 565 | void wait(bool, memory_order = memory_order::seq_cst) const volatile noexcept; // since C++20 |
| 566 | void wait(bool, memory_order = memory_order::seq_cst) const noexcept; // since C++20 |
| 567 | void notify_one() volatile noexcept; // since C++20 |
| 568 | void notify_one() noexcept; // since C++20 |
| 569 | void notify_all() volatile noexcept; // since C++20 |
| 570 | void notify_all() noexcept; // since C++20 |
| 571 | } atomic_flag; |
| 572 | |
| 573 | bool atomic_flag_test(volatile atomic_flag* obj) noexcept; |
| 574 | bool atomic_flag_test(atomic_flag* obj) noexcept; |
| 575 | bool atomic_flag_test_explicit(volatile atomic_flag* obj, |
| 576 | memory_order m) noexcept; |
| 577 | bool atomic_flag_test_explicit(atomic_flag* obj, memory_order m) noexcept; |
| 578 | bool atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept; |
| 579 | bool atomic_flag_test_and_set(atomic_flag* obj) noexcept; |
| 580 | bool atomic_flag_test_and_set_explicit(volatile atomic_flag* obj, |
| 581 | memory_order m) noexcept; |
| 582 | bool atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m) noexcept; |
| 583 | void atomic_flag_clear(volatile atomic_flag* obj) noexcept; |
| 584 | void atomic_flag_clear(atomic_flag* obj) noexcept; |
| 585 | void atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept; |
| 586 | void atomic_flag_clear_explicit(atomic_flag* obj, memory_order m) noexcept; |
| 587 | |
| 588 | void atomic_wait(const volatile atomic_flag* obj, T old) noexcept; // since C++20 |
| 589 | void atomic_wait(const atomic_flag* obj, T old) noexcept; // since C++20 |
| 590 | void atomic_wait_explicit(const volatile atomic_flag* obj, T old, memory_order m) noexcept; // since C++20 |
| 591 | void atomic_wait_explicit(const atomic_flag* obj, T old, memory_order m) noexcept; // since C++20 |
| 592 | void atomic_one(volatile atomic_flag* obj) noexcept; // since C++20 |
| 593 | void atomic_one(atomic_flag* obj) noexcept; // since C++20 |
| 594 | void atomic_all(volatile atomic_flag* obj) noexcept; // since C++20 |
| 595 | void atomic_all(atomic_flag* obj) noexcept; // since C++20 |
| 596 | |
| 597 | // fences |
| 598 | |
| 599 | void atomic_thread_fence(memory_order m) noexcept; |
| 600 | void atomic_signal_fence(memory_order m) noexcept; |
| 601 | |
| 602 | // deprecated |
| 603 | |
| 604 | template <class T> |
| 605 | void atomic_init(volatile atomic<T>* obj, atomic<T>::value_type desr) noexcept; |
| 606 | |
| 607 | template <class T> |
| 608 | void atomic_init(atomic<T>* obj, atomic<T>::value_type desr) noexcept; |
| 609 | |
| 610 | #define ATOMIC_VAR_INIT(value) see below |
| 611 | |
| 612 | #define ATOMIC_FLAG_INIT see below |
| 613 | |
| 614 | } // std |
| 615 | |
| 616 | */ |
| 617 | |
| 618 | #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 619 | # include <__cxx03/atomic> |
| 620 | #else |
| 621 | # include <__config> |
| 622 | |
| 623 | # if defined(_LIBCPP_STDATOMIC_H) || defined(kill_dependency) || defined(atomic_load) |
| 624 | # define _LIBCPP_STDATOMIC_H_HAS_DEFINITELY_BEEN_INCLUDED 1 |
| 625 | # else |
| 626 | # define _LIBCPP_STDATOMIC_H_HAS_DEFINITELY_BEEN_INCLUDED 0 |
| 627 | # endif |
| 628 | |
| 629 | # if _LIBCPP_STD_VER < 23 && _LIBCPP_STDATOMIC_H_HAS_DEFINITELY_BEEN_INCLUDED |
| 630 | # error <atomic> is incompatible with <stdatomic.h> before C++23. Please compile with -std=c++23. |
| 631 | # endif |
| 632 | |
| 633 | # include <__atomic/aliases.h> |
| 634 | # include <__atomic/atomic.h> |
| 635 | # include <__atomic/atomic_flag.h> |
| 636 | # include <__atomic/atomic_init.h> |
| 637 | # include <__atomic/atomic_lock_free.h> |
| 638 | # include <__atomic/atomic_sync.h> |
| 639 | # include <__atomic/atomic_sync_timed.h> |
| 640 | # include <__atomic/atomic_waitable_traits.h> |
| 641 | # include <__atomic/check_memory_order.h> |
| 642 | # include <__atomic/contention_t.h> |
| 643 | # include <__atomic/fence.h> |
| 644 | # include <__atomic/is_always_lock_free.h> |
| 645 | # include <__atomic/kill_dependency.h> |
| 646 | # include <__atomic/memory_order.h> |
| 647 | # include <version> |
| 648 | |
| 649 | # if _LIBCPP_STD_VER >= 20 |
| 650 | # include <__atomic/atomic_ref.h> |
| 651 | # endif |
| 652 | |
| 653 | # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 654 | # pragma GCC system_header |
| 655 | # endif |
| 656 | |
| 657 | # if defined(_LIBCPP_KEEP_TRANSITIVE_INCLUDES_LLVM23) && _LIBCPP_STD_VER <= 20 |
| 658 | # include <cmath> |
| 659 | # include <compare> |
| 660 | # include <cstddef> |
| 661 | # include <cstdlib> |
| 662 | # include <cstring> |
| 663 | # include <type_traits> |
| 664 | # endif |
| 665 | #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 666 | |
| 667 | #endif // _LIBCPP_ATOMIC |
| 668 | |