Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- atomic -----------------------------------===// |
| 3 | // |
Chandler Carruth | 7642bb1 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_ATOMIC |
| 11 | #define _LIBCPP_ATOMIC |
| 12 | |
| 13 | /* |
| 14 | atomic synopsis |
| 15 | |
| 16 | namespace std |
| 17 | { |
| 18 | |
JF Bastien | fdb42c2 | 2016-03-25 15:48:21 +0000 | [diff] [blame] | 19 | // feature test macro |
| 20 | |
| 21 | #define __cpp_lib_atomic_is_always_lock_free // as specified by SG10 |
| 22 | |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 23 | // order and consistency |
| 24 | |
| 25 | typedef enum memory_order |
| 26 | { |
Howard Hinnant | dca6e71 | 2010-09-28 17:13:38 +0000 | [diff] [blame] | 27 | memory_order_relaxed, |
| 28 | memory_order_consume, // load-consume |
| 29 | memory_order_acquire, // load-acquire |
| 30 | memory_order_release, // store-release |
| 31 | memory_order_acq_rel, // store-release load-acquire |
| 32 | memory_order_seq_cst // store-release load-acquire |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 33 | } memory_order; |
| 34 | |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 35 | template <class T> T kill_dependency(T y) noexcept; |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 36 | |
| 37 | // lock-free property |
| 38 | |
Howard Hinnant | 931e340 | 2013-01-21 20:39:41 +0000 | [diff] [blame] | 39 | #define ATOMIC_BOOL_LOCK_FREE unspecified |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 40 | #define ATOMIC_CHAR_LOCK_FREE unspecified |
| 41 | #define ATOMIC_CHAR16_T_LOCK_FREE unspecified |
| 42 | #define ATOMIC_CHAR32_T_LOCK_FREE unspecified |
| 43 | #define ATOMIC_WCHAR_T_LOCK_FREE unspecified |
| 44 | #define ATOMIC_SHORT_LOCK_FREE unspecified |
| 45 | #define ATOMIC_INT_LOCK_FREE unspecified |
| 46 | #define ATOMIC_LONG_LOCK_FREE unspecified |
| 47 | #define ATOMIC_LLONG_LOCK_FREE unspecified |
Howard Hinnant | 931e340 | 2013-01-21 20:39:41 +0000 | [diff] [blame] | 48 | #define ATOMIC_POINTER_LOCK_FREE unspecified |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 49 | |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 50 | // flag type and operations |
| 51 | |
| 52 | typedef struct atomic_flag |
| 53 | { |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 54 | bool test_and_set(memory_order m = memory_order_seq_cst) volatile noexcept; |
| 55 | bool test_and_set(memory_order m = memory_order_seq_cst) noexcept; |
| 56 | void clear(memory_order m = memory_order_seq_cst) volatile noexcept; |
| 57 | void clear(memory_order m = memory_order_seq_cst) noexcept; |
| 58 | atomic_flag() noexcept = default; |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 59 | atomic_flag(const atomic_flag&) = delete; |
| 60 | atomic_flag& operator=(const atomic_flag&) = delete; |
| 61 | atomic_flag& operator=(const atomic_flag&) volatile = delete; |
| 62 | } atomic_flag; |
| 63 | |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 64 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 65 | atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 66 | |
| 67 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 68 | atomic_flag_test_and_set(atomic_flag* obj) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 69 | |
| 70 | bool |
| 71 | atomic_flag_test_and_set_explicit(volatile atomic_flag* obj, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 72 | memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 73 | |
| 74 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 75 | atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 76 | |
| 77 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 78 | atomic_flag_clear(volatile atomic_flag* obj) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 79 | |
| 80 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 81 | atomic_flag_clear(atomic_flag* obj) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 82 | |
| 83 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 84 | atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 85 | |
| 86 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 87 | atomic_flag_clear_explicit(atomic_flag* obj, memory_order m) noexcept; |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 88 | |
| 89 | #define ATOMIC_FLAG_INIT see below |
Howard Hinnant | 493d1d9 | 2010-10-19 16:51:18 +0000 | [diff] [blame] | 90 | #define ATOMIC_VAR_INIT(value) see below |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 91 | |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 92 | template <class T> |
| 93 | struct atomic |
| 94 | { |
JF Bastien | fdb42c2 | 2016-03-25 15:48:21 +0000 | [diff] [blame] | 95 | static constexpr bool is_always_lock_free; |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 96 | bool is_lock_free() const volatile noexcept; |
| 97 | bool is_lock_free() const noexcept; |
| 98 | void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 99 | void store(T desr, memory_order m = memory_order_seq_cst) noexcept; |
| 100 | T load(memory_order m = memory_order_seq_cst) const volatile noexcept; |
| 101 | T load(memory_order m = memory_order_seq_cst) const noexcept; |
| 102 | operator T() const volatile noexcept; |
| 103 | operator T() const noexcept; |
| 104 | T exchange(T desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 105 | T exchange(T desr, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 106 | bool compare_exchange_weak(T& expc, T desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 107 | memory_order s, memory_order f) volatile noexcept; |
| 108 | bool compare_exchange_weak(T& expc, T desr, memory_order s, memory_order f) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 109 | bool compare_exchange_strong(T& expc, T desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 110 | memory_order s, memory_order f) volatile noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 111 | bool compare_exchange_strong(T& expc, T desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 112 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 113 | bool compare_exchange_weak(T& expc, T desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 114 | memory_order m = memory_order_seq_cst) volatile noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 115 | bool compare_exchange_weak(T& expc, T desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 116 | memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 117 | bool compare_exchange_strong(T& expc, T desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 118 | memory_order m = memory_order_seq_cst) volatile noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 119 | bool compare_exchange_strong(T& expc, T desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 120 | memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 121 | |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 122 | atomic() noexcept = default; |
| 123 | constexpr atomic(T desr) noexcept; |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 124 | atomic(const atomic&) = delete; |
| 125 | atomic& operator=(const atomic&) = delete; |
| 126 | atomic& operator=(const atomic&) volatile = delete; |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 127 | T operator=(T) volatile noexcept; |
| 128 | T operator=(T) noexcept; |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | template <> |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 132 | struct atomic<integral> |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 133 | { |
JF Bastien | fdb42c2 | 2016-03-25 15:48:21 +0000 | [diff] [blame] | 134 | static constexpr bool is_always_lock_free; |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 135 | bool is_lock_free() const volatile noexcept; |
| 136 | bool is_lock_free() const noexcept; |
| 137 | void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 138 | void store(integral desr, memory_order m = memory_order_seq_cst) noexcept; |
| 139 | integral load(memory_order m = memory_order_seq_cst) const volatile noexcept; |
| 140 | integral load(memory_order m = memory_order_seq_cst) const noexcept; |
| 141 | operator integral() const volatile noexcept; |
| 142 | operator integral() const noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 143 | integral exchange(integral desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 144 | memory_order m = memory_order_seq_cst) volatile noexcept; |
| 145 | integral exchange(integral desr, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 146 | bool compare_exchange_weak(integral& expc, integral desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 147 | memory_order s, memory_order f) volatile noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 148 | bool compare_exchange_weak(integral& expc, integral desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 149 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 150 | bool compare_exchange_strong(integral& expc, integral desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 151 | memory_order s, memory_order f) volatile noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 152 | bool compare_exchange_strong(integral& expc, integral desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 153 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 154 | bool compare_exchange_weak(integral& expc, integral desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 155 | memory_order m = memory_order_seq_cst) volatile noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 156 | bool compare_exchange_weak(integral& expc, integral desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 157 | memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 158 | bool compare_exchange_strong(integral& expc, integral desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 159 | memory_order m = memory_order_seq_cst) volatile noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 160 | bool compare_exchange_strong(integral& expc, integral desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 161 | memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 162 | |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 163 | integral |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 164 | fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 165 | integral fetch_add(integral op, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 166 | integral |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 167 | fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 168 | integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 169 | integral |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 170 | fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 171 | integral fetch_and(integral op, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 172 | integral |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 173 | fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 174 | integral fetch_or(integral op, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 175 | integral |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 176 | fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 177 | integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 178 | |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 179 | atomic() noexcept = default; |
| 180 | constexpr atomic(integral desr) noexcept; |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 181 | atomic(const atomic&) = delete; |
| 182 | atomic& operator=(const atomic&) = delete; |
| 183 | atomic& operator=(const atomic&) volatile = delete; |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 184 | integral operator=(integral desr) volatile noexcept; |
| 185 | integral operator=(integral desr) noexcept; |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 186 | |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 187 | integral operator++(int) volatile noexcept; |
| 188 | integral operator++(int) noexcept; |
| 189 | integral operator--(int) volatile noexcept; |
| 190 | integral operator--(int) noexcept; |
| 191 | integral operator++() volatile noexcept; |
| 192 | integral operator++() noexcept; |
| 193 | integral operator--() volatile noexcept; |
| 194 | integral operator--() noexcept; |
| 195 | integral operator+=(integral op) volatile noexcept; |
| 196 | integral operator+=(integral op) noexcept; |
| 197 | integral operator-=(integral op) volatile noexcept; |
| 198 | integral operator-=(integral op) noexcept; |
| 199 | integral operator&=(integral op) volatile noexcept; |
| 200 | integral operator&=(integral op) noexcept; |
| 201 | integral operator|=(integral op) volatile noexcept; |
| 202 | integral operator|=(integral op) noexcept; |
| 203 | integral operator^=(integral op) volatile noexcept; |
| 204 | integral operator^=(integral op) noexcept; |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 205 | }; |
| 206 | |
| 207 | template <class T> |
| 208 | struct atomic<T*> |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 209 | { |
JF Bastien | fdb42c2 | 2016-03-25 15:48:21 +0000 | [diff] [blame] | 210 | static constexpr bool is_always_lock_free; |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 211 | bool is_lock_free() const volatile noexcept; |
| 212 | bool is_lock_free() const noexcept; |
| 213 | void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 214 | void store(T* desr, memory_order m = memory_order_seq_cst) noexcept; |
| 215 | T* load(memory_order m = memory_order_seq_cst) const volatile noexcept; |
| 216 | T* load(memory_order m = memory_order_seq_cst) const noexcept; |
| 217 | operator T*() const volatile noexcept; |
| 218 | operator T*() const noexcept; |
| 219 | T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 220 | T* exchange(T* desr, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 221 | bool compare_exchange_weak(T*& expc, T* desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 222 | memory_order s, memory_order f) volatile noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 223 | bool compare_exchange_weak(T*& expc, T* desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 224 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 225 | bool compare_exchange_strong(T*& expc, T* desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 226 | memory_order s, memory_order f) volatile noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 227 | bool compare_exchange_strong(T*& expc, T* desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 228 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 229 | bool compare_exchange_weak(T*& expc, T* desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 230 | memory_order m = memory_order_seq_cst) volatile noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 231 | bool compare_exchange_weak(T*& expc, T* desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 232 | memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 233 | bool compare_exchange_strong(T*& expc, T* desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 234 | memory_order m = memory_order_seq_cst) volatile noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 235 | bool compare_exchange_strong(T*& expc, T* desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 236 | memory_order m = memory_order_seq_cst) noexcept; |
| 237 | T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 238 | T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept; |
| 239 | T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 240 | T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 241 | |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 242 | atomic() noexcept = default; |
| 243 | constexpr atomic(T* desr) noexcept; |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 244 | atomic(const atomic&) = delete; |
| 245 | atomic& operator=(const atomic&) = delete; |
| 246 | atomic& operator=(const atomic&) volatile = delete; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 247 | |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 248 | T* operator=(T*) volatile noexcept; |
| 249 | T* operator=(T*) noexcept; |
| 250 | T* operator++(int) volatile noexcept; |
| 251 | T* operator++(int) noexcept; |
| 252 | T* operator--(int) volatile noexcept; |
| 253 | T* operator--(int) noexcept; |
| 254 | T* operator++() volatile noexcept; |
| 255 | T* operator++() noexcept; |
| 256 | T* operator--() volatile noexcept; |
| 257 | T* operator--() noexcept; |
| 258 | T* operator+=(ptrdiff_t op) volatile noexcept; |
| 259 | T* operator+=(ptrdiff_t op) noexcept; |
| 260 | T* operator-=(ptrdiff_t op) volatile noexcept; |
| 261 | T* operator-=(ptrdiff_t op) noexcept; |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 262 | }; |
| 263 | |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 264 | |
| 265 | template <class T> |
| 266 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 267 | atomic_is_lock_free(const volatile atomic<T>* obj) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 268 | |
| 269 | template <class T> |
| 270 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 271 | atomic_is_lock_free(const atomic<T>* obj) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 272 | |
| 273 | template <class T> |
| 274 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 275 | atomic_init(volatile atomic<T>* obj, T desr) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 276 | |
| 277 | template <class T> |
| 278 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 279 | atomic_init(atomic<T>* obj, T desr) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 280 | |
| 281 | template <class T> |
| 282 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 283 | atomic_store(volatile atomic<T>* obj, T desr) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 284 | |
| 285 | template <class T> |
| 286 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 287 | atomic_store(atomic<T>* obj, T desr) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 288 | |
| 289 | template <class T> |
| 290 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 291 | atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 292 | |
| 293 | template <class T> |
| 294 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 295 | atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 296 | |
| 297 | template <class T> |
| 298 | T |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 299 | atomic_load(const volatile atomic<T>* obj) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 300 | |
| 301 | template <class T> |
| 302 | T |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 303 | atomic_load(const atomic<T>* obj) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 304 | |
| 305 | template <class T> |
| 306 | T |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 307 | atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 308 | |
| 309 | template <class T> |
| 310 | T |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 311 | atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 312 | |
| 313 | template <class T> |
| 314 | T |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 315 | atomic_exchange(volatile atomic<T>* obj, T desr) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 316 | |
| 317 | template <class T> |
| 318 | T |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 319 | atomic_exchange(atomic<T>* obj, T desr) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 320 | |
| 321 | template <class T> |
| 322 | T |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 323 | atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 324 | |
| 325 | template <class T> |
| 326 | T |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 327 | atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 328 | |
| 329 | template <class T> |
| 330 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 331 | atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 332 | |
| 333 | template <class T> |
| 334 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 335 | atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 336 | |
| 337 | template <class T> |
| 338 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 339 | atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 340 | |
| 341 | template <class T> |
| 342 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 343 | atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 344 | |
| 345 | template <class T> |
| 346 | bool |
| 347 | atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc, |
| 348 | T desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 349 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 350 | |
| 351 | template <class T> |
| 352 | bool |
| 353 | atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 354 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 355 | |
| 356 | template <class T> |
| 357 | bool |
| 358 | atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj, |
| 359 | T* expc, T desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 360 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 361 | |
| 362 | template <class T> |
| 363 | bool |
| 364 | atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc, |
| 365 | T desr, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 366 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 367 | |
| 368 | template <class Integral> |
| 369 | Integral |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 370 | atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 371 | |
| 372 | template <class Integral> |
| 373 | Integral |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 374 | atomic_fetch_add(atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 375 | |
| 376 | template <class Integral> |
| 377 | Integral |
| 378 | atomic_fetch_add_explicit(volatile atomic<Integral>* obj, Integral op, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 379 | memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 380 | template <class Integral> |
| 381 | Integral |
| 382 | atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 383 | memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 384 | template <class Integral> |
| 385 | Integral |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 386 | atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 387 | |
| 388 | template <class Integral> |
| 389 | Integral |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 390 | atomic_fetch_sub(atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 391 | |
| 392 | template <class Integral> |
| 393 | Integral |
| 394 | atomic_fetch_sub_explicit(volatile atomic<Integral>* obj, Integral op, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 395 | memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 396 | template <class Integral> |
| 397 | Integral |
| 398 | atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 399 | memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 400 | template <class Integral> |
| 401 | Integral |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 402 | atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 403 | |
| 404 | template <class Integral> |
| 405 | Integral |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 406 | atomic_fetch_and(atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 407 | |
| 408 | template <class Integral> |
| 409 | Integral |
| 410 | atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 411 | memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 412 | template <class Integral> |
| 413 | Integral |
| 414 | atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 415 | memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 416 | template <class Integral> |
| 417 | Integral |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 418 | atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 419 | |
| 420 | template <class Integral> |
| 421 | Integral |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 422 | atomic_fetch_or(atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 423 | |
| 424 | template <class Integral> |
| 425 | Integral |
| 426 | atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 427 | memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 428 | template <class Integral> |
| 429 | Integral |
| 430 | atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 431 | memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 432 | template <class Integral> |
| 433 | Integral |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 434 | atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 435 | |
| 436 | template <class Integral> |
| 437 | Integral |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 438 | atomic_fetch_xor(atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 439 | |
| 440 | template <class Integral> |
| 441 | Integral |
| 442 | atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 443 | memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 444 | template <class Integral> |
| 445 | Integral |
| 446 | atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 447 | memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 448 | |
| 449 | template <class T> |
| 450 | T* |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 451 | atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 452 | |
| 453 | template <class T> |
| 454 | T* |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 455 | atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 456 | |
| 457 | template <class T> |
| 458 | T* |
| 459 | atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 460 | memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 461 | template <class T> |
| 462 | T* |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 463 | atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 464 | |
| 465 | template <class T> |
| 466 | T* |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 467 | atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 468 | |
| 469 | template <class T> |
| 470 | T* |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 471 | atomic_fetch_sub(atomic<T*>* obj, ptrdiff_t op) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 472 | |
| 473 | template <class T> |
| 474 | T* |
| 475 | atomic_fetch_sub_explicit(volatile atomic<T*>* obj, ptrdiff_t op, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 476 | memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 477 | template <class T> |
| 478 | T* |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 479 | atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 480 | |
| 481 | // Atomics for standard typedef types |
| 482 | |
Howard Hinnant | f0af8d9 | 2013-01-04 18:58:50 +0000 | [diff] [blame] | 483 | typedef atomic<bool> atomic_bool; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 484 | typedef atomic<char> atomic_char; |
| 485 | typedef atomic<signed char> atomic_schar; |
| 486 | typedef atomic<unsigned char> atomic_uchar; |
| 487 | typedef atomic<short> atomic_short; |
| 488 | typedef atomic<unsigned short> atomic_ushort; |
| 489 | typedef atomic<int> atomic_int; |
| 490 | typedef atomic<unsigned int> atomic_uint; |
| 491 | typedef atomic<long> atomic_long; |
| 492 | typedef atomic<unsigned long> atomic_ulong; |
| 493 | typedef atomic<long long> atomic_llong; |
| 494 | typedef atomic<unsigned long long> atomic_ullong; |
| 495 | typedef atomic<char16_t> atomic_char16_t; |
| 496 | typedef atomic<char32_t> atomic_char32_t; |
| 497 | typedef atomic<wchar_t> atomic_wchar_t; |
| 498 | |
| 499 | typedef atomic<int_least8_t> atomic_int_least8_t; |
| 500 | typedef atomic<uint_least8_t> atomic_uint_least8_t; |
| 501 | typedef atomic<int_least16_t> atomic_int_least16_t; |
| 502 | typedef atomic<uint_least16_t> atomic_uint_least16_t; |
| 503 | typedef atomic<int_least32_t> atomic_int_least32_t; |
| 504 | typedef atomic<uint_least32_t> atomic_uint_least32_t; |
| 505 | typedef atomic<int_least64_t> atomic_int_least64_t; |
| 506 | typedef atomic<uint_least64_t> atomic_uint_least64_t; |
| 507 | |
| 508 | typedef atomic<int_fast8_t> atomic_int_fast8_t; |
| 509 | typedef atomic<uint_fast8_t> atomic_uint_fast8_t; |
| 510 | typedef atomic<int_fast16_t> atomic_int_fast16_t; |
| 511 | typedef atomic<uint_fast16_t> atomic_uint_fast16_t; |
| 512 | typedef atomic<int_fast32_t> atomic_int_fast32_t; |
| 513 | typedef atomic<uint_fast32_t> atomic_uint_fast32_t; |
| 514 | typedef atomic<int_fast64_t> atomic_int_fast64_t; |
| 515 | typedef atomic<uint_fast64_t> atomic_uint_fast64_t; |
| 516 | |
Marshall Clow | f710afc | 2016-06-30 15:28:38 +0000 | [diff] [blame] | 517 | typedef atomic<int8_t> atomic_int8_t; |
| 518 | typedef atomic<uint8_t> atomic_uint8_t; |
| 519 | typedef atomic<int16_t> atomic_int16_t; |
| 520 | typedef atomic<uint16_t> atomic_uint16_t; |
| 521 | typedef atomic<int32_t> atomic_int32_t; |
| 522 | typedef atomic<uint32_t> atomic_uint32_t; |
| 523 | typedef atomic<int64_t> atomic_int64_t; |
| 524 | typedef atomic<uint64_t> atomic_uint64_t; |
| 525 | |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 526 | typedef atomic<intptr_t> atomic_intptr_t; |
| 527 | typedef atomic<uintptr_t> atomic_uintptr_t; |
| 528 | typedef atomic<size_t> atomic_size_t; |
| 529 | typedef atomic<ptrdiff_t> atomic_ptrdiff_t; |
| 530 | typedef atomic<intmax_t> atomic_intmax_t; |
| 531 | typedef atomic<uintmax_t> atomic_uintmax_t; |
| 532 | |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 533 | // fences |
| 534 | |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 535 | void atomic_thread_fence(memory_order m) noexcept; |
| 536 | void atomic_signal_fence(memory_order m) noexcept; |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 537 | |
| 538 | } // std |
| 539 | |
| 540 | */ |
| 541 | |
| 542 | #include <__config> |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 543 | #include <cstddef> |
| 544 | #include <cstdint> |
| 545 | #include <type_traits> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 546 | #include <version> |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 547 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 548 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 549 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 550 | #endif |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 551 | |
Jonathan Roelofs | 39cb6bf | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 552 | #ifdef _LIBCPP_HAS_NO_THREADS |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 553 | # error <atomic> is not supported on this single threaded system |
Eric Fiselier | 8020b6c | 2015-08-19 17:21:46 +0000 | [diff] [blame] | 554 | #endif |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 555 | #ifdef _LIBCPP_HAS_NO_ATOMIC_HEADER |
| 556 | # error <atomic> is not implemented |
Eric Fiselier | 8020b6c | 2015-08-19 17:21:46 +0000 | [diff] [blame] | 557 | #endif |
Volodymyr Sapsai | f3ed1fd | 2018-05-15 22:38:31 +0000 | [diff] [blame] | 558 | #ifdef kill_dependency |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 559 | # error C++ standard library is incompatible with <stdatomic.h> |
Volodymyr Sapsai | f3ed1fd | 2018-05-15 22:38:31 +0000 | [diff] [blame] | 560 | #endif |
Jonathan Roelofs | 39cb6bf | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 561 | |
Eric Fiselier | b5ab51d | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 562 | #define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \ |
| 563 | _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_consume || \ |
| 564 | __m == memory_order_acquire || \ |
| 565 | __m == memory_order_acq_rel, \ |
| 566 | "memory order argument to atomic operation is invalid") |
| 567 | |
| 568 | #define _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) \ |
| 569 | _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || \ |
| 570 | __m == memory_order_acq_rel, \ |
| 571 | "memory order argument to atomic operation is invalid") |
| 572 | |
| 573 | #define _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__m, __f) \ |
| 574 | _LIBCPP_DIAGNOSE_WARNING(__f == memory_order_release || \ |
| 575 | __f == memory_order_acq_rel, \ |
| 576 | "memory order argument to atomic operation is invalid") |
| 577 | |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 578 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 579 | |
Howard Hinnant | dca6e71 | 2010-09-28 17:13:38 +0000 | [diff] [blame] | 580 | typedef enum memory_order |
| 581 | { |
| 582 | memory_order_relaxed, memory_order_consume, memory_order_acquire, |
| 583 | memory_order_release, memory_order_acq_rel, memory_order_seq_cst |
| 584 | } memory_order; |
| 585 | |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 586 | #if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) || \ |
| 587 | defined(_LIBCPP_ATOMIC_ONLY_USE_BUILTINS) |
Eric Fiselier | 88f0712 | 2015-12-15 00:32:21 +0000 | [diff] [blame] | 588 | |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 589 | // [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because |
| 590 | // the default operator= in an object is not volatile, a byte-by-byte copy |
| 591 | // is required. |
| 592 | template <typename _Tp, typename _Tv> _LIBCPP_INLINE_VISIBILITY |
| 593 | typename enable_if<is_assignable<_Tp&, _Tv>::value>::type |
| 594 | __cxx_atomic_assign_volatile(_Tp& __a_value, _Tv const& __val) { |
| 595 | __a_value = __val; |
| 596 | } |
| 597 | template <typename _Tp, typename _Tv> _LIBCPP_INLINE_VISIBILITY |
| 598 | typename enable_if<is_assignable<_Tp&, _Tv>::value>::type |
| 599 | __cxx_atomic_assign_volatile(_Tp volatile& __a_value, _Tv volatile const& __val) { |
| 600 | volatile char* __to = reinterpret_cast<volatile char*>(&__a_value); |
| 601 | volatile char* __end = __to + sizeof(_Tp); |
| 602 | volatile const char* __from = reinterpret_cast<volatile const char*>(&__val); |
| 603 | while (__to != __end) |
| 604 | *__to++ = *__from++; |
| 605 | } |
| 606 | |
Eric Fiselier | 88f0712 | 2015-12-15 00:32:21 +0000 | [diff] [blame] | 607 | #endif |
| 608 | |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 609 | #if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) |
| 610 | |
| 611 | template <typename _Tp> |
| 612 | struct __cxx_atomic_base_impl { |
| 613 | |
Eric Fiselier | 684aaca | 2015-10-14 08:36:22 +0000 | [diff] [blame] | 614 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 07b2b55 | 2016-11-18 06:42:17 +0000 | [diff] [blame] | 615 | #ifndef _LIBCPP_CXX03_LANG |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 616 | __cxx_atomic_base_impl() _NOEXCEPT = default; |
Eric Fiselier | 684aaca | 2015-10-14 08:36:22 +0000 | [diff] [blame] | 617 | #else |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 618 | __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {} |
Eric Fiselier | 07b2b55 | 2016-11-18 06:42:17 +0000 | [diff] [blame] | 619 | #endif // _LIBCPP_CXX03_LANG |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 620 | _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT |
Eric Fiselier | 719e044 | 2015-07-14 17:50:27 +0000 | [diff] [blame] | 621 | : __a_value(value) {} |
Marshall Clow | 290eb3f | 2015-01-11 06:15:59 +0000 | [diff] [blame] | 622 | _Tp __a_value; |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 623 | }; |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 624 | |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 625 | _LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 626 | // Avoid switch statement to make this a constexpr. |
| 627 | return __order == memory_order_relaxed ? __ATOMIC_RELAXED: |
| 628 | (__order == memory_order_acquire ? __ATOMIC_ACQUIRE: |
| 629 | (__order == memory_order_release ? __ATOMIC_RELEASE: |
| 630 | (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST: |
| 631 | (__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL: |
| 632 | __ATOMIC_CONSUME)))); |
| 633 | } |
| 634 | |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 635 | _LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) { |
Dan Albert | 48815f2 | 2015-01-06 18:39:37 +0000 | [diff] [blame] | 636 | // Avoid switch statement to make this a constexpr. |
| 637 | return __order == memory_order_relaxed ? __ATOMIC_RELAXED: |
| 638 | (__order == memory_order_acquire ? __ATOMIC_ACQUIRE: |
| 639 | (__order == memory_order_release ? __ATOMIC_RELAXED: |
| 640 | (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST: |
| 641 | (__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE: |
| 642 | __ATOMIC_CONSUME)))); |
| 643 | } |
| 644 | |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 645 | template <typename _Tp> |
| 646 | _LIBCPP_INLINE_VISIBILITY |
| 647 | void __cxx_atomic_init(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val) { |
| 648 | __cxx_atomic_assign_volatile(__a->__a_value, __val); |
| 649 | } |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 650 | |
| 651 | template <typename _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 652 | _LIBCPP_INLINE_VISIBILITY |
| 653 | void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 654 | __a->__a_value = __val; |
| 655 | } |
| 656 | |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 657 | _LIBCPP_INLINE_VISIBILITY inline |
| 658 | void __cxx_atomic_thread_fence(memory_order __order) { |
| 659 | __atomic_thread_fence(__to_gcc_order(__order)); |
| 660 | } |
| 661 | |
| 662 | _LIBCPP_INLINE_VISIBILITY inline |
| 663 | void __cxx_atomic_signal_fence(memory_order __order) { |
| 664 | __atomic_signal_fence(__to_gcc_order(__order)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | template <typename _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 668 | _LIBCPP_INLINE_VISIBILITY |
| 669 | void __cxx_atomic_store(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val, |
| 670 | memory_order __order) { |
Dan Albert | 48815f2 | 2015-01-06 18:39:37 +0000 | [diff] [blame] | 671 | __atomic_store(&__a->__a_value, &__val, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 672 | __to_gcc_order(__order)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | template <typename _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 676 | _LIBCPP_INLINE_VISIBILITY |
| 677 | void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val, |
| 678 | memory_order __order) { |
| 679 | __atomic_store(&__a->__a_value, &__val, |
| 680 | __to_gcc_order(__order)); |
| 681 | } |
| 682 | |
| 683 | template <typename _Tp> |
| 684 | _LIBCPP_INLINE_VISIBILITY |
| 685 | _Tp __cxx_atomic_load(const volatile __cxx_atomic_base_impl<_Tp>* __a, |
| 686 | memory_order __order) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 687 | _Tp __ret; |
| 688 | __atomic_load(&__a->__a_value, &__ret, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 689 | __to_gcc_order(__order)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 690 | return __ret; |
| 691 | } |
| 692 | |
| 693 | template <typename _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 694 | _LIBCPP_INLINE_VISIBILITY |
| 695 | _Tp __cxx_atomic_load(const __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 696 | _Tp __ret; |
| 697 | __atomic_load(&__a->__a_value, &__ret, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 698 | __to_gcc_order(__order)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 699 | return __ret; |
| 700 | } |
| 701 | |
| 702 | template <typename _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 703 | _LIBCPP_INLINE_VISIBILITY |
| 704 | _Tp __cxx_atomic_exchange(volatile __cxx_atomic_base_impl<_Tp>* __a, |
| 705 | _Tp __value, memory_order __order) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 706 | _Tp __ret; |
| 707 | __atomic_exchange(&__a->__a_value, &__value, &__ret, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 708 | __to_gcc_order(__order)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 709 | return __ret; |
| 710 | } |
| 711 | |
| 712 | template <typename _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 713 | _LIBCPP_INLINE_VISIBILITY |
| 714 | _Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value, |
| 715 | memory_order __order) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 716 | _Tp __ret; |
| 717 | __atomic_exchange(&__a->__a_value, &__value, &__ret, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 718 | __to_gcc_order(__order)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 719 | return __ret; |
| 720 | } |
| 721 | |
| 722 | template <typename _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 723 | _LIBCPP_INLINE_VISIBILITY |
| 724 | bool __cxx_atomic_compare_exchange_strong( |
| 725 | volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, |
JF Bastien | 6e412d9 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 726 | memory_order __success, memory_order __failure) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 727 | return __atomic_compare_exchange(&__a->__a_value, __expected, &__value, |
| 728 | false, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 729 | __to_gcc_order(__success), |
| 730 | __to_gcc_failure_order(__failure)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | template <typename _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 734 | _LIBCPP_INLINE_VISIBILITY |
| 735 | bool __cxx_atomic_compare_exchange_strong( |
| 736 | __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, |
JF Bastien | 6e412d9 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 737 | memory_order __failure) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 738 | return __atomic_compare_exchange(&__a->__a_value, __expected, &__value, |
| 739 | false, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 740 | __to_gcc_order(__success), |
| 741 | __to_gcc_failure_order(__failure)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | template <typename _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 745 | _LIBCPP_INLINE_VISIBILITY |
| 746 | bool __cxx_atomic_compare_exchange_weak( |
| 747 | volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, |
JF Bastien | 6e412d9 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 748 | memory_order __success, memory_order __failure) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 749 | return __atomic_compare_exchange(&__a->__a_value, __expected, &__value, |
| 750 | true, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 751 | __to_gcc_order(__success), |
| 752 | __to_gcc_failure_order(__failure)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | template <typename _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 756 | _LIBCPP_INLINE_VISIBILITY |
| 757 | bool __cxx_atomic_compare_exchange_weak( |
| 758 | __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, |
JF Bastien | 6e412d9 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 759 | memory_order __failure) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 760 | return __atomic_compare_exchange(&__a->__a_value, __expected, &__value, |
| 761 | true, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 762 | __to_gcc_order(__success), |
| 763 | __to_gcc_failure_order(__failure)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | template <typename _Tp> |
| 767 | struct __skip_amt { enum {value = 1}; }; |
| 768 | |
| 769 | template <typename _Tp> |
| 770 | struct __skip_amt<_Tp*> { enum {value = sizeof(_Tp)}; }; |
| 771 | |
| 772 | // FIXME: Haven't figured out what the spec says about using arrays with |
| 773 | // atomic_fetch_add. Force a failure rather than creating bad behavior. |
| 774 | template <typename _Tp> |
| 775 | struct __skip_amt<_Tp[]> { }; |
| 776 | template <typename _Tp, int n> |
| 777 | struct __skip_amt<_Tp[n]> { }; |
| 778 | |
| 779 | template <typename _Tp, typename _Td> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 780 | _LIBCPP_INLINE_VISIBILITY |
| 781 | _Tp __cxx_atomic_fetch_add(volatile __cxx_atomic_base_impl<_Tp>* __a, |
| 782 | _Td __delta, memory_order __order) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 783 | return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 784 | __to_gcc_order(__order)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | template <typename _Tp, typename _Td> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 788 | _LIBCPP_INLINE_VISIBILITY |
| 789 | _Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, |
| 790 | memory_order __order) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 791 | return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 792 | __to_gcc_order(__order)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | template <typename _Tp, typename _Td> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 796 | _LIBCPP_INLINE_VISIBILITY |
| 797 | _Tp __cxx_atomic_fetch_sub(volatile __cxx_atomic_base_impl<_Tp>* __a, |
| 798 | _Td __delta, memory_order __order) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 799 | return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 800 | __to_gcc_order(__order)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | template <typename _Tp, typename _Td> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 804 | _LIBCPP_INLINE_VISIBILITY |
| 805 | _Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, |
| 806 | memory_order __order) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 807 | return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 808 | __to_gcc_order(__order)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | template <typename _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 812 | _LIBCPP_INLINE_VISIBILITY |
| 813 | _Tp __cxx_atomic_fetch_and(volatile __cxx_atomic_base_impl<_Tp>* __a, |
| 814 | _Tp __pattern, memory_order __order) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 815 | return __atomic_fetch_and(&__a->__a_value, __pattern, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 816 | __to_gcc_order(__order)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | template <typename _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 820 | _LIBCPP_INLINE_VISIBILITY |
| 821 | _Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a, |
| 822 | _Tp __pattern, memory_order __order) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 823 | return __atomic_fetch_and(&__a->__a_value, __pattern, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 824 | __to_gcc_order(__order)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | template <typename _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 828 | _LIBCPP_INLINE_VISIBILITY |
| 829 | _Tp __cxx_atomic_fetch_or(volatile __cxx_atomic_base_impl<_Tp>* __a, |
| 830 | _Tp __pattern, memory_order __order) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 831 | return __atomic_fetch_or(&__a->__a_value, __pattern, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 832 | __to_gcc_order(__order)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | template <typename _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 836 | _LIBCPP_INLINE_VISIBILITY |
| 837 | _Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, |
| 838 | memory_order __order) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 839 | return __atomic_fetch_or(&__a->__a_value, __pattern, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 840 | __to_gcc_order(__order)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | template <typename _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 844 | _LIBCPP_INLINE_VISIBILITY |
| 845 | _Tp __cxx_atomic_fetch_xor(volatile __cxx_atomic_base_impl<_Tp>* __a, |
| 846 | _Tp __pattern, memory_order __order) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 847 | return __atomic_fetch_xor(&__a->__a_value, __pattern, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 848 | __to_gcc_order(__order)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | template <typename _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 852 | _LIBCPP_INLINE_VISIBILITY |
| 853 | _Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, |
| 854 | memory_order __order) { |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 855 | return __atomic_fetch_xor(&__a->__a_value, __pattern, |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 856 | __to_gcc_order(__order)); |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 857 | } |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 858 | |
| 859 | #define __cxx_atomic_is_lock_free(__s) __atomic_is_lock_free(__s, 0) |
| 860 | |
| 861 | #elif defined(_LIBCPP_HAS_C_ATOMIC_IMP) |
| 862 | |
| 863 | template <typename _Tp> |
| 864 | struct __cxx_atomic_base_impl { |
| 865 | |
| 866 | _LIBCPP_INLINE_VISIBILITY |
| 867 | #ifndef _LIBCPP_CXX03_LANG |
| 868 | __cxx_atomic_base_impl() _NOEXCEPT = default; |
| 869 | #else |
| 870 | __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {} |
| 871 | #endif // _LIBCPP_CXX03_LANG |
| 872 | _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT |
| 873 | : __a_value(value) {} |
| 874 | _Atomic(_Tp) __a_value; |
| 875 | }; |
| 876 | |
| 877 | #define __cxx_atomic_is_lock_free(__s) __c11_atomic_is_lock_free(__s) |
| 878 | |
| 879 | _LIBCPP_INLINE_VISIBILITY inline |
| 880 | void __cxx_atomic_thread_fence(int __order) { |
| 881 | __c11_atomic_thread_fence(__order); |
| 882 | } |
| 883 | |
| 884 | _LIBCPP_INLINE_VISIBILITY inline |
| 885 | void __cxx_atomic_signal_fence(int __order) { |
| 886 | __c11_atomic_signal_fence(__order); |
| 887 | } |
| 888 | |
| 889 | template<class _Tp> |
| 890 | _LIBCPP_INLINE_VISIBILITY |
| 891 | void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val) { |
| 892 | __c11_atomic_init(&__a->__a_value, __val); |
| 893 | } |
| 894 | template<class _Tp> |
| 895 | _LIBCPP_INLINE_VISIBILITY |
| 896 | void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> * __a, _Tp __val) { |
| 897 | __c11_atomic_init(&__a->__a_value, __val); |
| 898 | } |
| 899 | |
| 900 | template<class _Tp> |
| 901 | _LIBCPP_INLINE_VISIBILITY |
| 902 | void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val, int __order) { |
| 903 | __c11_atomic_store(&__a->__a_value, __val, __order); |
| 904 | } |
| 905 | template<class _Tp> |
| 906 | _LIBCPP_INLINE_VISIBILITY |
| 907 | void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp> * __a, _Tp __val, int __order) { |
| 908 | __c11_atomic_store(&__a->__a_value, __val, __order); |
| 909 | } |
| 910 | |
| 911 | template<class _Tp> |
| 912 | _LIBCPP_INLINE_VISIBILITY |
| 913 | _Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const volatile* __a, int __order) { |
| 914 | using __ptr_type = typename remove_const<decltype(__a->__a_value)>::type*; |
| 915 | return __c11_atomic_load(const_cast<__ptr_type>(&__a->__a_value), __order); |
| 916 | } |
| 917 | template<class _Tp> |
| 918 | _LIBCPP_INLINE_VISIBILITY |
| 919 | _Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const* __a, int __order) { |
| 920 | using __ptr_type = typename remove_const<decltype(__a->__a_value)>::type*; |
| 921 | return __c11_atomic_load(const_cast<__ptr_type>(&__a->__a_value), __order); |
| 922 | } |
| 923 | |
| 924 | template<class _Tp> |
| 925 | _LIBCPP_INLINE_VISIBILITY |
| 926 | _Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __value, int __order) { |
| 927 | return __c11_atomic_exchange(&__a->__a_value, __value, __order); |
| 928 | } |
| 929 | template<class _Tp> |
| 930 | _LIBCPP_INLINE_VISIBILITY |
| 931 | _Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> * __a, _Tp __value, int __order) { |
| 932 | return __c11_atomic_exchange(&__a->__a_value, __value, __order); |
| 933 | } |
| 934 | |
| 935 | template<class _Tp> |
| 936 | _LIBCPP_INLINE_VISIBILITY |
| 937 | bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp* __expected, _Tp __value, int __success, int __failure) { |
| 938 | return __c11_atomic_compare_exchange_strong(&__a->__a_value, __expected, __value, __success, __failure); |
| 939 | } |
| 940 | template<class _Tp> |
| 941 | _LIBCPP_INLINE_VISIBILITY |
| 942 | bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_base_impl<_Tp> * __a, _Tp* __expected, _Tp __value, int __success, int __failure) { |
| 943 | return __c11_atomic_compare_exchange_strong(&__a->__a_value, __expected, __value, __success, __failure); |
| 944 | } |
| 945 | |
| 946 | template<class _Tp> |
| 947 | _LIBCPP_INLINE_VISIBILITY |
| 948 | bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp* __expected, _Tp __value, int __success, int __failure) { |
| 949 | return __c11_atomic_compare_exchange_weak(&__a->__a_value, __expected, __value, __success, __failure); |
| 950 | } |
| 951 | template<class _Tp> |
| 952 | _LIBCPP_INLINE_VISIBILITY |
| 953 | bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_base_impl<_Tp> * __a, _Tp* __expected, _Tp __value, int __success, int __failure) { |
| 954 | return __c11_atomic_compare_exchange_weak(&__a->__a_value, __expected, __value, __success, __failure); |
| 955 | } |
| 956 | |
| 957 | template<class _Tp> |
| 958 | _LIBCPP_INLINE_VISIBILITY |
| 959 | _Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, int __order) { |
| 960 | return __c11_atomic_fetch_add(&__a->__a_value, __delta, __order); |
| 961 | } |
| 962 | template<class _Tp> |
| 963 | _LIBCPP_INLINE_VISIBILITY |
| 964 | _Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> * __a, _Tp __delta, int __order) { |
| 965 | return __c11_atomic_fetch_add(&__a->__a_value, __delta, __order); |
| 966 | } |
| 967 | |
| 968 | template<class _Tp> |
| 969 | _LIBCPP_INLINE_VISIBILITY |
| 970 | _Tp* __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, int __order) { |
| 971 | return __c11_atomic_fetch_add(&__a->__a_value, __delta, __order); |
| 972 | } |
| 973 | template<class _Tp> |
| 974 | _LIBCPP_INLINE_VISIBILITY |
| 975 | _Tp* __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> * __a, ptrdiff_t __delta, int __order) { |
| 976 | return __c11_atomic_fetch_add(&__a->__a_value, __delta, __order); |
| 977 | } |
| 978 | |
| 979 | template<class _Tp> |
| 980 | _LIBCPP_INLINE_VISIBILITY |
| 981 | _Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, int __order) { |
| 982 | return __c11_atomic_fetch_sub(&__a->__a_value, __delta, __order); |
| 983 | } |
| 984 | template<class _Tp> |
| 985 | _LIBCPP_INLINE_VISIBILITY |
| 986 | _Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> * __a, _Tp __delta, int __order) { |
| 987 | return __c11_atomic_fetch_sub(&__a->__a_value, __delta, __order); |
| 988 | } |
| 989 | template<class _Tp> |
| 990 | _LIBCPP_INLINE_VISIBILITY |
| 991 | _Tp* __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, int __order) { |
| 992 | return __c11_atomic_fetch_sub(&__a->__a_value, __delta, __order); |
| 993 | } |
| 994 | template<class _Tp> |
| 995 | _LIBCPP_INLINE_VISIBILITY |
| 996 | _Tp* __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> * __a, ptrdiff_t __delta, int __order) { |
| 997 | return __c11_atomic_fetch_sub(&__a->__a_value, __delta, __order); |
| 998 | } |
| 999 | |
| 1000 | template<class _Tp> |
| 1001 | _LIBCPP_INLINE_VISIBILITY |
| 1002 | _Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, int __order) { |
| 1003 | return __c11_atomic_fetch_and(&__a->__a_value, __pattern, __order); |
| 1004 | } |
| 1005 | template<class _Tp> |
| 1006 | _LIBCPP_INLINE_VISIBILITY |
| 1007 | _Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, int __order) { |
| 1008 | return __c11_atomic_fetch_and(&__a->__a_value, __pattern, __order); |
| 1009 | } |
| 1010 | |
| 1011 | template<class _Tp> |
| 1012 | _LIBCPP_INLINE_VISIBILITY |
| 1013 | _Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, int __order) { |
| 1014 | return __c11_atomic_fetch_or(&__a->__a_value, __pattern, __order); |
| 1015 | } |
| 1016 | template<class _Tp> |
| 1017 | _LIBCPP_INLINE_VISIBILITY |
| 1018 | _Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, int __order) { |
| 1019 | return __c11_atomic_fetch_or(&__a->__a_value, __pattern, __order); |
| 1020 | } |
| 1021 | |
| 1022 | template<class _Tp> |
| 1023 | _LIBCPP_INLINE_VISIBILITY |
| 1024 | _Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, int __order) { |
| 1025 | return __c11_atomic_fetch_xor(&__a->__a_value, __pattern, __order); |
| 1026 | } |
| 1027 | template<class _Tp> |
| 1028 | _LIBCPP_INLINE_VISIBILITY |
| 1029 | _Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, int __order) { |
| 1030 | return __c11_atomic_fetch_xor(&__a->__a_value, __pattern, __order); |
| 1031 | } |
| 1032 | |
| 1033 | #endif // _LIBCPP_HAS_GCC_ATOMIC_IMP, _LIBCPP_HAS_C_ATOMIC_IMP |
Dan Albert | 7b65ace | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 1034 | |
Howard Hinnant | dca6e71 | 2010-09-28 17:13:38 +0000 | [diff] [blame] | 1035 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1036 | _LIBCPP_INLINE_VISIBILITY |
| 1037 | _Tp kill_dependency(_Tp __y) _NOEXCEPT |
Howard Hinnant | dca6e71 | 2010-09-28 17:13:38 +0000 | [diff] [blame] | 1038 | { |
| 1039 | return __y; |
| 1040 | } |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 1041 | |
Eric Fiselier | bed42df | 2017-04-20 23:22:46 +0000 | [diff] [blame] | 1042 | #if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE) |
| 1043 | # define ATOMIC_BOOL_LOCK_FREE __CLANG_ATOMIC_BOOL_LOCK_FREE |
| 1044 | # define ATOMIC_CHAR_LOCK_FREE __CLANG_ATOMIC_CHAR_LOCK_FREE |
| 1045 | # define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE |
| 1046 | # define ATOMIC_CHAR32_T_LOCK_FREE __CLANG_ATOMIC_CHAR32_T_LOCK_FREE |
| 1047 | # define ATOMIC_WCHAR_T_LOCK_FREE __CLANG_ATOMIC_WCHAR_T_LOCK_FREE |
| 1048 | # define ATOMIC_SHORT_LOCK_FREE __CLANG_ATOMIC_SHORT_LOCK_FREE |
| 1049 | # define ATOMIC_INT_LOCK_FREE __CLANG_ATOMIC_INT_LOCK_FREE |
| 1050 | # define ATOMIC_LONG_LOCK_FREE __CLANG_ATOMIC_LONG_LOCK_FREE |
| 1051 | # define ATOMIC_LLONG_LOCK_FREE __CLANG_ATOMIC_LLONG_LOCK_FREE |
| 1052 | # define ATOMIC_POINTER_LOCK_FREE __CLANG_ATOMIC_POINTER_LOCK_FREE |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1053 | #elif defined(__GCC_ATOMIC_BOOL_LOCK_FREE) |
Eric Fiselier | bed42df | 2017-04-20 23:22:46 +0000 | [diff] [blame] | 1054 | # define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE |
| 1055 | # define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE |
| 1056 | # define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE |
| 1057 | # define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE |
| 1058 | # define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE |
| 1059 | # define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE |
| 1060 | # define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE |
| 1061 | # define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE |
| 1062 | # define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE |
| 1063 | # define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE |
| 1064 | #endif |
JF Bastien | fdb42c2 | 2016-03-25 15:48:21 +0000 | [diff] [blame] | 1065 | |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1066 | #ifdef _LIBCPP_ATOMIC_ONLY_USE_BUILTINS |
| 1067 | |
| 1068 | template<typename _Tp> |
| 1069 | struct __cxx_atomic_lock_impl { |
| 1070 | |
| 1071 | _LIBCPP_INLINE_VISIBILITY |
| 1072 | __cxx_atomic_lock_impl() _NOEXCEPT |
| 1073 | : __a_value(), __a_lock(0) {} |
| 1074 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit |
| 1075 | __cxx_atomic_lock_impl(_Tp value) _NOEXCEPT |
| 1076 | : __a_value(value), __a_lock(0) {} |
| 1077 | |
| 1078 | _Tp __a_value; |
| 1079 | mutable __cxx_atomic_base_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_lock; |
| 1080 | |
| 1081 | _LIBCPP_INLINE_VISIBILITY void __lock() const volatile { |
| 1082 | while(1 == __cxx_atomic_exchange(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(true), memory_order_acquire)) |
| 1083 | /*spin*/; |
| 1084 | } |
| 1085 | _LIBCPP_INLINE_VISIBILITY void __lock() const { |
| 1086 | while(1 == __cxx_atomic_exchange(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(true), memory_order_acquire)) |
| 1087 | /*spin*/; |
| 1088 | } |
| 1089 | _LIBCPP_INLINE_VISIBILITY void __unlock() const volatile { |
| 1090 | __cxx_atomic_store(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(false), memory_order_release); |
| 1091 | } |
| 1092 | _LIBCPP_INLINE_VISIBILITY void __unlock() const { |
| 1093 | __cxx_atomic_store(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(false), memory_order_release); |
| 1094 | } |
| 1095 | _LIBCPP_INLINE_VISIBILITY _Tp __read() const volatile { |
| 1096 | __lock(); |
| 1097 | _Tp __old; |
| 1098 | __cxx_atomic_assign_volatile(__old, __a_value); |
| 1099 | __unlock(); |
| 1100 | return __old; |
| 1101 | } |
| 1102 | _LIBCPP_INLINE_VISIBILITY _Tp __read() const { |
| 1103 | __lock(); |
| 1104 | _Tp __old = __a_value; |
| 1105 | __unlock(); |
| 1106 | return __old; |
| 1107 | } |
| 1108 | }; |
| 1109 | |
| 1110 | template <typename _Tp> |
| 1111 | _LIBCPP_INLINE_VISIBILITY |
| 1112 | void __cxx_atomic_init(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __val) { |
| 1113 | __cxx_atomic_assign_volatile(__a->__a_value, __val); |
| 1114 | } |
| 1115 | template <typename _Tp> |
| 1116 | _LIBCPP_INLINE_VISIBILITY |
| 1117 | void __cxx_atomic_init(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __val) { |
| 1118 | __a->__a_value = __val; |
| 1119 | } |
| 1120 | |
| 1121 | template <typename _Tp> |
| 1122 | _LIBCPP_INLINE_VISIBILITY |
| 1123 | void __cxx_atomic_store(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __val, memory_order) { |
| 1124 | __a->__lock(); |
| 1125 | __cxx_atomic_assign_volatile(__a->__a_value, __val); |
| 1126 | __a->__unlock(); |
| 1127 | } |
| 1128 | template <typename _Tp> |
| 1129 | _LIBCPP_INLINE_VISIBILITY |
| 1130 | void __cxx_atomic_store(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __val, memory_order) { |
| 1131 | __a->__lock(); |
| 1132 | __a->__a_value = __val; |
| 1133 | __a->__unlock(); |
| 1134 | } |
| 1135 | |
| 1136 | template <typename _Tp> |
| 1137 | _LIBCPP_INLINE_VISIBILITY |
| 1138 | _Tp __cxx_atomic_load(const volatile __cxx_atomic_lock_impl<_Tp>* __a, memory_order) { |
| 1139 | return __a->__read(); |
| 1140 | } |
| 1141 | template <typename _Tp> |
| 1142 | _LIBCPP_INLINE_VISIBILITY |
| 1143 | _Tp __cxx_atomic_load(const __cxx_atomic_lock_impl<_Tp>* __a, memory_order) { |
| 1144 | return __a->__read(); |
| 1145 | } |
| 1146 | |
| 1147 | template <typename _Tp> |
| 1148 | _LIBCPP_INLINE_VISIBILITY |
| 1149 | _Tp __cxx_atomic_exchange(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __value, memory_order) { |
| 1150 | __a->__lock(); |
| 1151 | _Tp __old; |
| 1152 | __cxx_atomic_assign_volatile(__old, __a->__a_value); |
| 1153 | __cxx_atomic_assign_volatile(__a->__a_value, __value); |
| 1154 | __a->__unlock(); |
| 1155 | return __old; |
| 1156 | } |
| 1157 | template <typename _Tp> |
| 1158 | _LIBCPP_INLINE_VISIBILITY |
| 1159 | _Tp __cxx_atomic_exchange(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __value, memory_order) { |
| 1160 | __a->__lock(); |
| 1161 | _Tp __old = __a->__a_value; |
| 1162 | __a->__a_value = __value; |
| 1163 | __a->__unlock(); |
| 1164 | return __old; |
| 1165 | } |
| 1166 | |
| 1167 | template <typename _Tp> |
| 1168 | _LIBCPP_INLINE_VISIBILITY |
| 1169 | bool __cxx_atomic_compare_exchange_strong(volatile __cxx_atomic_lock_impl<_Tp>* __a, |
| 1170 | _Tp* __expected, _Tp __value, memory_order, memory_order) { |
| 1171 | __a->__lock(); |
| 1172 | _Tp temp; |
| 1173 | __cxx_atomic_assign_volatile(temp, __a->__a_value); |
| 1174 | bool __ret = temp == *__expected; |
| 1175 | if(__ret) |
| 1176 | __cxx_atomic_assign_volatile(__a->__a_value, __value); |
| 1177 | else |
| 1178 | __cxx_atomic_assign_volatile(*__expected, __a->__a_value); |
| 1179 | __a->__unlock(); |
| 1180 | return __ret; |
| 1181 | } |
| 1182 | template <typename _Tp> |
| 1183 | _LIBCPP_INLINE_VISIBILITY |
| 1184 | bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_lock_impl<_Tp>* __a, |
| 1185 | _Tp* __expected, _Tp __value, memory_order, memory_order) { |
| 1186 | __a->__lock(); |
| 1187 | bool __ret = __a->__a_value == *__expected; |
| 1188 | if(__ret) |
| 1189 | __a->__a_value = __value; |
| 1190 | else |
| 1191 | *__expected = __a->__a_value; |
| 1192 | __a->__unlock(); |
| 1193 | return __ret; |
| 1194 | } |
| 1195 | |
| 1196 | template <typename _Tp> |
| 1197 | _LIBCPP_INLINE_VISIBILITY |
| 1198 | bool __cxx_atomic_compare_exchange_weak(volatile __cxx_atomic_lock_impl<_Tp>* __a, |
| 1199 | _Tp* __expected, _Tp __value, memory_order, memory_order) { |
| 1200 | __a->__lock(); |
| 1201 | _Tp temp; |
| 1202 | __cxx_atomic_assign_volatile(temp, __a->__a_value); |
| 1203 | bool __ret = temp == *__expected; |
| 1204 | if(__ret) |
| 1205 | __cxx_atomic_assign_volatile(__a->__a_value, __value); |
| 1206 | else |
| 1207 | __cxx_atomic_assign_volatile(*__expected, __a->__a_value); |
| 1208 | __a->__unlock(); |
| 1209 | return __ret; |
| 1210 | } |
| 1211 | template <typename _Tp> |
| 1212 | _LIBCPP_INLINE_VISIBILITY |
| 1213 | bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_lock_impl<_Tp>* __a, |
| 1214 | _Tp* __expected, _Tp __value, memory_order, memory_order) { |
| 1215 | __a->__lock(); |
| 1216 | bool __ret = __a->__a_value == *__expected; |
| 1217 | if(__ret) |
| 1218 | __a->__a_value = __value; |
| 1219 | else |
| 1220 | *__expected = __a->__a_value; |
| 1221 | __a->__unlock(); |
| 1222 | return __ret; |
| 1223 | } |
| 1224 | |
| 1225 | template <typename _Tp, typename _Td> |
| 1226 | _LIBCPP_INLINE_VISIBILITY |
| 1227 | _Tp __cxx_atomic_fetch_add(volatile __cxx_atomic_lock_impl<_Tp>* __a, |
| 1228 | _Td __delta, memory_order) { |
| 1229 | __a->__lock(); |
| 1230 | _Tp __old; |
| 1231 | __cxx_atomic_assign_volatile(__old, __a->__a_value); |
| 1232 | __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old + __delta)); |
| 1233 | __a->__unlock(); |
| 1234 | return __old; |
| 1235 | } |
| 1236 | template <typename _Tp, typename _Td> |
| 1237 | _LIBCPP_INLINE_VISIBILITY |
| 1238 | _Tp __cxx_atomic_fetch_add(__cxx_atomic_lock_impl<_Tp>* __a, |
| 1239 | _Td __delta, memory_order) { |
| 1240 | __a->__lock(); |
| 1241 | _Tp __old = __a->__a_value; |
| 1242 | __a->__a_value += __delta; |
| 1243 | __a->__unlock(); |
| 1244 | return __old; |
| 1245 | } |
| 1246 | |
| 1247 | template <typename _Tp, typename _Td> |
| 1248 | _LIBCPP_INLINE_VISIBILITY |
| 1249 | _Tp* __cxx_atomic_fetch_add(volatile __cxx_atomic_lock_impl<_Tp*>* __a, |
| 1250 | ptrdiff_t __delta, memory_order) { |
| 1251 | __a->__lock(); |
| 1252 | _Tp* __old; |
| 1253 | __cxx_atomic_assign_volatile(__old, __a->__a_value); |
| 1254 | __cxx_atomic_assign_volatile(__a->__a_value, __old + __delta); |
| 1255 | __a->__unlock(); |
| 1256 | return __old; |
| 1257 | } |
| 1258 | template <typename _Tp, typename _Td> |
| 1259 | _LIBCPP_INLINE_VISIBILITY |
| 1260 | _Tp* __cxx_atomic_fetch_add(__cxx_atomic_lock_impl<_Tp*>* __a, |
| 1261 | ptrdiff_t __delta, memory_order) { |
| 1262 | __a->__lock(); |
| 1263 | _Tp* __old = __a->__a_value; |
| 1264 | __a->__a_value += __delta; |
| 1265 | __a->__unlock(); |
| 1266 | return __old; |
| 1267 | } |
| 1268 | |
| 1269 | template <typename _Tp, typename _Td> |
| 1270 | _LIBCPP_INLINE_VISIBILITY |
| 1271 | _Tp __cxx_atomic_fetch_sub(volatile __cxx_atomic_lock_impl<_Tp>* __a, |
| 1272 | _Td __delta, memory_order) { |
| 1273 | __a->__lock(); |
| 1274 | _Tp __old; |
| 1275 | __cxx_atomic_assign_volatile(__old, __a->__a_value); |
| 1276 | __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old - __delta)); |
| 1277 | __a->__unlock(); |
| 1278 | return __old; |
| 1279 | } |
| 1280 | template <typename _Tp, typename _Td> |
| 1281 | _LIBCPP_INLINE_VISIBILITY |
| 1282 | _Tp __cxx_atomic_fetch_sub(__cxx_atomic_lock_impl<_Tp>* __a, |
| 1283 | _Td __delta, memory_order) { |
| 1284 | __a->__lock(); |
| 1285 | _Tp __old = __a->__a_value; |
| 1286 | __a->__a_value -= __delta; |
| 1287 | __a->__unlock(); |
| 1288 | return __old; |
| 1289 | } |
| 1290 | |
| 1291 | template <typename _Tp> |
| 1292 | _LIBCPP_INLINE_VISIBILITY |
| 1293 | _Tp __cxx_atomic_fetch_and(volatile __cxx_atomic_lock_impl<_Tp>* __a, |
| 1294 | _Tp __pattern, memory_order) { |
| 1295 | __a->__lock(); |
| 1296 | _Tp __old; |
| 1297 | __cxx_atomic_assign_volatile(__old, __a->__a_value); |
| 1298 | __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old & __pattern)); |
| 1299 | __a->__unlock(); |
| 1300 | return __old; |
| 1301 | } |
| 1302 | template <typename _Tp> |
| 1303 | _LIBCPP_INLINE_VISIBILITY |
| 1304 | _Tp __cxx_atomic_fetch_and(__cxx_atomic_lock_impl<_Tp>* __a, |
| 1305 | _Tp __pattern, memory_order) { |
| 1306 | __a->__lock(); |
| 1307 | _Tp __old = __a->__a_value; |
| 1308 | __a->__a_value &= __pattern; |
| 1309 | __a->__unlock(); |
| 1310 | return __old; |
| 1311 | } |
| 1312 | |
| 1313 | template <typename _Tp> |
| 1314 | _LIBCPP_INLINE_VISIBILITY |
| 1315 | _Tp __cxx_atomic_fetch_or(volatile __cxx_atomic_lock_impl<_Tp>* __a, |
| 1316 | _Tp __pattern, memory_order) { |
| 1317 | __a->__lock(); |
| 1318 | _Tp __old; |
| 1319 | __cxx_atomic_assign_volatile(__old, __a->__a_value); |
| 1320 | __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old | __pattern)); |
| 1321 | __a->__unlock(); |
| 1322 | return __old; |
| 1323 | } |
| 1324 | template <typename _Tp> |
| 1325 | _LIBCPP_INLINE_VISIBILITY |
| 1326 | _Tp __cxx_atomic_fetch_or(__cxx_atomic_lock_impl<_Tp>* __a, |
| 1327 | _Tp __pattern, memory_order) { |
| 1328 | __a->__lock(); |
| 1329 | _Tp __old = __a->__a_value; |
| 1330 | __a->__a_value |= __pattern; |
| 1331 | __a->__unlock(); |
| 1332 | return __old; |
| 1333 | } |
| 1334 | |
| 1335 | template <typename _Tp> |
| 1336 | _LIBCPP_INLINE_VISIBILITY |
| 1337 | _Tp __cxx_atomic_fetch_xor(volatile __cxx_atomic_lock_impl<_Tp>* __a, |
| 1338 | _Tp __pattern, memory_order) { |
| 1339 | __a->__lock(); |
| 1340 | _Tp __old; |
| 1341 | __cxx_atomic_assign_volatile(__old, __a->__a_value); |
| 1342 | __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old ^ __pattern)); |
| 1343 | __a->__unlock(); |
| 1344 | return __old; |
| 1345 | } |
| 1346 | template <typename _Tp> |
| 1347 | _LIBCPP_INLINE_VISIBILITY |
| 1348 | _Tp __cxx_atomic_fetch_xor(__cxx_atomic_lock_impl<_Tp>* __a, |
| 1349 | _Tp __pattern, memory_order) { |
| 1350 | __a->__lock(); |
| 1351 | _Tp __old = __a->__a_value; |
| 1352 | __a->__a_value ^= __pattern; |
| 1353 | __a->__unlock(); |
| 1354 | return __old; |
| 1355 | } |
| 1356 | |
| 1357 | #ifdef __cpp_lib_atomic_is_always_lock_free |
| 1358 | |
| 1359 | template<typename _Tp> struct __cxx_is_always_lock_free { |
| 1360 | enum { __value = __atomic_always_lock_free(sizeof(_Tp), 0) }; }; |
| 1361 | |
| 1362 | #else |
| 1363 | |
| 1364 | template<typename _Tp> struct __cxx_is_always_lock_free { enum { __value = false }; }; |
| 1365 | // Implementations must match the C ATOMIC_*_LOCK_FREE macro values. |
| 1366 | template<> struct __cxx_is_always_lock_free<bool> { enum { __value = 2 == ATOMIC_BOOL_LOCK_FREE }; }; |
| 1367 | template<> struct __cxx_is_always_lock_free<char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; }; |
| 1368 | template<> struct __cxx_is_always_lock_free<signed char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; }; |
| 1369 | template<> struct __cxx_is_always_lock_free<unsigned char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; }; |
| 1370 | template<> struct __cxx_is_always_lock_free<char16_t> { enum { __value = 2 == ATOMIC_CHAR16_T_LOCK_FREE }; }; |
| 1371 | template<> struct __cxx_is_always_lock_free<char32_t> { enum { __value = 2 == ATOMIC_CHAR32_T_LOCK_FREE }; }; |
| 1372 | template<> struct __cxx_is_always_lock_free<wchar_t> { enum { __value = 2 == ATOMIC_WCHAR_T_LOCK_FREE }; }; |
| 1373 | template<> struct __cxx_is_always_lock_free<short> { enum { __value = 2 == ATOMIC_SHORT_LOCK_FREE }; }; |
| 1374 | template<> struct __cxx_is_always_lock_free<unsigned short> { enum { __value = 2 == ATOMIC_SHORT_LOCK_FREE }; }; |
| 1375 | template<> struct __cxx_is_always_lock_free<int> { enum { __value = 2 == ATOMIC_INT_LOCK_FREE }; }; |
| 1376 | template<> struct __cxx_is_always_lock_free<unsigned int> { enum { __value = 2 == ATOMIC_INT_LOCK_FREE }; }; |
| 1377 | template<> struct __cxx_is_always_lock_free<long> { enum { __value = 2 == ATOMIC_LONG_LOCK_FREE }; }; |
| 1378 | template<> struct __cxx_is_always_lock_free<unsigned long> { enum { __value = 2 == ATOMIC_LONG_LOCK_FREE }; }; |
| 1379 | template<> struct __cxx_is_always_lock_free<long long> { enum { __value = 2 == ATOMIC_LLONG_LOCK_FREE }; }; |
| 1380 | template<> struct __cxx_is_always_lock_free<unsigned long long> { enum { __value = 2 == ATOMIC_LLONG_LOCK_FREE }; }; |
| 1381 | template<typename _Tp> struct __cxx_is_always_lock_free<_Tp*> { enum { __value = 2 == ATOMIC_POINTER_LOCK_FREE }; }; |
| 1382 | template<> struct __cxx_is_always_lock_free<std::nullptr_t> { enum { __value = 2 == ATOMIC_POINTER_LOCK_FREE }; }; |
| 1383 | |
| 1384 | #endif //__cpp_lib_atomic_is_always_lock_free |
| 1385 | |
| 1386 | template <typename _Tp, |
| 1387 | typename _Base = typename conditional<__cxx_is_always_lock_free<_Tp>::__value, |
| 1388 | __cxx_atomic_base_impl<_Tp>, |
| 1389 | __cxx_atomic_lock_impl<_Tp> >::type> |
| 1390 | #else |
| 1391 | template <typename _Tp, |
| 1392 | typename _Base = __cxx_atomic_base_impl<_Tp> > |
| 1393 | #endif //_LIBCPP_ATOMIC_ONLY_USE_BUILTINS |
| 1394 | struct __cxx_atomic_impl : public _Base { |
| 1395 | |
| 1396 | #if _GNUC_VER >= 501 |
| 1397 | static_assert(is_trivially_copyable<_Tp>::value, |
| 1398 | "std::atomic<Tp> requires that 'Tp' be a trivially copyable type"); |
| 1399 | #endif |
| 1400 | |
| 1401 | _LIBCPP_INLINE_VISIBILITY __cxx_atomic_impl() _NOEXCEPT _LIBCPP_DEFAULT |
| 1402 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp value) _NOEXCEPT |
| 1403 | : _Base(value) {} |
| 1404 | }; |
| 1405 | |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1406 | // general atomic<T> |
| 1407 | |
| 1408 | template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value> |
| 1409 | struct __atomic_base // false |
| 1410 | { |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1411 | mutable __cxx_atomic_impl<_Tp> __a_; |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1412 | |
JF Bastien | fdb42c2 | 2016-03-25 15:48:21 +0000 | [diff] [blame] | 1413 | #if defined(__cpp_lib_atomic_is_always_lock_free) |
| 1414 | static _LIBCPP_CONSTEXPR bool is_always_lock_free = __atomic_always_lock_free(sizeof(__a_), 0); |
| 1415 | #endif |
| 1416 | |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1417 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1418 | bool is_lock_free() const volatile _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1419 | {return __cxx_atomic_is_lock_free(sizeof(_Tp));} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1420 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1421 | bool is_lock_free() const _NOEXCEPT |
Eric Fiselier | 3fd22c2 | 2015-06-13 00:23:07 +0000 | [diff] [blame] | 1422 | {return static_cast<__atomic_base const volatile*>(this)->is_lock_free();} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1423 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1424 | void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Eric Fiselier | b5ab51d | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1425 | _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1426 | {__cxx_atomic_store(&__a_, __d, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1427 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1428 | void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Eric Fiselier | b5ab51d | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1429 | _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1430 | {__cxx_atomic_store(&__a_, __d, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1431 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1432 | _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT |
Eric Fiselier | b5ab51d | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1433 | _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1434 | {return __cxx_atomic_load(&__a_, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1435 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1436 | _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT |
Eric Fiselier | b5ab51d | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1437 | _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1438 | {return __cxx_atomic_load(&__a_, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1439 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1440 | operator _Tp() const volatile _NOEXCEPT {return load();} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1441 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1442 | operator _Tp() const _NOEXCEPT {return load();} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1443 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1444 | _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1445 | {return __cxx_atomic_exchange(&__a_, __d, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1446 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1447 | _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1448 | {return __cxx_atomic_exchange(&__a_, __d, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1449 | _LIBCPP_INLINE_VISIBILITY |
| 1450 | bool compare_exchange_weak(_Tp& __e, _Tp __d, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1451 | memory_order __s, memory_order __f) volatile _NOEXCEPT |
Eric Fiselier | b5ab51d | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1452 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1453 | {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1454 | _LIBCPP_INLINE_VISIBILITY |
| 1455 | bool compare_exchange_weak(_Tp& __e, _Tp __d, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1456 | memory_order __s, memory_order __f) _NOEXCEPT |
Eric Fiselier | b5ab51d | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1457 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1458 | {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1459 | _LIBCPP_INLINE_VISIBILITY |
| 1460 | bool compare_exchange_strong(_Tp& __e, _Tp __d, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1461 | memory_order __s, memory_order __f) volatile _NOEXCEPT |
Eric Fiselier | b5ab51d | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1462 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1463 | {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1464 | _LIBCPP_INLINE_VISIBILITY |
| 1465 | bool compare_exchange_strong(_Tp& __e, _Tp __d, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1466 | memory_order __s, memory_order __f) _NOEXCEPT |
Eric Fiselier | b5ab51d | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1467 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1468 | {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1469 | _LIBCPP_INLINE_VISIBILITY |
| 1470 | bool compare_exchange_weak(_Tp& __e, _Tp __d, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1471 | memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1472 | {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1473 | _LIBCPP_INLINE_VISIBILITY |
| 1474 | bool compare_exchange_weak(_Tp& __e, _Tp __d, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1475 | memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1476 | {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1477 | _LIBCPP_INLINE_VISIBILITY |
| 1478 | bool compare_exchange_strong(_Tp& __e, _Tp __d, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1479 | memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1480 | {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1481 | _LIBCPP_INLINE_VISIBILITY |
| 1482 | bool compare_exchange_strong(_Tp& __e, _Tp __d, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1483 | memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1484 | {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1485 | |
| 1486 | _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1487 | __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT |
Howard Hinnant | 3d28422 | 2013-05-02 20:18:43 +0000 | [diff] [blame] | 1488 | |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1489 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 1490 | __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {} |
| 1491 | |
Eric Fiselier | 2d8515f | 2017-01-06 20:58:25 +0000 | [diff] [blame] | 1492 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1493 | __atomic_base(const __atomic_base&) = delete; |
| 1494 | __atomic_base& operator=(const __atomic_base&) = delete; |
| 1495 | __atomic_base& operator=(const __atomic_base&) volatile = delete; |
Eric Fiselier | 2d8515f | 2017-01-06 20:58:25 +0000 | [diff] [blame] | 1496 | #else |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1497 | private: |
| 1498 | __atomic_base(const __atomic_base&); |
| 1499 | __atomic_base& operator=(const __atomic_base&); |
| 1500 | __atomic_base& operator=(const __atomic_base&) volatile; |
Eric Fiselier | 2d8515f | 2017-01-06 20:58:25 +0000 | [diff] [blame] | 1501 | #endif |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1502 | }; |
| 1503 | |
JF Bastien | fdb42c2 | 2016-03-25 15:48:21 +0000 | [diff] [blame] | 1504 | #if defined(__cpp_lib_atomic_is_always_lock_free) |
| 1505 | template <class _Tp, bool __b> |
| 1506 | _LIBCPP_CONSTEXPR bool __atomic_base<_Tp, __b>::is_always_lock_free; |
| 1507 | #endif |
| 1508 | |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1509 | // atomic<Integral> |
| 1510 | |
| 1511 | template <class _Tp> |
| 1512 | struct __atomic_base<_Tp, true> |
| 1513 | : public __atomic_base<_Tp, false> |
| 1514 | { |
| 1515 | typedef __atomic_base<_Tp, false> __base; |
| 1516 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3d28422 | 2013-05-02 20:18:43 +0000 | [diff] [blame] | 1517 | __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1518 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1519 | _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1520 | |
| 1521 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1522 | _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1523 | {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1524 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1525 | _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1526 | {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1527 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1528 | _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1529 | {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1530 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1531 | _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1532 | {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1533 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1534 | _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1535 | {return __cxx_atomic_fetch_and(&this->__a_, __op, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1536 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1537 | _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1538 | {return __cxx_atomic_fetch_and(&this->__a_, __op, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1539 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1540 | _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1541 | {return __cxx_atomic_fetch_or(&this->__a_, __op, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1542 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1543 | _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1544 | {return __cxx_atomic_fetch_or(&this->__a_, __op, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1545 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1546 | _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1547 | {return __cxx_atomic_fetch_xor(&this->__a_, __op, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1548 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1549 | _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1550 | {return __cxx_atomic_fetch_xor(&this->__a_, __op, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1551 | |
| 1552 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1553 | _Tp operator++(int) volatile _NOEXCEPT {return fetch_add(_Tp(1));} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1554 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1555 | _Tp operator++(int) _NOEXCEPT {return fetch_add(_Tp(1));} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1556 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1557 | _Tp operator--(int) volatile _NOEXCEPT {return fetch_sub(_Tp(1));} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1558 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1559 | _Tp operator--(int) _NOEXCEPT {return fetch_sub(_Tp(1));} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1560 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1561 | _Tp operator++() volatile _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1562 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1563 | _Tp operator++() _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1564 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1565 | _Tp operator--() volatile _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1566 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1567 | _Tp operator--() _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1568 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1569 | _Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1570 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1571 | _Tp operator+=(_Tp __op) _NOEXCEPT {return fetch_add(__op) + __op;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1572 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1573 | _Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1574 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1575 | _Tp operator-=(_Tp __op) _NOEXCEPT {return fetch_sub(__op) - __op;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1576 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1577 | _Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1578 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1579 | _Tp operator&=(_Tp __op) _NOEXCEPT {return fetch_and(__op) & __op;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1580 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1581 | _Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1582 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1583 | _Tp operator|=(_Tp __op) _NOEXCEPT {return fetch_or(__op) | __op;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1584 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1585 | _Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1586 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1587 | _Tp operator^=(_Tp __op) _NOEXCEPT {return fetch_xor(__op) ^ __op;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1588 | }; |
| 1589 | |
| 1590 | // atomic<T> |
| 1591 | |
| 1592 | template <class _Tp> |
| 1593 | struct atomic |
| 1594 | : public __atomic_base<_Tp> |
| 1595 | { |
| 1596 | typedef __atomic_base<_Tp> __base; |
| 1597 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3d28422 | 2013-05-02 20:18:43 +0000 | [diff] [blame] | 1598 | atomic() _NOEXCEPT _LIBCPP_DEFAULT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1599 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1600 | _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {} |
Howard Hinnant | 96e4cd6 | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 1601 | |
| 1602 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1603 | _Tp operator=(_Tp __d) volatile _NOEXCEPT |
Howard Hinnant | 96e4cd6 | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 1604 | {__base::store(__d); return __d;} |
| 1605 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1606 | _Tp operator=(_Tp __d) _NOEXCEPT |
Howard Hinnant | 96e4cd6 | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 1607 | {__base::store(__d); return __d;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1608 | }; |
| 1609 | |
| 1610 | // atomic<T*> |
| 1611 | |
| 1612 | template <class _Tp> |
| 1613 | struct atomic<_Tp*> |
| 1614 | : public __atomic_base<_Tp*> |
| 1615 | { |
Howard Hinnant | 96e4cd6 | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 1616 | typedef __atomic_base<_Tp*> __base; |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1617 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3d28422 | 2013-05-02 20:18:43 +0000 | [diff] [blame] | 1618 | atomic() _NOEXCEPT _LIBCPP_DEFAULT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1619 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1620 | _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1621 | |
| 1622 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1623 | _Tp* operator=(_Tp* __d) volatile _NOEXCEPT |
Howard Hinnant | 96e4cd6 | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 1624 | {__base::store(__d); return __d;} |
| 1625 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1626 | _Tp* operator=(_Tp* __d) _NOEXCEPT |
Howard Hinnant | 96e4cd6 | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 1627 | {__base::store(__d); return __d;} |
| 1628 | |
| 1629 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1630 | _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1631 | volatile _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1632 | {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1633 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1634 | _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1635 | {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1636 | _LIBCPP_INLINE_VISIBILITY |
| 1637 | _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1638 | volatile _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1639 | {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1640 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1641 | _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1642 | {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1643 | |
| 1644 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1645 | _Tp* operator++(int) volatile _NOEXCEPT {return fetch_add(1);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1646 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1647 | _Tp* operator++(int) _NOEXCEPT {return fetch_add(1);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1648 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1649 | _Tp* operator--(int) volatile _NOEXCEPT {return fetch_sub(1);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1650 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1651 | _Tp* operator--(int) _NOEXCEPT {return fetch_sub(1);} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1652 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1653 | _Tp* operator++() volatile _NOEXCEPT {return fetch_add(1) + 1;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1654 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1655 | _Tp* operator++() _NOEXCEPT {return fetch_add(1) + 1;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1656 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1657 | _Tp* operator--() volatile _NOEXCEPT {return fetch_sub(1) - 1;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1658 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1659 | _Tp* operator--() _NOEXCEPT {return fetch_sub(1) - 1;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1660 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1661 | _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1662 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1663 | _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT {return fetch_add(__op) + __op;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1664 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1665 | _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1666 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1667 | _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT {return fetch_sub(__op) - __op;} |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1668 | }; |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1669 | |
| 1670 | // atomic_is_lock_free |
| 1671 | |
| 1672 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1673 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1674 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1675 | atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1676 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1677 | return __o->is_lock_free(); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1681 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1682 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1683 | atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1684 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1685 | return __o->is_lock_free(); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | // atomic_init |
| 1689 | |
| 1690 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1691 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1692 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1693 | atomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1694 | { |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1695 | __cxx_atomic_init(&__o->__a_, __d); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1699 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1700 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1701 | atomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1702 | { |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1703 | __cxx_atomic_init(&__o->__a_, __d); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | // atomic_store |
| 1707 | |
| 1708 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1709 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1710 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1711 | atomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1712 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1713 | __o->store(__d); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1717 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1718 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1719 | atomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1720 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1721 | __o->store(__d); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | // atomic_store_explicit |
| 1725 | |
| 1726 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1727 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1728 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1729 | atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT |
Eric Fiselier | b5ab51d | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1730 | _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1731 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1732 | __o->store(__d, __m); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1736 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1737 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1738 | atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT |
Eric Fiselier | b5ab51d | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1739 | _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1740 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1741 | __o->store(__d, __m); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | // atomic_load |
| 1745 | |
| 1746 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1747 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1748 | _Tp |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1749 | atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1750 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1751 | return __o->load(); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1755 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1756 | _Tp |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1757 | atomic_load(const atomic<_Tp>* __o) _NOEXCEPT |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1758 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1759 | return __o->load(); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1760 | } |
| 1761 | |
| 1762 | // atomic_load_explicit |
| 1763 | |
| 1764 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1765 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1766 | _Tp |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1767 | atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT |
Eric Fiselier | b5ab51d | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1768 | _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1769 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1770 | return __o->load(__m); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1774 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1775 | _Tp |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1776 | atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT |
Eric Fiselier | b5ab51d | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1777 | _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1778 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1779 | return __o->load(__m); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | // atomic_exchange |
| 1783 | |
| 1784 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1785 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1786 | _Tp |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1787 | atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1788 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1789 | return __o->exchange(__d); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1793 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1794 | _Tp |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1795 | atomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1796 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1797 | return __o->exchange(__d); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | // atomic_exchange_explicit |
| 1801 | |
| 1802 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1803 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1804 | _Tp |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1805 | atomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1806 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1807 | return __o->exchange(__d, __m); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1811 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1812 | _Tp |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1813 | atomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1814 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1815 | return __o->exchange(__d, __m); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | // atomic_compare_exchange_weak |
| 1819 | |
| 1820 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1821 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1822 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1823 | atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1824 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1825 | return __o->compare_exchange_weak(*__e, __d); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1829 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1830 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1831 | atomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1832 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1833 | return __o->compare_exchange_weak(*__e, __d); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | // atomic_compare_exchange_strong |
| 1837 | |
| 1838 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1839 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1840 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1841 | atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1842 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1843 | return __o->compare_exchange_strong(*__e, __d); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1847 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1848 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1849 | atomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1850 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1851 | return __o->compare_exchange_strong(*__e, __d); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1852 | } |
| 1853 | |
| 1854 | // atomic_compare_exchange_weak_explicit |
| 1855 | |
| 1856 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1857 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1858 | bool |
| 1859 | atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e, |
| 1860 | _Tp __d, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1861 | memory_order __s, memory_order __f) _NOEXCEPT |
Eric Fiselier | b5ab51d | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1862 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1863 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1864 | return __o->compare_exchange_weak(*__e, __d, __s, __f); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1865 | } |
| 1866 | |
| 1867 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1868 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1869 | bool |
| 1870 | atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1871 | memory_order __s, memory_order __f) _NOEXCEPT |
Eric Fiselier | b5ab51d | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1872 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1873 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1874 | return __o->compare_exchange_weak(*__e, __d, __s, __f); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | // atomic_compare_exchange_strong_explicit |
| 1878 | |
| 1879 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1880 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1881 | bool |
| 1882 | atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o, |
| 1883 | _Tp* __e, _Tp __d, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1884 | memory_order __s, memory_order __f) _NOEXCEPT |
Eric Fiselier | b5ab51d | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1885 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1886 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1887 | return __o->compare_exchange_strong(*__e, __d, __s, __f); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1891 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1892 | bool |
| 1893 | atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e, |
| 1894 | _Tp __d, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1895 | memory_order __s, memory_order __f) _NOEXCEPT |
Eric Fiselier | b5ab51d | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1896 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1897 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1898 | return __o->compare_exchange_strong(*__e, __d, __s, __f); |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1899 | } |
| 1900 | |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1901 | // atomic_fetch_add |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1902 | |
| 1903 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1904 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1905 | typename enable_if |
| 1906 | < |
| 1907 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1908 | _Tp |
| 1909 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1910 | atomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1911 | { |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1912 | return __o->fetch_add(__op); |
| 1913 | } |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1914 | |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1915 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1916 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1917 | typename enable_if |
| 1918 | < |
| 1919 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1920 | _Tp |
| 1921 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1922 | atomic_fetch_add(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1923 | { |
| 1924 | return __o->fetch_add(__op); |
| 1925 | } |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1926 | |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1927 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1928 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1929 | _Tp* |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1930 | atomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1931 | { |
| 1932 | return __o->fetch_add(__op); |
| 1933 | } |
| 1934 | |
| 1935 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1936 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1937 | _Tp* |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1938 | atomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1939 | { |
| 1940 | return __o->fetch_add(__op); |
| 1941 | } |
| 1942 | |
| 1943 | // atomic_fetch_add_explicit |
| 1944 | |
| 1945 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1946 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1947 | typename enable_if |
| 1948 | < |
| 1949 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1950 | _Tp |
| 1951 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1952 | atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1953 | { |
| 1954 | return __o->fetch_add(__op, __m); |
| 1955 | } |
| 1956 | |
| 1957 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1958 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1959 | typename enable_if |
| 1960 | < |
| 1961 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1962 | _Tp |
| 1963 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1964 | atomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1965 | { |
| 1966 | return __o->fetch_add(__op, __m); |
| 1967 | } |
| 1968 | |
| 1969 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1970 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1971 | _Tp* |
| 1972 | atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1973 | memory_order __m) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1974 | { |
| 1975 | return __o->fetch_add(__op, __m); |
| 1976 | } |
| 1977 | |
| 1978 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1979 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1980 | _Tp* |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1981 | atomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1982 | { |
| 1983 | return __o->fetch_add(__op, __m); |
| 1984 | } |
| 1985 | |
| 1986 | // atomic_fetch_sub |
| 1987 | |
| 1988 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 1989 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1990 | typename enable_if |
| 1991 | < |
| 1992 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1993 | _Tp |
| 1994 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1995 | atomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1996 | { |
| 1997 | return __o->fetch_sub(__op); |
| 1998 | } |
| 1999 | |
| 2000 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2001 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2002 | typename enable_if |
| 2003 | < |
| 2004 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 2005 | _Tp |
| 2006 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2007 | atomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2008 | { |
| 2009 | return __o->fetch_sub(__op); |
| 2010 | } |
| 2011 | |
| 2012 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2013 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2014 | _Tp* |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2015 | atomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2016 | { |
| 2017 | return __o->fetch_sub(__op); |
| 2018 | } |
| 2019 | |
| 2020 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2021 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2022 | _Tp* |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2023 | atomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2024 | { |
| 2025 | return __o->fetch_sub(__op); |
| 2026 | } |
| 2027 | |
| 2028 | // atomic_fetch_sub_explicit |
| 2029 | |
| 2030 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2031 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2032 | typename enable_if |
| 2033 | < |
| 2034 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 2035 | _Tp |
| 2036 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2037 | atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2038 | { |
| 2039 | return __o->fetch_sub(__op, __m); |
| 2040 | } |
| 2041 | |
| 2042 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2043 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2044 | typename enable_if |
| 2045 | < |
| 2046 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 2047 | _Tp |
| 2048 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2049 | atomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2050 | { |
| 2051 | return __o->fetch_sub(__op, __m); |
| 2052 | } |
| 2053 | |
| 2054 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2055 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2056 | _Tp* |
| 2057 | atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op, |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2058 | memory_order __m) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2059 | { |
| 2060 | return __o->fetch_sub(__op, __m); |
| 2061 | } |
| 2062 | |
| 2063 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2064 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2065 | _Tp* |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2066 | atomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2067 | { |
| 2068 | return __o->fetch_sub(__op, __m); |
| 2069 | } |
| 2070 | |
| 2071 | // atomic_fetch_and |
| 2072 | |
| 2073 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2074 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2075 | typename enable_if |
| 2076 | < |
| 2077 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 2078 | _Tp |
| 2079 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2080 | atomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2081 | { |
| 2082 | return __o->fetch_and(__op); |
| 2083 | } |
| 2084 | |
| 2085 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2086 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2087 | typename enable_if |
| 2088 | < |
| 2089 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 2090 | _Tp |
| 2091 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2092 | atomic_fetch_and(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2093 | { |
| 2094 | return __o->fetch_and(__op); |
| 2095 | } |
| 2096 | |
| 2097 | // atomic_fetch_and_explicit |
| 2098 | |
| 2099 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2100 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2101 | typename enable_if |
| 2102 | < |
| 2103 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 2104 | _Tp |
| 2105 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2106 | atomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2107 | { |
| 2108 | return __o->fetch_and(__op, __m); |
| 2109 | } |
| 2110 | |
| 2111 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2112 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2113 | typename enable_if |
| 2114 | < |
| 2115 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 2116 | _Tp |
| 2117 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2118 | atomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2119 | { |
| 2120 | return __o->fetch_and(__op, __m); |
| 2121 | } |
| 2122 | |
| 2123 | // atomic_fetch_or |
| 2124 | |
| 2125 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2126 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2127 | typename enable_if |
| 2128 | < |
| 2129 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 2130 | _Tp |
| 2131 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2132 | atomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2133 | { |
| 2134 | return __o->fetch_or(__op); |
| 2135 | } |
| 2136 | |
| 2137 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2138 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2139 | typename enable_if |
| 2140 | < |
| 2141 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 2142 | _Tp |
| 2143 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2144 | atomic_fetch_or(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2145 | { |
| 2146 | return __o->fetch_or(__op); |
| 2147 | } |
| 2148 | |
| 2149 | // atomic_fetch_or_explicit |
| 2150 | |
| 2151 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2152 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2153 | typename enable_if |
| 2154 | < |
| 2155 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 2156 | _Tp |
| 2157 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2158 | atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2159 | { |
| 2160 | return __o->fetch_or(__op, __m); |
| 2161 | } |
| 2162 | |
| 2163 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2164 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2165 | typename enable_if |
| 2166 | < |
| 2167 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 2168 | _Tp |
| 2169 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2170 | atomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2171 | { |
| 2172 | return __o->fetch_or(__op, __m); |
| 2173 | } |
| 2174 | |
| 2175 | // atomic_fetch_xor |
| 2176 | |
| 2177 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2178 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2179 | typename enable_if |
| 2180 | < |
| 2181 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 2182 | _Tp |
| 2183 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2184 | atomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2185 | { |
| 2186 | return __o->fetch_xor(__op); |
| 2187 | } |
| 2188 | |
| 2189 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2190 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2191 | typename enable_if |
| 2192 | < |
| 2193 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 2194 | _Tp |
| 2195 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2196 | atomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2197 | { |
| 2198 | return __o->fetch_xor(__op); |
| 2199 | } |
| 2200 | |
| 2201 | // atomic_fetch_xor_explicit |
| 2202 | |
| 2203 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2204 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2205 | typename enable_if |
| 2206 | < |
| 2207 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 2208 | _Tp |
| 2209 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2210 | atomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2211 | { |
| 2212 | return __o->fetch_xor(__op, __m); |
| 2213 | } |
| 2214 | |
| 2215 | template <class _Tp> |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2216 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2217 | typename enable_if |
| 2218 | < |
| 2219 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 2220 | _Tp |
| 2221 | >::type |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2222 | atomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 138f592 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 2223 | { |
| 2224 | return __o->fetch_xor(__op, __m); |
| 2225 | } |
Howard Hinnant | 7bfaeb8 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 2226 | |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2227 | // flag type and operations |
| 2228 | |
| 2229 | typedef struct atomic_flag |
| 2230 | { |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2231 | __cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_; |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2232 | |
| 2233 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2234 | bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2235 | {return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);} |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2236 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2237 | bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2238 | {return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);} |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2239 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2240 | void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2241 | {__cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);} |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2242 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2243 | void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2244 | {__cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);} |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2245 | |
| 2246 | _LIBCPP_INLINE_VISIBILITY |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2247 | atomic_flag() _NOEXCEPT _LIBCPP_DEFAULT |
Howard Hinnant | 3d28422 | 2013-05-02 20:18:43 +0000 | [diff] [blame] | 2248 | |
Marshall Clow | cf99075 | 2018-04-25 14:27:29 +0000 | [diff] [blame] | 2249 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Eric Fiselier | fec26a9 | 2016-05-03 02:12:26 +0000 | [diff] [blame] | 2250 | atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2251 | |
Eric Fiselier | 2d8515f | 2017-01-06 20:58:25 +0000 | [diff] [blame] | 2252 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2253 | atomic_flag(const atomic_flag&) = delete; |
| 2254 | atomic_flag& operator=(const atomic_flag&) = delete; |
| 2255 | atomic_flag& operator=(const atomic_flag&) volatile = delete; |
Eric Fiselier | 2d8515f | 2017-01-06 20:58:25 +0000 | [diff] [blame] | 2256 | #else |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2257 | private: |
| 2258 | atomic_flag(const atomic_flag&); |
| 2259 | atomic_flag& operator=(const atomic_flag&); |
| 2260 | atomic_flag& operator=(const atomic_flag&) volatile; |
Eric Fiselier | 2d8515f | 2017-01-06 20:58:25 +0000 | [diff] [blame] | 2261 | #endif |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2262 | } atomic_flag; |
| 2263 | |
| 2264 | inline _LIBCPP_INLINE_VISIBILITY |
| 2265 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2266 | atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2267 | { |
| 2268 | return __o->test_and_set(); |
| 2269 | } |
| 2270 | |
| 2271 | inline _LIBCPP_INLINE_VISIBILITY |
| 2272 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2273 | atomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2274 | { |
| 2275 | return __o->test_and_set(); |
| 2276 | } |
| 2277 | |
| 2278 | inline _LIBCPP_INLINE_VISIBILITY |
| 2279 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2280 | atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2281 | { |
| 2282 | return __o->test_and_set(__m); |
| 2283 | } |
| 2284 | |
| 2285 | inline _LIBCPP_INLINE_VISIBILITY |
| 2286 | bool |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2287 | atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2288 | { |
| 2289 | return __o->test_and_set(__m); |
| 2290 | } |
| 2291 | |
| 2292 | inline _LIBCPP_INLINE_VISIBILITY |
| 2293 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2294 | atomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2295 | { |
| 2296 | __o->clear(); |
| 2297 | } |
| 2298 | |
| 2299 | inline _LIBCPP_INLINE_VISIBILITY |
| 2300 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2301 | atomic_flag_clear(atomic_flag* __o) _NOEXCEPT |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2302 | { |
| 2303 | __o->clear(); |
| 2304 | } |
| 2305 | |
| 2306 | inline _LIBCPP_INLINE_VISIBILITY |
| 2307 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2308 | atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2309 | { |
| 2310 | __o->clear(__m); |
| 2311 | } |
| 2312 | |
| 2313 | inline _LIBCPP_INLINE_VISIBILITY |
| 2314 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2315 | atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2316 | { |
| 2317 | __o->clear(__m); |
| 2318 | } |
| 2319 | |
| 2320 | // fences |
| 2321 | |
| 2322 | inline _LIBCPP_INLINE_VISIBILITY |
| 2323 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2324 | atomic_thread_fence(memory_order __m) _NOEXCEPT |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2325 | { |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2326 | __cxx_atomic_thread_fence(__m); |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | inline _LIBCPP_INLINE_VISIBILITY |
| 2330 | void |
Howard Hinnant | eee2c14 | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 2331 | atomic_signal_fence(memory_order __m) _NOEXCEPT |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2332 | { |
Louis Dionne | a1ae003 | 2019-03-04 15:26:27 +0000 | [diff] [blame^] | 2333 | __cxx_atomic_signal_fence(__m); |
Howard Hinnant | 6ac60f8 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 2334 | } |
| 2335 | |
Howard Hinnant | 96e4cd6 | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 2336 | // Atomics for standard typedef types |
| 2337 | |
Howard Hinnant | f0af8d9 | 2013-01-04 18:58:50 +0000 | [diff] [blame] | 2338 | typedef atomic<bool> atomic_bool; |
Howard Hinnant | 96e4cd6 | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 2339 | typedef atomic<char> atomic_char; |
| 2340 | typedef atomic<signed char> atomic_schar; |
| 2341 | typedef atomic<unsigned char> atomic_uchar; |
| 2342 | typedef atomic<short> atomic_short; |
| 2343 | typedef atomic<unsigned short> atomic_ushort; |
| 2344 | typedef atomic<int> atomic_int; |
| 2345 | typedef atomic<unsigned int> atomic_uint; |
| 2346 | typedef atomic<long> atomic_long; |
| 2347 | typedef atomic<unsigned long> atomic_ulong; |
| 2348 | typedef atomic<long long> atomic_llong; |
| 2349 | typedef atomic<unsigned long long> atomic_ullong; |
| 2350 | typedef atomic<char16_t> atomic_char16_t; |
| 2351 | typedef atomic<char32_t> atomic_char32_t; |
| 2352 | typedef atomic<wchar_t> atomic_wchar_t; |
| 2353 | |
| 2354 | typedef atomic<int_least8_t> atomic_int_least8_t; |
| 2355 | typedef atomic<uint_least8_t> atomic_uint_least8_t; |
| 2356 | typedef atomic<int_least16_t> atomic_int_least16_t; |
| 2357 | typedef atomic<uint_least16_t> atomic_uint_least16_t; |
| 2358 | typedef atomic<int_least32_t> atomic_int_least32_t; |
| 2359 | typedef atomic<uint_least32_t> atomic_uint_least32_t; |
| 2360 | typedef atomic<int_least64_t> atomic_int_least64_t; |
| 2361 | typedef atomic<uint_least64_t> atomic_uint_least64_t; |
| 2362 | |
| 2363 | typedef atomic<int_fast8_t> atomic_int_fast8_t; |
| 2364 | typedef atomic<uint_fast8_t> atomic_uint_fast8_t; |
| 2365 | typedef atomic<int_fast16_t> atomic_int_fast16_t; |
| 2366 | typedef atomic<uint_fast16_t> atomic_uint_fast16_t; |
| 2367 | typedef atomic<int_fast32_t> atomic_int_fast32_t; |
| 2368 | typedef atomic<uint_fast32_t> atomic_uint_fast32_t; |
| 2369 | typedef atomic<int_fast64_t> atomic_int_fast64_t; |
| 2370 | typedef atomic<uint_fast64_t> atomic_uint_fast64_t; |
| 2371 | |
Marshall Clow | f710afc | 2016-06-30 15:28:38 +0000 | [diff] [blame] | 2372 | typedef atomic< int8_t> atomic_int8_t; |
| 2373 | typedef atomic<uint8_t> atomic_uint8_t; |
| 2374 | typedef atomic< int16_t> atomic_int16_t; |
| 2375 | typedef atomic<uint16_t> atomic_uint16_t; |
| 2376 | typedef atomic< int32_t> atomic_int32_t; |
| 2377 | typedef atomic<uint32_t> atomic_uint32_t; |
| 2378 | typedef atomic< int64_t> atomic_int64_t; |
| 2379 | typedef atomic<uint64_t> atomic_uint64_t; |
| 2380 | |
Howard Hinnant | 96e4cd6 | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 2381 | typedef atomic<intptr_t> atomic_intptr_t; |
| 2382 | typedef atomic<uintptr_t> atomic_uintptr_t; |
| 2383 | typedef atomic<size_t> atomic_size_t; |
| 2384 | typedef atomic<ptrdiff_t> atomic_ptrdiff_t; |
| 2385 | typedef atomic<intmax_t> atomic_intmax_t; |
| 2386 | typedef atomic<uintmax_t> atomic_uintmax_t; |
| 2387 | |
Howard Hinnant | f1f066a | 2010-09-29 21:20:03 +0000 | [diff] [blame] | 2388 | #define ATOMIC_FLAG_INIT {false} |
Howard Hinnant | 953c31d | 2010-10-04 18:52:54 +0000 | [diff] [blame] | 2389 | #define ATOMIC_VAR_INIT(__v) {__v} |
| 2390 | |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 2391 | _LIBCPP_END_NAMESPACE_STD |
| 2392 | |
Howard Hinnant | 71be729 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 2393 | #endif // _LIBCPP_ATOMIC |