Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- atomic -----------------------------------===// |
| 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
| 6 | // This file is distributed under the University of Illinois Open Source |
| 7 | // License. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_ATOMIC |
| 12 | #define _LIBCPP_ATOMIC |
| 13 | |
| 14 | /* |
| 15 | atomic synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
JF Bastien | 08511cd | 2016-03-25 15:48:21 +0000 | [diff] [blame] | 20 | // feature test macro |
| 21 | |
| 22 | #define __cpp_lib_atomic_is_always_lock_free // as specified by SG10 |
| 23 | |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 24 | // order and consistency |
| 25 | |
| 26 | typedef enum memory_order |
| 27 | { |
Howard Hinnant | d1176e2 | 2010-09-28 17:13:38 +0000 | [diff] [blame] | 28 | memory_order_relaxed, |
| 29 | memory_order_consume, // load-consume |
| 30 | memory_order_acquire, // load-acquire |
| 31 | memory_order_release, // store-release |
| 32 | memory_order_acq_rel, // store-release load-acquire |
| 33 | memory_order_seq_cst // store-release load-acquire |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 34 | } memory_order; |
| 35 | |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 36 | template <class T> T kill_dependency(T y) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 37 | |
| 38 | // lock-free property |
| 39 | |
Howard Hinnant | 7b9d6a8 | 2013-01-21 20:39:41 +0000 | [diff] [blame] | 40 | #define ATOMIC_BOOL_LOCK_FREE unspecified |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 41 | #define ATOMIC_CHAR_LOCK_FREE unspecified |
| 42 | #define ATOMIC_CHAR16_T_LOCK_FREE unspecified |
| 43 | #define ATOMIC_CHAR32_T_LOCK_FREE unspecified |
| 44 | #define ATOMIC_WCHAR_T_LOCK_FREE unspecified |
| 45 | #define ATOMIC_SHORT_LOCK_FREE unspecified |
| 46 | #define ATOMIC_INT_LOCK_FREE unspecified |
| 47 | #define ATOMIC_LONG_LOCK_FREE unspecified |
| 48 | #define ATOMIC_LLONG_LOCK_FREE unspecified |
Howard Hinnant | 7b9d6a8 | 2013-01-21 20:39:41 +0000 | [diff] [blame] | 49 | #define ATOMIC_POINTER_LOCK_FREE unspecified |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 50 | |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 51 | // flag type and operations |
| 52 | |
| 53 | typedef struct atomic_flag |
| 54 | { |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 55 | bool test_and_set(memory_order m = memory_order_seq_cst) volatile noexcept; |
| 56 | bool test_and_set(memory_order m = memory_order_seq_cst) noexcept; |
| 57 | void clear(memory_order m = memory_order_seq_cst) volatile noexcept; |
| 58 | void clear(memory_order m = memory_order_seq_cst) noexcept; |
| 59 | atomic_flag() noexcept = default; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 60 | atomic_flag(const atomic_flag&) = delete; |
| 61 | atomic_flag& operator=(const atomic_flag&) = delete; |
| 62 | atomic_flag& operator=(const atomic_flag&) volatile = delete; |
| 63 | } atomic_flag; |
| 64 | |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 65 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 66 | atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 67 | |
| 68 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 69 | atomic_flag_test_and_set(atomic_flag* obj) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 70 | |
| 71 | bool |
| 72 | atomic_flag_test_and_set_explicit(volatile atomic_flag* obj, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 73 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 74 | |
| 75 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 76 | atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 77 | |
| 78 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 79 | atomic_flag_clear(volatile atomic_flag* obj) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 80 | |
| 81 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 82 | atomic_flag_clear(atomic_flag* obj) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 83 | |
| 84 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 85 | atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 86 | |
| 87 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 88 | atomic_flag_clear_explicit(atomic_flag* obj, memory_order m) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 89 | |
| 90 | #define ATOMIC_FLAG_INIT see below |
Howard Hinnant | e738501 | 2010-10-19 16:51:18 +0000 | [diff] [blame] | 91 | #define ATOMIC_VAR_INIT(value) see below |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 92 | |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 93 | template <class T> |
| 94 | struct atomic |
| 95 | { |
JF Bastien | 08511cd | 2016-03-25 15:48:21 +0000 | [diff] [blame] | 96 | static constexpr bool is_always_lock_free; |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 97 | bool is_lock_free() const volatile noexcept; |
| 98 | bool is_lock_free() const noexcept; |
| 99 | void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 100 | void store(T desr, memory_order m = memory_order_seq_cst) noexcept; |
| 101 | T load(memory_order m = memory_order_seq_cst) const volatile noexcept; |
| 102 | T load(memory_order m = memory_order_seq_cst) const noexcept; |
| 103 | operator T() const volatile noexcept; |
| 104 | operator T() const noexcept; |
| 105 | T exchange(T desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 106 | T exchange(T desr, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 107 | bool compare_exchange_weak(T& expc, T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 108 | memory_order s, memory_order f) volatile noexcept; |
| 109 | bool compare_exchange_weak(T& expc, T desr, memory_order s, memory_order f) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 110 | bool compare_exchange_strong(T& expc, T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 111 | memory_order s, memory_order f) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 112 | bool compare_exchange_strong(T& expc, T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 113 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 114 | bool compare_exchange_weak(T& expc, T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 115 | memory_order m = memory_order_seq_cst) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 116 | bool compare_exchange_weak(T& expc, T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 117 | memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 118 | bool compare_exchange_strong(T& expc, T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 119 | memory_order m = memory_order_seq_cst) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 120 | bool compare_exchange_strong(T& expc, T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 121 | memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 122 | |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 123 | atomic() noexcept = default; |
| 124 | constexpr atomic(T desr) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 125 | atomic(const atomic&) = delete; |
| 126 | atomic& operator=(const atomic&) = delete; |
| 127 | atomic& operator=(const atomic&) volatile = delete; |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 128 | T operator=(T) volatile noexcept; |
| 129 | T operator=(T) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | template <> |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 133 | struct atomic<integral> |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 134 | { |
JF Bastien | 08511cd | 2016-03-25 15:48:21 +0000 | [diff] [blame] | 135 | static constexpr bool is_always_lock_free; |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 136 | bool is_lock_free() const volatile noexcept; |
| 137 | bool is_lock_free() const noexcept; |
| 138 | void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 139 | void store(integral desr, memory_order m = memory_order_seq_cst) noexcept; |
| 140 | integral load(memory_order m = memory_order_seq_cst) const volatile noexcept; |
| 141 | integral load(memory_order m = memory_order_seq_cst) const noexcept; |
| 142 | operator integral() const volatile noexcept; |
| 143 | operator integral() const noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 144 | integral exchange(integral desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 145 | memory_order m = memory_order_seq_cst) volatile noexcept; |
| 146 | integral exchange(integral desr, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 147 | bool compare_exchange_weak(integral& expc, integral desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 148 | memory_order s, memory_order f) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 149 | bool compare_exchange_weak(integral& expc, integral desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 150 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 151 | bool compare_exchange_strong(integral& expc, integral desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 152 | memory_order s, memory_order f) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 153 | bool compare_exchange_strong(integral& expc, integral desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 154 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 155 | bool compare_exchange_weak(integral& expc, integral desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 156 | memory_order m = memory_order_seq_cst) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 157 | bool compare_exchange_weak(integral& expc, integral desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 158 | memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 159 | bool compare_exchange_strong(integral& expc, integral desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 160 | memory_order m = memory_order_seq_cst) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 161 | bool compare_exchange_strong(integral& expc, integral desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 162 | memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 163 | |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 164 | integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 165 | fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 166 | integral fetch_add(integral op, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 167 | integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 168 | fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 169 | integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 170 | integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 171 | fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 172 | integral fetch_and(integral op, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 173 | integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 174 | fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 175 | integral fetch_or(integral op, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 176 | integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 177 | fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 178 | integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 179 | |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 180 | atomic() noexcept = default; |
| 181 | constexpr atomic(integral desr) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 182 | atomic(const atomic&) = delete; |
| 183 | atomic& operator=(const atomic&) = delete; |
| 184 | atomic& operator=(const atomic&) volatile = delete; |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 185 | integral operator=(integral desr) volatile noexcept; |
| 186 | integral operator=(integral desr) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 187 | |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 188 | integral operator++(int) volatile noexcept; |
| 189 | integral operator++(int) noexcept; |
| 190 | integral operator--(int) volatile noexcept; |
| 191 | integral operator--(int) noexcept; |
| 192 | integral operator++() volatile noexcept; |
| 193 | integral operator++() noexcept; |
| 194 | integral operator--() volatile noexcept; |
| 195 | integral operator--() noexcept; |
| 196 | integral operator+=(integral op) volatile noexcept; |
| 197 | integral operator+=(integral op) noexcept; |
| 198 | integral operator-=(integral op) volatile noexcept; |
| 199 | integral operator-=(integral op) noexcept; |
| 200 | integral operator&=(integral op) volatile noexcept; |
| 201 | integral operator&=(integral op) noexcept; |
| 202 | integral operator|=(integral op) volatile noexcept; |
| 203 | integral operator|=(integral op) noexcept; |
| 204 | integral operator^=(integral op) volatile noexcept; |
| 205 | integral operator^=(integral op) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | template <class T> |
| 209 | struct atomic<T*> |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 210 | { |
JF Bastien | 08511cd | 2016-03-25 15:48:21 +0000 | [diff] [blame] | 211 | static constexpr bool is_always_lock_free; |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 212 | bool is_lock_free() const volatile noexcept; |
| 213 | bool is_lock_free() const noexcept; |
| 214 | void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 215 | void store(T* desr, memory_order m = memory_order_seq_cst) noexcept; |
| 216 | T* load(memory_order m = memory_order_seq_cst) const volatile noexcept; |
| 217 | T* load(memory_order m = memory_order_seq_cst) const noexcept; |
| 218 | operator T*() const volatile noexcept; |
| 219 | operator T*() const noexcept; |
| 220 | T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 221 | T* exchange(T* desr, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 222 | bool compare_exchange_weak(T*& expc, T* desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 223 | memory_order s, memory_order f) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 224 | bool compare_exchange_weak(T*& expc, T* desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 225 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 226 | bool compare_exchange_strong(T*& expc, T* desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 227 | memory_order s, memory_order f) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 228 | bool compare_exchange_strong(T*& expc, T* desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 229 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 230 | bool compare_exchange_weak(T*& expc, T* desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 231 | memory_order m = memory_order_seq_cst) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 232 | bool compare_exchange_weak(T*& expc, T* desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 233 | memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 234 | bool compare_exchange_strong(T*& expc, T* desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 235 | memory_order m = memory_order_seq_cst) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 236 | bool compare_exchange_strong(T*& expc, T* desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 237 | memory_order m = memory_order_seq_cst) noexcept; |
| 238 | T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 239 | T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept; |
| 240 | T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 241 | T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 242 | |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 243 | atomic() noexcept = default; |
| 244 | constexpr atomic(T* desr) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 245 | atomic(const atomic&) = delete; |
| 246 | atomic& operator=(const atomic&) = delete; |
| 247 | atomic& operator=(const atomic&) volatile = delete; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 248 | |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 249 | T* operator=(T*) volatile noexcept; |
| 250 | T* operator=(T*) noexcept; |
| 251 | T* operator++(int) volatile noexcept; |
| 252 | T* operator++(int) noexcept; |
| 253 | T* operator--(int) volatile noexcept; |
| 254 | T* operator--(int) noexcept; |
| 255 | T* operator++() volatile noexcept; |
| 256 | T* operator++() noexcept; |
| 257 | T* operator--() volatile noexcept; |
| 258 | T* operator--() noexcept; |
| 259 | T* operator+=(ptrdiff_t op) volatile noexcept; |
| 260 | T* operator+=(ptrdiff_t op) noexcept; |
| 261 | T* operator-=(ptrdiff_t op) volatile noexcept; |
| 262 | T* operator-=(ptrdiff_t op) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 263 | }; |
| 264 | |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 265 | |
| 266 | template <class T> |
| 267 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 268 | atomic_is_lock_free(const volatile atomic<T>* obj) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 269 | |
| 270 | template <class T> |
| 271 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 272 | atomic_is_lock_free(const atomic<T>* obj) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 273 | |
| 274 | template <class T> |
| 275 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 276 | atomic_init(volatile atomic<T>* obj, T desr) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 277 | |
| 278 | template <class T> |
| 279 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 280 | atomic_init(atomic<T>* obj, T desr) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 281 | |
| 282 | template <class T> |
| 283 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 284 | atomic_store(volatile atomic<T>* obj, T desr) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 285 | |
| 286 | template <class T> |
| 287 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 288 | atomic_store(atomic<T>* obj, T desr) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 289 | |
| 290 | template <class T> |
| 291 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 292 | atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 293 | |
| 294 | template <class T> |
| 295 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 296 | atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 297 | |
| 298 | template <class T> |
| 299 | T |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 300 | atomic_load(const volatile atomic<T>* obj) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 301 | |
| 302 | template <class T> |
| 303 | T |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 304 | atomic_load(const atomic<T>* obj) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 305 | |
| 306 | template <class T> |
| 307 | T |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 308 | atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 309 | |
| 310 | template <class T> |
| 311 | T |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 312 | atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 313 | |
| 314 | template <class T> |
| 315 | T |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 316 | atomic_exchange(volatile atomic<T>* obj, T desr) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 317 | |
| 318 | template <class T> |
| 319 | T |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 320 | atomic_exchange(atomic<T>* obj, T desr) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 321 | |
| 322 | template <class T> |
| 323 | T |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 324 | atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 325 | |
| 326 | template <class T> |
| 327 | T |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 328 | atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 329 | |
| 330 | template <class T> |
| 331 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 332 | atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 333 | |
| 334 | template <class T> |
| 335 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 336 | atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 337 | |
| 338 | template <class T> |
| 339 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 340 | atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 341 | |
| 342 | template <class T> |
| 343 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 344 | atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 345 | |
| 346 | template <class T> |
| 347 | bool |
| 348 | atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc, |
| 349 | T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 350 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 351 | |
| 352 | template <class T> |
| 353 | bool |
| 354 | atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 355 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 356 | |
| 357 | template <class T> |
| 358 | bool |
| 359 | atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj, |
| 360 | T* expc, T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 361 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 362 | |
| 363 | template <class T> |
| 364 | bool |
| 365 | atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc, |
| 366 | T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 367 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 368 | |
| 369 | template <class Integral> |
| 370 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 371 | atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 372 | |
| 373 | template <class Integral> |
| 374 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 375 | atomic_fetch_add(atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 376 | |
| 377 | template <class Integral> |
| 378 | Integral |
| 379 | atomic_fetch_add_explicit(volatile atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 380 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 381 | template <class Integral> |
| 382 | Integral |
| 383 | atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 384 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 385 | template <class Integral> |
| 386 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 387 | atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 388 | |
| 389 | template <class Integral> |
| 390 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 391 | atomic_fetch_sub(atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 392 | |
| 393 | template <class Integral> |
| 394 | Integral |
| 395 | atomic_fetch_sub_explicit(volatile atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 396 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 397 | template <class Integral> |
| 398 | Integral |
| 399 | atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 400 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 401 | template <class Integral> |
| 402 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 403 | atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 404 | |
| 405 | template <class Integral> |
| 406 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 407 | atomic_fetch_and(atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 408 | |
| 409 | template <class Integral> |
| 410 | Integral |
| 411 | atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 412 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 413 | template <class Integral> |
| 414 | Integral |
| 415 | atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 416 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 417 | template <class Integral> |
| 418 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 419 | atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 420 | |
| 421 | template <class Integral> |
| 422 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 423 | atomic_fetch_or(atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 424 | |
| 425 | template <class Integral> |
| 426 | Integral |
| 427 | atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 428 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 429 | template <class Integral> |
| 430 | Integral |
| 431 | atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 432 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 433 | template <class Integral> |
| 434 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 435 | atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 436 | |
| 437 | template <class Integral> |
| 438 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 439 | atomic_fetch_xor(atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 440 | |
| 441 | template <class Integral> |
| 442 | Integral |
| 443 | atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 444 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 445 | template <class Integral> |
| 446 | Integral |
| 447 | atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 448 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 449 | |
| 450 | template <class T> |
| 451 | T* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 452 | atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 453 | |
| 454 | template <class T> |
| 455 | T* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 456 | atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 457 | |
| 458 | template <class T> |
| 459 | T* |
| 460 | atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 461 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 462 | template <class T> |
| 463 | T* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 464 | atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 465 | |
| 466 | template <class T> |
| 467 | T* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 468 | atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 469 | |
| 470 | template <class T> |
| 471 | T* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 472 | atomic_fetch_sub(atomic<T*>* obj, ptrdiff_t op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 473 | |
| 474 | template <class T> |
| 475 | T* |
| 476 | atomic_fetch_sub_explicit(volatile atomic<T*>* obj, ptrdiff_t op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 477 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 478 | template <class T> |
| 479 | T* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 480 | atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 481 | |
| 482 | // Atomics for standard typedef types |
| 483 | |
Howard Hinnant | 6ae4705 | 2013-01-04 18:58:50 +0000 | [diff] [blame] | 484 | typedef atomic<bool> atomic_bool; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 485 | typedef atomic<char> atomic_char; |
| 486 | typedef atomic<signed char> atomic_schar; |
| 487 | typedef atomic<unsigned char> atomic_uchar; |
| 488 | typedef atomic<short> atomic_short; |
| 489 | typedef atomic<unsigned short> atomic_ushort; |
| 490 | typedef atomic<int> atomic_int; |
| 491 | typedef atomic<unsigned int> atomic_uint; |
| 492 | typedef atomic<long> atomic_long; |
| 493 | typedef atomic<unsigned long> atomic_ulong; |
| 494 | typedef atomic<long long> atomic_llong; |
| 495 | typedef atomic<unsigned long long> atomic_ullong; |
| 496 | typedef atomic<char16_t> atomic_char16_t; |
| 497 | typedef atomic<char32_t> atomic_char32_t; |
| 498 | typedef atomic<wchar_t> atomic_wchar_t; |
| 499 | |
| 500 | typedef atomic<int_least8_t> atomic_int_least8_t; |
| 501 | typedef atomic<uint_least8_t> atomic_uint_least8_t; |
| 502 | typedef atomic<int_least16_t> atomic_int_least16_t; |
| 503 | typedef atomic<uint_least16_t> atomic_uint_least16_t; |
| 504 | typedef atomic<int_least32_t> atomic_int_least32_t; |
| 505 | typedef atomic<uint_least32_t> atomic_uint_least32_t; |
| 506 | typedef atomic<int_least64_t> atomic_int_least64_t; |
| 507 | typedef atomic<uint_least64_t> atomic_uint_least64_t; |
| 508 | |
| 509 | typedef atomic<int_fast8_t> atomic_int_fast8_t; |
| 510 | typedef atomic<uint_fast8_t> atomic_uint_fast8_t; |
| 511 | typedef atomic<int_fast16_t> atomic_int_fast16_t; |
| 512 | typedef atomic<uint_fast16_t> atomic_uint_fast16_t; |
| 513 | typedef atomic<int_fast32_t> atomic_int_fast32_t; |
| 514 | typedef atomic<uint_fast32_t> atomic_uint_fast32_t; |
| 515 | typedef atomic<int_fast64_t> atomic_int_fast64_t; |
| 516 | typedef atomic<uint_fast64_t> atomic_uint_fast64_t; |
| 517 | |
Marshall Clow | ca89450 | 2016-06-30 15:28:38 +0000 | [diff] [blame] | 518 | typedef atomic<int8_t> atomic_int8_t; |
| 519 | typedef atomic<uint8_t> atomic_uint8_t; |
| 520 | typedef atomic<int16_t> atomic_int16_t; |
| 521 | typedef atomic<uint16_t> atomic_uint16_t; |
| 522 | typedef atomic<int32_t> atomic_int32_t; |
| 523 | typedef atomic<uint32_t> atomic_uint32_t; |
| 524 | typedef atomic<int64_t> atomic_int64_t; |
| 525 | typedef atomic<uint64_t> atomic_uint64_t; |
| 526 | |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 527 | typedef atomic<intptr_t> atomic_intptr_t; |
| 528 | typedef atomic<uintptr_t> atomic_uintptr_t; |
| 529 | typedef atomic<size_t> atomic_size_t; |
| 530 | typedef atomic<ptrdiff_t> atomic_ptrdiff_t; |
| 531 | typedef atomic<intmax_t> atomic_intmax_t; |
| 532 | typedef atomic<uintmax_t> atomic_uintmax_t; |
| 533 | |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 534 | // fences |
| 535 | |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 536 | void atomic_thread_fence(memory_order m) noexcept; |
| 537 | void atomic_signal_fence(memory_order m) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 538 | |
| 539 | } // std |
| 540 | |
| 541 | */ |
| 542 | |
| 543 | #include <__config> |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 544 | #include <cstddef> |
| 545 | #include <cstdint> |
| 546 | #include <type_traits> |
Marshall Clow | e3973fd | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 547 | #include <version> |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 548 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 549 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 550 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 551 | #endif |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 552 | |
Jonathan Roelofs | 8d86b2e | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 553 | #ifdef _LIBCPP_HAS_NO_THREADS |
| 554 | #error <atomic> is not supported on this single threaded system |
Eric Fiselier | 00f4a49 | 2015-08-19 17:21:46 +0000 | [diff] [blame] | 555 | #endif |
| 556 | #if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) |
| 557 | #error <atomic> is not implemented |
| 558 | #endif |
Volodymyr Sapsai | 6c03a7a | 2018-05-15 22:38:31 +0000 | [diff] [blame] | 559 | #ifdef kill_dependency |
| 560 | #error C++ standard library is incompatible with <stdatomic.h> |
| 561 | #endif |
Jonathan Roelofs | 8d86b2e | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 562 | |
Eric Fiselier | 5ed7675 | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 563 | #define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \ |
| 564 | _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_consume || \ |
| 565 | __m == memory_order_acquire || \ |
| 566 | __m == memory_order_acq_rel, \ |
| 567 | "memory order argument to atomic operation is invalid") |
| 568 | |
| 569 | #define _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) \ |
| 570 | _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || \ |
| 571 | __m == memory_order_acq_rel, \ |
| 572 | "memory order argument to atomic operation is invalid") |
| 573 | |
| 574 | #define _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__m, __f) \ |
| 575 | _LIBCPP_DIAGNOSE_WARNING(__f == memory_order_release || \ |
| 576 | __f == memory_order_acq_rel, \ |
| 577 | "memory order argument to atomic operation is invalid") |
| 578 | |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 579 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 580 | |
Howard Hinnant | d1176e2 | 2010-09-28 17:13:38 +0000 | [diff] [blame] | 581 | typedef enum memory_order |
| 582 | { |
| 583 | memory_order_relaxed, memory_order_consume, memory_order_acquire, |
| 584 | memory_order_release, memory_order_acq_rel, memory_order_seq_cst |
| 585 | } memory_order; |
| 586 | |
Eric Fiselier | 00f4a49 | 2015-08-19 17:21:46 +0000 | [diff] [blame] | 587 | #if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 588 | namespace __gcc_atomic { |
Marshall Clow | e422021 | 2015-01-11 06:15:59 +0000 | [diff] [blame] | 589 | template <typename _Tp> |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 590 | struct __gcc_atomic_t { |
Eric Fiselier | e39f4b9 | 2015-12-15 00:32:21 +0000 | [diff] [blame] | 591 | |
| 592 | #if _GNUC_VER >= 501 |
| 593 | static_assert(is_trivially_copyable<_Tp>::value, |
| 594 | "std::atomic<Tp> requires that 'Tp' be a trivially copyable type"); |
| 595 | #endif |
| 596 | |
Eric Fiselier | a4ae16b | 2015-10-14 08:36:22 +0000 | [diff] [blame] | 597 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 8c57032 | 2016-11-18 06:42:17 +0000 | [diff] [blame] | 598 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | a4ae16b | 2015-10-14 08:36:22 +0000 | [diff] [blame] | 599 | __gcc_atomic_t() _NOEXCEPT = default; |
| 600 | #else |
| 601 | __gcc_atomic_t() _NOEXCEPT : __a_value() {} |
Eric Fiselier | 8c57032 | 2016-11-18 06:42:17 +0000 | [diff] [blame] | 602 | #endif // _LIBCPP_CXX03_LANG |
Eric Fiselier | 26edd80 | 2015-07-14 17:50:27 +0000 | [diff] [blame] | 603 | _LIBCPP_CONSTEXPR explicit __gcc_atomic_t(_Tp value) _NOEXCEPT |
| 604 | : __a_value(value) {} |
Marshall Clow | e422021 | 2015-01-11 06:15:59 +0000 | [diff] [blame] | 605 | _Tp __a_value; |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 606 | }; |
| 607 | #define _Atomic(x) __gcc_atomic::__gcc_atomic_t<x> |
| 608 | |
Marshall Clow | e422021 | 2015-01-11 06:15:59 +0000 | [diff] [blame] | 609 | template <typename _Tp> _Tp __create(); |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 610 | |
Marshall Clow | e422021 | 2015-01-11 06:15:59 +0000 | [diff] [blame] | 611 | template <typename _Tp, typename _Td> |
| 612 | typename enable_if<sizeof(_Tp()->__a_value = __create<_Td>()), char>::type |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 613 | __test_atomic_assignable(int); |
Marshall Clow | e422021 | 2015-01-11 06:15:59 +0000 | [diff] [blame] | 614 | template <typename _Tp, typename _Up> |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 615 | __two __test_atomic_assignable(...); |
| 616 | |
Marshall Clow | e422021 | 2015-01-11 06:15:59 +0000 | [diff] [blame] | 617 | template <typename _Tp, typename _Td> |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 618 | struct __can_assign { |
| 619 | static const bool value = |
Marshall Clow | e422021 | 2015-01-11 06:15:59 +0000 | [diff] [blame] | 620 | sizeof(__test_atomic_assignable<_Tp, _Td>(1)) == sizeof(char); |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 621 | }; |
| 622 | |
Eric Fiselier | a4ae16b | 2015-10-14 08:36:22 +0000 | [diff] [blame] | 623 | static inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 624 | // Avoid switch statement to make this a constexpr. |
| 625 | return __order == memory_order_relaxed ? __ATOMIC_RELAXED: |
| 626 | (__order == memory_order_acquire ? __ATOMIC_ACQUIRE: |
| 627 | (__order == memory_order_release ? __ATOMIC_RELEASE: |
| 628 | (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST: |
| 629 | (__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL: |
| 630 | __ATOMIC_CONSUME)))); |
| 631 | } |
| 632 | |
Eric Fiselier | a4ae16b | 2015-10-14 08:36:22 +0000 | [diff] [blame] | 633 | static inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) { |
Dan Albert | c101738 | 2015-01-06 18:39:37 +0000 | [diff] [blame] | 634 | // Avoid switch statement to make this a constexpr. |
| 635 | return __order == memory_order_relaxed ? __ATOMIC_RELAXED: |
| 636 | (__order == memory_order_acquire ? __ATOMIC_ACQUIRE: |
| 637 | (__order == memory_order_release ? __ATOMIC_RELAXED: |
| 638 | (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST: |
| 639 | (__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE: |
| 640 | __ATOMIC_CONSUME)))); |
| 641 | } |
| 642 | |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 643 | } // namespace __gcc_atomic |
| 644 | |
| 645 | template <typename _Tp> |
| 646 | static inline |
| 647 | typename enable_if< |
| 648 | __gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value>::type |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 649 | __c11_atomic_init(volatile _Atomic(_Tp)* __a, _Tp __val) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 650 | __a->__a_value = __val; |
| 651 | } |
| 652 | |
| 653 | template <typename _Tp> |
| 654 | static inline |
| 655 | typename enable_if< |
| 656 | !__gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value && |
| 657 | __gcc_atomic::__can_assign< _Atomic(_Tp)*, _Tp>::value>::type |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 658 | __c11_atomic_init(volatile _Atomic(_Tp)* __a, _Tp __val) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 659 | // [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because |
| 660 | // the default operator= in an object is not volatile, a byte-by-byte copy |
| 661 | // is required. |
| 662 | volatile char* to = reinterpret_cast<volatile char*>(&__a->__a_value); |
| 663 | volatile char* end = to + sizeof(_Tp); |
| 664 | char* from = reinterpret_cast<char*>(&__val); |
| 665 | while (to != end) { |
| 666 | *to++ = *from++; |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | template <typename _Tp> |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 671 | static inline void __c11_atomic_init(_Atomic(_Tp)* __a, _Tp __val) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 672 | __a->__a_value = __val; |
| 673 | } |
| 674 | |
| 675 | static inline void __c11_atomic_thread_fence(memory_order __order) { |
| 676 | __atomic_thread_fence(__gcc_atomic::__to_gcc_order(__order)); |
| 677 | } |
| 678 | |
| 679 | static inline void __c11_atomic_signal_fence(memory_order __order) { |
| 680 | __atomic_signal_fence(__gcc_atomic::__to_gcc_order(__order)); |
| 681 | } |
| 682 | |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 683 | template <typename _Tp> |
| 684 | static inline void __c11_atomic_store(volatile _Atomic(_Tp)* __a, _Tp __val, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 685 | memory_order __order) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 686 | return __atomic_store(&__a->__a_value, &__val, |
| 687 | __gcc_atomic::__to_gcc_order(__order)); |
| 688 | } |
| 689 | |
| 690 | template <typename _Tp> |
| 691 | static inline void __c11_atomic_store(_Atomic(_Tp)* __a, _Tp __val, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 692 | memory_order __order) { |
Dan Albert | c101738 | 2015-01-06 18:39:37 +0000 | [diff] [blame] | 693 | __atomic_store(&__a->__a_value, &__val, |
| 694 | __gcc_atomic::__to_gcc_order(__order)); |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | template <typename _Tp> |
JF Bastien | 8d476cd | 2018-06-01 18:02:53 +0000 | [diff] [blame] | 698 | static inline _Tp __c11_atomic_load(const volatile _Atomic(_Tp)* __a, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 699 | memory_order __order) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 700 | _Tp __ret; |
| 701 | __atomic_load(&__a->__a_value, &__ret, |
| 702 | __gcc_atomic::__to_gcc_order(__order)); |
| 703 | return __ret; |
| 704 | } |
| 705 | |
| 706 | template <typename _Tp> |
JF Bastien | 8d476cd | 2018-06-01 18:02:53 +0000 | [diff] [blame] | 707 | static inline _Tp __c11_atomic_load(const _Atomic(_Tp)* __a, memory_order __order) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 708 | _Tp __ret; |
| 709 | __atomic_load(&__a->__a_value, &__ret, |
| 710 | __gcc_atomic::__to_gcc_order(__order)); |
| 711 | return __ret; |
| 712 | } |
| 713 | |
| 714 | template <typename _Tp> |
| 715 | static inline _Tp __c11_atomic_exchange(volatile _Atomic(_Tp)* __a, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 716 | _Tp __value, memory_order __order) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 717 | _Tp __ret; |
| 718 | __atomic_exchange(&__a->__a_value, &__value, &__ret, |
| 719 | __gcc_atomic::__to_gcc_order(__order)); |
| 720 | return __ret; |
| 721 | } |
| 722 | |
| 723 | template <typename _Tp> |
| 724 | static inline _Tp __c11_atomic_exchange(_Atomic(_Tp)* __a, _Tp __value, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 725 | memory_order __order) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 726 | _Tp __ret; |
| 727 | __atomic_exchange(&__a->__a_value, &__value, &__ret, |
| 728 | __gcc_atomic::__to_gcc_order(__order)); |
| 729 | return __ret; |
| 730 | } |
| 731 | |
| 732 | template <typename _Tp> |
| 733 | static inline bool __c11_atomic_compare_exchange_strong( |
| 734 | volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 735 | memory_order __success, memory_order __failure) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 736 | return __atomic_compare_exchange(&__a->__a_value, __expected, &__value, |
| 737 | false, |
| 738 | __gcc_atomic::__to_gcc_order(__success), |
Dan Albert | c101738 | 2015-01-06 18:39:37 +0000 | [diff] [blame] | 739 | __gcc_atomic::__to_gcc_failure_order(__failure)); |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | template <typename _Tp> |
| 743 | static inline bool __c11_atomic_compare_exchange_strong( |
| 744 | _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 745 | memory_order __failure) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 746 | return __atomic_compare_exchange(&__a->__a_value, __expected, &__value, |
| 747 | false, |
| 748 | __gcc_atomic::__to_gcc_order(__success), |
Dan Albert | c101738 | 2015-01-06 18:39:37 +0000 | [diff] [blame] | 749 | __gcc_atomic::__to_gcc_failure_order(__failure)); |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | template <typename _Tp> |
| 753 | static inline bool __c11_atomic_compare_exchange_weak( |
| 754 | volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 755 | memory_order __success, memory_order __failure) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 756 | return __atomic_compare_exchange(&__a->__a_value, __expected, &__value, |
| 757 | true, |
| 758 | __gcc_atomic::__to_gcc_order(__success), |
Dan Albert | c101738 | 2015-01-06 18:39:37 +0000 | [diff] [blame] | 759 | __gcc_atomic::__to_gcc_failure_order(__failure)); |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | template <typename _Tp> |
| 763 | static inline bool __c11_atomic_compare_exchange_weak( |
| 764 | _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 765 | memory_order __failure) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 766 | return __atomic_compare_exchange(&__a->__a_value, __expected, &__value, |
| 767 | true, |
| 768 | __gcc_atomic::__to_gcc_order(__success), |
Dan Albert | c101738 | 2015-01-06 18:39:37 +0000 | [diff] [blame] | 769 | __gcc_atomic::__to_gcc_failure_order(__failure)); |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | template <typename _Tp> |
| 773 | struct __skip_amt { enum {value = 1}; }; |
| 774 | |
| 775 | template <typename _Tp> |
| 776 | struct __skip_amt<_Tp*> { enum {value = sizeof(_Tp)}; }; |
| 777 | |
| 778 | // FIXME: Haven't figured out what the spec says about using arrays with |
| 779 | // atomic_fetch_add. Force a failure rather than creating bad behavior. |
| 780 | template <typename _Tp> |
| 781 | struct __skip_amt<_Tp[]> { }; |
| 782 | template <typename _Tp, int n> |
| 783 | struct __skip_amt<_Tp[n]> { }; |
| 784 | |
| 785 | template <typename _Tp, typename _Td> |
| 786 | static inline _Tp __c11_atomic_fetch_add(volatile _Atomic(_Tp)* __a, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 787 | _Td __delta, memory_order __order) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 788 | return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value, |
| 789 | __gcc_atomic::__to_gcc_order(__order)); |
| 790 | } |
| 791 | |
| 792 | template <typename _Tp, typename _Td> |
| 793 | static inline _Tp __c11_atomic_fetch_add(_Atomic(_Tp)* __a, _Td __delta, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 794 | memory_order __order) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 795 | return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value, |
| 796 | __gcc_atomic::__to_gcc_order(__order)); |
| 797 | } |
| 798 | |
| 799 | template <typename _Tp, typename _Td> |
| 800 | static inline _Tp __c11_atomic_fetch_sub(volatile _Atomic(_Tp)* __a, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 801 | _Td __delta, memory_order __order) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 802 | return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value, |
| 803 | __gcc_atomic::__to_gcc_order(__order)); |
| 804 | } |
| 805 | |
| 806 | template <typename _Tp, typename _Td> |
| 807 | static inline _Tp __c11_atomic_fetch_sub(_Atomic(_Tp)* __a, _Td __delta, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 808 | memory_order __order) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 809 | return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value, |
| 810 | __gcc_atomic::__to_gcc_order(__order)); |
| 811 | } |
| 812 | |
| 813 | template <typename _Tp> |
| 814 | static inline _Tp __c11_atomic_fetch_and(volatile _Atomic(_Tp)* __a, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 815 | _Tp __pattern, memory_order __order) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 816 | return __atomic_fetch_and(&__a->__a_value, __pattern, |
| 817 | __gcc_atomic::__to_gcc_order(__order)); |
| 818 | } |
| 819 | |
| 820 | template <typename _Tp> |
| 821 | static inline _Tp __c11_atomic_fetch_and(_Atomic(_Tp)* __a, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 822 | _Tp __pattern, memory_order __order) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 823 | return __atomic_fetch_and(&__a->__a_value, __pattern, |
| 824 | __gcc_atomic::__to_gcc_order(__order)); |
| 825 | } |
| 826 | |
| 827 | template <typename _Tp> |
| 828 | static inline _Tp __c11_atomic_fetch_or(volatile _Atomic(_Tp)* __a, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 829 | _Tp __pattern, memory_order __order) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 830 | return __atomic_fetch_or(&__a->__a_value, __pattern, |
| 831 | __gcc_atomic::__to_gcc_order(__order)); |
| 832 | } |
| 833 | |
| 834 | template <typename _Tp> |
| 835 | static inline _Tp __c11_atomic_fetch_or(_Atomic(_Tp)* __a, _Tp __pattern, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 836 | memory_order __order) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 837 | return __atomic_fetch_or(&__a->__a_value, __pattern, |
| 838 | __gcc_atomic::__to_gcc_order(__order)); |
| 839 | } |
| 840 | |
| 841 | template <typename _Tp> |
| 842 | static inline _Tp __c11_atomic_fetch_xor(volatile _Atomic(_Tp)* __a, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 843 | _Tp __pattern, memory_order __order) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 844 | return __atomic_fetch_xor(&__a->__a_value, __pattern, |
| 845 | __gcc_atomic::__to_gcc_order(__order)); |
| 846 | } |
| 847 | |
| 848 | template <typename _Tp> |
| 849 | static inline _Tp __c11_atomic_fetch_xor(_Atomic(_Tp)* __a, _Tp __pattern, |
JF Bastien | 4b72294 | 2018-05-26 19:44:45 +0000 | [diff] [blame] | 850 | memory_order __order) { |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 851 | return __atomic_fetch_xor(&__a->__a_value, __pattern, |
| 852 | __gcc_atomic::__to_gcc_order(__order)); |
| 853 | } |
Eric Fiselier | 00f4a49 | 2015-08-19 17:21:46 +0000 | [diff] [blame] | 854 | #endif // _LIBCPP_HAS_GCC_ATOMIC_IMP |
Dan Albert | e8b4232 | 2014-08-09 23:51:51 +0000 | [diff] [blame] | 855 | |
Howard Hinnant | d1176e2 | 2010-09-28 17:13:38 +0000 | [diff] [blame] | 856 | template <class _Tp> |
| 857 | inline _LIBCPP_INLINE_VISIBILITY |
| 858 | _Tp |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 859 | kill_dependency(_Tp __y) _NOEXCEPT |
Howard Hinnant | d1176e2 | 2010-09-28 17:13:38 +0000 | [diff] [blame] | 860 | { |
| 861 | return __y; |
| 862 | } |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 863 | |
Eric Fiselier | a67beb7 | 2017-04-20 23:22:46 +0000 | [diff] [blame] | 864 | #if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE) |
| 865 | # define ATOMIC_BOOL_LOCK_FREE __CLANG_ATOMIC_BOOL_LOCK_FREE |
| 866 | # define ATOMIC_CHAR_LOCK_FREE __CLANG_ATOMIC_CHAR_LOCK_FREE |
| 867 | # define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE |
| 868 | # define ATOMIC_CHAR32_T_LOCK_FREE __CLANG_ATOMIC_CHAR32_T_LOCK_FREE |
| 869 | # define ATOMIC_WCHAR_T_LOCK_FREE __CLANG_ATOMIC_WCHAR_T_LOCK_FREE |
| 870 | # define ATOMIC_SHORT_LOCK_FREE __CLANG_ATOMIC_SHORT_LOCK_FREE |
| 871 | # define ATOMIC_INT_LOCK_FREE __CLANG_ATOMIC_INT_LOCK_FREE |
| 872 | # define ATOMIC_LONG_LOCK_FREE __CLANG_ATOMIC_LONG_LOCK_FREE |
| 873 | # define ATOMIC_LLONG_LOCK_FREE __CLANG_ATOMIC_LLONG_LOCK_FREE |
| 874 | # define ATOMIC_POINTER_LOCK_FREE __CLANG_ATOMIC_POINTER_LOCK_FREE |
| 875 | #else |
| 876 | # define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE |
| 877 | # define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE |
| 878 | # define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE |
| 879 | # define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE |
| 880 | # define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE |
| 881 | # define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE |
| 882 | # define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE |
| 883 | # define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE |
| 884 | # define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE |
| 885 | # define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE |
| 886 | #endif |
JF Bastien | 08511cd | 2016-03-25 15:48:21 +0000 | [diff] [blame] | 887 | |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 888 | // general atomic<T> |
| 889 | |
| 890 | template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value> |
| 891 | struct __atomic_base // false |
| 892 | { |
Howard Hinnant | 7eb9f1e | 2012-09-16 20:33:09 +0000 | [diff] [blame] | 893 | mutable _Atomic(_Tp) __a_; |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 894 | |
JF Bastien | 08511cd | 2016-03-25 15:48:21 +0000 | [diff] [blame] | 895 | #if defined(__cpp_lib_atomic_is_always_lock_free) |
| 896 | static _LIBCPP_CONSTEXPR bool is_always_lock_free = __atomic_always_lock_free(sizeof(__a_), 0); |
| 897 | #endif |
| 898 | |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 899 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 900 | bool is_lock_free() const volatile _NOEXCEPT |
Eric Fiselier | 7726a34 | 2015-06-13 00:23:07 +0000 | [diff] [blame] | 901 | { |
Eric Fiselier | 00f4a49 | 2015-08-19 17:21:46 +0000 | [diff] [blame] | 902 | #if defined(_LIBCPP_HAS_C_ATOMIC_IMP) |
Eric Fiselier | 7726a34 | 2015-06-13 00:23:07 +0000 | [diff] [blame] | 903 | return __c11_atomic_is_lock_free(sizeof(_Tp)); |
| 904 | #else |
| 905 | return __atomic_is_lock_free(sizeof(_Tp), 0); |
| 906 | #endif |
| 907 | } |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 908 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 909 | bool is_lock_free() const _NOEXCEPT |
Eric Fiselier | 7726a34 | 2015-06-13 00:23:07 +0000 | [diff] [blame] | 910 | {return static_cast<__atomic_base const volatile*>(this)->is_lock_free();} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 911 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 912 | void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Eric Fiselier | 5ed7675 | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 913 | _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 914 | {__c11_atomic_store(&__a_, __d, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 915 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 916 | void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Eric Fiselier | 5ed7675 | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 917 | _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 918 | {__c11_atomic_store(&__a_, __d, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 919 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 920 | _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT |
Eric Fiselier | 5ed7675 | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 921 | _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 922 | {return __c11_atomic_load(&__a_, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 923 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 924 | _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT |
Eric Fiselier | 5ed7675 | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 925 | _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 926 | {return __c11_atomic_load(&__a_, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 927 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 928 | operator _Tp() const volatile _NOEXCEPT {return load();} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 929 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 930 | operator _Tp() const _NOEXCEPT {return load();} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 931 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 932 | _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 933 | {return __c11_atomic_exchange(&__a_, __d, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 934 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 935 | _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 936 | {return __c11_atomic_exchange(&__a_, __d, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 937 | _LIBCPP_INLINE_VISIBILITY |
| 938 | bool compare_exchange_weak(_Tp& __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 939 | memory_order __s, memory_order __f) volatile _NOEXCEPT |
Eric Fiselier | 5ed7675 | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 940 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 941 | {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 942 | _LIBCPP_INLINE_VISIBILITY |
| 943 | bool compare_exchange_weak(_Tp& __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 944 | memory_order __s, memory_order __f) _NOEXCEPT |
Eric Fiselier | 5ed7675 | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 945 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 946 | {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 947 | _LIBCPP_INLINE_VISIBILITY |
| 948 | bool compare_exchange_strong(_Tp& __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 949 | memory_order __s, memory_order __f) volatile _NOEXCEPT |
Eric Fiselier | 5ed7675 | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 950 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 951 | {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 952 | _LIBCPP_INLINE_VISIBILITY |
| 953 | bool compare_exchange_strong(_Tp& __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 954 | memory_order __s, memory_order __f) _NOEXCEPT |
Eric Fiselier | 5ed7675 | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 955 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 956 | {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 957 | _LIBCPP_INLINE_VISIBILITY |
| 958 | bool compare_exchange_weak(_Tp& __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 959 | memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 960 | {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 961 | _LIBCPP_INLINE_VISIBILITY |
| 962 | bool compare_exchange_weak(_Tp& __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 963 | memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 964 | {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 965 | _LIBCPP_INLINE_VISIBILITY |
| 966 | bool compare_exchange_strong(_Tp& __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 967 | memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 968 | {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 969 | _LIBCPP_INLINE_VISIBILITY |
| 970 | bool compare_exchange_strong(_Tp& __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 971 | memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 972 | {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 973 | |
| 974 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 8c57032 | 2016-11-18 06:42:17 +0000 | [diff] [blame] | 975 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 74f4da7 | 2013-05-02 20:18:43 +0000 | [diff] [blame] | 976 | __atomic_base() _NOEXCEPT = default; |
| 977 | #else |
| 978 | __atomic_base() _NOEXCEPT : __a_() {} |
Eric Fiselier | 8c57032 | 2016-11-18 06:42:17 +0000 | [diff] [blame] | 979 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 74f4da7 | 2013-05-02 20:18:43 +0000 | [diff] [blame] | 980 | |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 981 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 982 | _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {} |
Eric Fiselier | 8eb066a | 2017-01-06 20:58:25 +0000 | [diff] [blame] | 983 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 984 | __atomic_base(const __atomic_base&) = delete; |
| 985 | __atomic_base& operator=(const __atomic_base&) = delete; |
| 986 | __atomic_base& operator=(const __atomic_base&) volatile = delete; |
Eric Fiselier | 8eb066a | 2017-01-06 20:58:25 +0000 | [diff] [blame] | 987 | #else |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 988 | private: |
| 989 | __atomic_base(const __atomic_base&); |
| 990 | __atomic_base& operator=(const __atomic_base&); |
| 991 | __atomic_base& operator=(const __atomic_base&) volatile; |
Eric Fiselier | 8eb066a | 2017-01-06 20:58:25 +0000 | [diff] [blame] | 992 | #endif |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 993 | }; |
| 994 | |
JF Bastien | 08511cd | 2016-03-25 15:48:21 +0000 | [diff] [blame] | 995 | #if defined(__cpp_lib_atomic_is_always_lock_free) |
| 996 | template <class _Tp, bool __b> |
| 997 | _LIBCPP_CONSTEXPR bool __atomic_base<_Tp, __b>::is_always_lock_free; |
| 998 | #endif |
| 999 | |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1000 | // atomic<Integral> |
| 1001 | |
| 1002 | template <class _Tp> |
| 1003 | struct __atomic_base<_Tp, true> |
| 1004 | : public __atomic_base<_Tp, false> |
| 1005 | { |
| 1006 | typedef __atomic_base<_Tp, false> __base; |
| 1007 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 74f4da7 | 2013-05-02 20:18:43 +0000 | [diff] [blame] | 1008 | __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1009 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1010 | _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1011 | |
| 1012 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1013 | _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1014 | {return __c11_atomic_fetch_add(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1015 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1016 | _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1017 | {return __c11_atomic_fetch_add(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1018 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1019 | _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1020 | {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1021 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1022 | _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1023 | {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1024 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1025 | _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1026 | {return __c11_atomic_fetch_and(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1027 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1028 | _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1029 | {return __c11_atomic_fetch_and(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1030 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1031 | _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1032 | {return __c11_atomic_fetch_or(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1033 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1034 | _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1035 | {return __c11_atomic_fetch_or(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1036 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1037 | _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1038 | {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1039 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1040 | _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1041 | {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1042 | |
| 1043 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1044 | _Tp operator++(int) volatile _NOEXCEPT {return fetch_add(_Tp(1));} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1045 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1046 | _Tp operator++(int) _NOEXCEPT {return fetch_add(_Tp(1));} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1047 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1048 | _Tp operator--(int) volatile _NOEXCEPT {return fetch_sub(_Tp(1));} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1049 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1050 | _Tp operator--(int) _NOEXCEPT {return fetch_sub(_Tp(1));} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1051 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1052 | _Tp operator++() volatile _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1053 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1054 | _Tp operator++() _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1055 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1056 | _Tp operator--() volatile _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1057 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1058 | _Tp operator--() _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1059 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1060 | _Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1061 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1062 | _Tp operator+=(_Tp __op) _NOEXCEPT {return fetch_add(__op) + __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1063 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1064 | _Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1065 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1066 | _Tp operator-=(_Tp __op) _NOEXCEPT {return fetch_sub(__op) - __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1067 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1068 | _Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1069 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1070 | _Tp operator&=(_Tp __op) _NOEXCEPT {return fetch_and(__op) & __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1071 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1072 | _Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1073 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1074 | _Tp operator|=(_Tp __op) _NOEXCEPT {return fetch_or(__op) | __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1075 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1076 | _Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1077 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1078 | _Tp operator^=(_Tp __op) _NOEXCEPT {return fetch_xor(__op) ^ __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1079 | }; |
| 1080 | |
| 1081 | // atomic<T> |
| 1082 | |
| 1083 | template <class _Tp> |
| 1084 | struct atomic |
| 1085 | : public __atomic_base<_Tp> |
| 1086 | { |
| 1087 | typedef __atomic_base<_Tp> __base; |
| 1088 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 74f4da7 | 2013-05-02 20:18:43 +0000 | [diff] [blame] | 1089 | atomic() _NOEXCEPT _LIBCPP_DEFAULT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1090 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1091 | _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {} |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 1092 | |
| 1093 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1094 | _Tp operator=(_Tp __d) volatile _NOEXCEPT |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 1095 | {__base::store(__d); return __d;} |
| 1096 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1097 | _Tp operator=(_Tp __d) _NOEXCEPT |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 1098 | {__base::store(__d); return __d;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1099 | }; |
| 1100 | |
| 1101 | // atomic<T*> |
| 1102 | |
| 1103 | template <class _Tp> |
| 1104 | struct atomic<_Tp*> |
| 1105 | : public __atomic_base<_Tp*> |
| 1106 | { |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 1107 | typedef __atomic_base<_Tp*> __base; |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1108 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 74f4da7 | 2013-05-02 20:18:43 +0000 | [diff] [blame] | 1109 | atomic() _NOEXCEPT _LIBCPP_DEFAULT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1110 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1111 | _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1112 | |
| 1113 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1114 | _Tp* operator=(_Tp* __d) volatile _NOEXCEPT |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 1115 | {__base::store(__d); return __d;} |
| 1116 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1117 | _Tp* operator=(_Tp* __d) _NOEXCEPT |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 1118 | {__base::store(__d); return __d;} |
| 1119 | |
| 1120 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1121 | _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1122 | volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1123 | {return __c11_atomic_fetch_add(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1124 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1125 | _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1126 | {return __c11_atomic_fetch_add(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1127 | _LIBCPP_INLINE_VISIBILITY |
| 1128 | _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1129 | volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1130 | {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1131 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1132 | _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1133 | {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1134 | |
| 1135 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1136 | _Tp* operator++(int) volatile _NOEXCEPT {return fetch_add(1);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1137 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1138 | _Tp* operator++(int) _NOEXCEPT {return fetch_add(1);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1139 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1140 | _Tp* operator--(int) volatile _NOEXCEPT {return fetch_sub(1);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1141 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1142 | _Tp* operator--(int) _NOEXCEPT {return fetch_sub(1);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1143 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1144 | _Tp* operator++() volatile _NOEXCEPT {return fetch_add(1) + 1;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1145 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1146 | _Tp* operator++() _NOEXCEPT {return fetch_add(1) + 1;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1147 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1148 | _Tp* operator--() volatile _NOEXCEPT {return fetch_sub(1) - 1;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1149 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1150 | _Tp* operator--() _NOEXCEPT {return fetch_sub(1) - 1;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1151 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1152 | _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1153 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1154 | _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT {return fetch_add(__op) + __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1155 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1156 | _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1157 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1158 | _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT {return fetch_sub(__op) - __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1159 | }; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1160 | |
| 1161 | // atomic_is_lock_free |
| 1162 | |
| 1163 | template <class _Tp> |
| 1164 | inline _LIBCPP_INLINE_VISIBILITY |
| 1165 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1166 | atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1167 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1168 | return __o->is_lock_free(); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | template <class _Tp> |
| 1172 | inline _LIBCPP_INLINE_VISIBILITY |
| 1173 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1174 | atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1175 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1176 | return __o->is_lock_free(); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | // atomic_init |
| 1180 | |
| 1181 | template <class _Tp> |
| 1182 | inline _LIBCPP_INLINE_VISIBILITY |
| 1183 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1184 | atomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1185 | { |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1186 | __c11_atomic_init(&__o->__a_, __d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | template <class _Tp> |
| 1190 | inline _LIBCPP_INLINE_VISIBILITY |
| 1191 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1192 | atomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1193 | { |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1194 | __c11_atomic_init(&__o->__a_, __d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | // atomic_store |
| 1198 | |
| 1199 | template <class _Tp> |
| 1200 | inline _LIBCPP_INLINE_VISIBILITY |
| 1201 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1202 | atomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1203 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1204 | __o->store(__d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | template <class _Tp> |
| 1208 | inline _LIBCPP_INLINE_VISIBILITY |
| 1209 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1210 | atomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1211 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1212 | __o->store(__d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | // atomic_store_explicit |
| 1216 | |
| 1217 | template <class _Tp> |
| 1218 | inline _LIBCPP_INLINE_VISIBILITY |
| 1219 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1220 | atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT |
Eric Fiselier | 5ed7675 | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1221 | _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1222 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1223 | __o->store(__d, __m); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | template <class _Tp> |
| 1227 | inline _LIBCPP_INLINE_VISIBILITY |
| 1228 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1229 | atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT |
Eric Fiselier | 5ed7675 | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1230 | _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1231 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1232 | __o->store(__d, __m); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | // atomic_load |
| 1236 | |
| 1237 | template <class _Tp> |
| 1238 | inline _LIBCPP_INLINE_VISIBILITY |
| 1239 | _Tp |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1240 | atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1241 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1242 | return __o->load(); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | template <class _Tp> |
| 1246 | inline _LIBCPP_INLINE_VISIBILITY |
| 1247 | _Tp |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1248 | atomic_load(const atomic<_Tp>* __o) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1249 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1250 | return __o->load(); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | // atomic_load_explicit |
| 1254 | |
| 1255 | template <class _Tp> |
| 1256 | inline _LIBCPP_INLINE_VISIBILITY |
| 1257 | _Tp |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1258 | atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT |
Eric Fiselier | 5ed7675 | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1259 | _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1260 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1261 | return __o->load(__m); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | template <class _Tp> |
| 1265 | inline _LIBCPP_INLINE_VISIBILITY |
| 1266 | _Tp |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1267 | atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT |
Eric Fiselier | 5ed7675 | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1268 | _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1269 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1270 | return __o->load(__m); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | // atomic_exchange |
| 1274 | |
| 1275 | template <class _Tp> |
| 1276 | inline _LIBCPP_INLINE_VISIBILITY |
| 1277 | _Tp |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1278 | atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1279 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1280 | return __o->exchange(__d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | template <class _Tp> |
| 1284 | inline _LIBCPP_INLINE_VISIBILITY |
| 1285 | _Tp |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1286 | atomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1287 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1288 | return __o->exchange(__d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | // atomic_exchange_explicit |
| 1292 | |
| 1293 | template <class _Tp> |
| 1294 | inline _LIBCPP_INLINE_VISIBILITY |
| 1295 | _Tp |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1296 | atomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1297 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1298 | return __o->exchange(__d, __m); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | template <class _Tp> |
| 1302 | inline _LIBCPP_INLINE_VISIBILITY |
| 1303 | _Tp |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1304 | atomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1305 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1306 | return __o->exchange(__d, __m); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | // atomic_compare_exchange_weak |
| 1310 | |
| 1311 | template <class _Tp> |
| 1312 | inline _LIBCPP_INLINE_VISIBILITY |
| 1313 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1314 | atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1315 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1316 | return __o->compare_exchange_weak(*__e, __d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | template <class _Tp> |
| 1320 | inline _LIBCPP_INLINE_VISIBILITY |
| 1321 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1322 | atomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1323 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1324 | return __o->compare_exchange_weak(*__e, __d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | // atomic_compare_exchange_strong |
| 1328 | |
| 1329 | template <class _Tp> |
| 1330 | inline _LIBCPP_INLINE_VISIBILITY |
| 1331 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1332 | atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1333 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1334 | return __o->compare_exchange_strong(*__e, __d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | template <class _Tp> |
| 1338 | inline _LIBCPP_INLINE_VISIBILITY |
| 1339 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1340 | atomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1341 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1342 | return __o->compare_exchange_strong(*__e, __d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | // atomic_compare_exchange_weak_explicit |
| 1346 | |
| 1347 | template <class _Tp> |
| 1348 | inline _LIBCPP_INLINE_VISIBILITY |
| 1349 | bool |
| 1350 | atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e, |
| 1351 | _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1352 | memory_order __s, memory_order __f) _NOEXCEPT |
Eric Fiselier | 5ed7675 | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1353 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1354 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1355 | return __o->compare_exchange_weak(*__e, __d, __s, __f); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | template <class _Tp> |
| 1359 | inline _LIBCPP_INLINE_VISIBILITY |
| 1360 | bool |
| 1361 | atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1362 | memory_order __s, memory_order __f) _NOEXCEPT |
Eric Fiselier | 5ed7675 | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1363 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1364 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1365 | return __o->compare_exchange_weak(*__e, __d, __s, __f); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | // atomic_compare_exchange_strong_explicit |
| 1369 | |
| 1370 | template <class _Tp> |
| 1371 | inline _LIBCPP_INLINE_VISIBILITY |
| 1372 | bool |
| 1373 | atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o, |
| 1374 | _Tp* __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1375 | memory_order __s, memory_order __f) _NOEXCEPT |
Eric Fiselier | 5ed7675 | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1376 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1377 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1378 | return __o->compare_exchange_strong(*__e, __d, __s, __f); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | template <class _Tp> |
| 1382 | inline _LIBCPP_INLINE_VISIBILITY |
| 1383 | bool |
| 1384 | atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e, |
| 1385 | _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1386 | memory_order __s, memory_order __f) _NOEXCEPT |
Eric Fiselier | 5ed7675 | 2017-01-13 23:45:39 +0000 | [diff] [blame] | 1387 | _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1388 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1389 | return __o->compare_exchange_strong(*__e, __d, __s, __f); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1392 | // atomic_fetch_add |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1393 | |
| 1394 | template <class _Tp> |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1395 | inline _LIBCPP_INLINE_VISIBILITY |
| 1396 | typename enable_if |
| 1397 | < |
| 1398 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1399 | _Tp |
| 1400 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1401 | atomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1402 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1403 | return __o->fetch_add(__op); |
| 1404 | } |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1405 | |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1406 | template <class _Tp> |
| 1407 | inline _LIBCPP_INLINE_VISIBILITY |
| 1408 | typename enable_if |
| 1409 | < |
| 1410 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1411 | _Tp |
| 1412 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1413 | atomic_fetch_add(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1414 | { |
| 1415 | return __o->fetch_add(__op); |
| 1416 | } |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1417 | |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1418 | template <class _Tp> |
| 1419 | inline _LIBCPP_INLINE_VISIBILITY |
| 1420 | _Tp* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1421 | atomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1422 | { |
| 1423 | return __o->fetch_add(__op); |
| 1424 | } |
| 1425 | |
| 1426 | template <class _Tp> |
| 1427 | inline _LIBCPP_INLINE_VISIBILITY |
| 1428 | _Tp* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1429 | atomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1430 | { |
| 1431 | return __o->fetch_add(__op); |
| 1432 | } |
| 1433 | |
| 1434 | // atomic_fetch_add_explicit |
| 1435 | |
| 1436 | template <class _Tp> |
| 1437 | inline _LIBCPP_INLINE_VISIBILITY |
| 1438 | typename enable_if |
| 1439 | < |
| 1440 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1441 | _Tp |
| 1442 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1443 | atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1444 | { |
| 1445 | return __o->fetch_add(__op, __m); |
| 1446 | } |
| 1447 | |
| 1448 | template <class _Tp> |
| 1449 | inline _LIBCPP_INLINE_VISIBILITY |
| 1450 | typename enable_if |
| 1451 | < |
| 1452 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1453 | _Tp |
| 1454 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1455 | atomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1456 | { |
| 1457 | return __o->fetch_add(__op, __m); |
| 1458 | } |
| 1459 | |
| 1460 | template <class _Tp> |
| 1461 | inline _LIBCPP_INLINE_VISIBILITY |
| 1462 | _Tp* |
| 1463 | atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1464 | memory_order __m) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1465 | { |
| 1466 | return __o->fetch_add(__op, __m); |
| 1467 | } |
| 1468 | |
| 1469 | template <class _Tp> |
| 1470 | inline _LIBCPP_INLINE_VISIBILITY |
| 1471 | _Tp* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1472 | atomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1473 | { |
| 1474 | return __o->fetch_add(__op, __m); |
| 1475 | } |
| 1476 | |
| 1477 | // atomic_fetch_sub |
| 1478 | |
| 1479 | template <class _Tp> |
| 1480 | inline _LIBCPP_INLINE_VISIBILITY |
| 1481 | typename enable_if |
| 1482 | < |
| 1483 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1484 | _Tp |
| 1485 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1486 | atomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1487 | { |
| 1488 | return __o->fetch_sub(__op); |
| 1489 | } |
| 1490 | |
| 1491 | template <class _Tp> |
| 1492 | inline _LIBCPP_INLINE_VISIBILITY |
| 1493 | typename enable_if |
| 1494 | < |
| 1495 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1496 | _Tp |
| 1497 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1498 | atomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1499 | { |
| 1500 | return __o->fetch_sub(__op); |
| 1501 | } |
| 1502 | |
| 1503 | template <class _Tp> |
| 1504 | inline _LIBCPP_INLINE_VISIBILITY |
| 1505 | _Tp* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1506 | atomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1507 | { |
| 1508 | return __o->fetch_sub(__op); |
| 1509 | } |
| 1510 | |
| 1511 | template <class _Tp> |
| 1512 | inline _LIBCPP_INLINE_VISIBILITY |
| 1513 | _Tp* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1514 | atomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1515 | { |
| 1516 | return __o->fetch_sub(__op); |
| 1517 | } |
| 1518 | |
| 1519 | // atomic_fetch_sub_explicit |
| 1520 | |
| 1521 | template <class _Tp> |
| 1522 | inline _LIBCPP_INLINE_VISIBILITY |
| 1523 | typename enable_if |
| 1524 | < |
| 1525 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1526 | _Tp |
| 1527 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1528 | atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1529 | { |
| 1530 | return __o->fetch_sub(__op, __m); |
| 1531 | } |
| 1532 | |
| 1533 | template <class _Tp> |
| 1534 | inline _LIBCPP_INLINE_VISIBILITY |
| 1535 | typename enable_if |
| 1536 | < |
| 1537 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1538 | _Tp |
| 1539 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1540 | atomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1541 | { |
| 1542 | return __o->fetch_sub(__op, __m); |
| 1543 | } |
| 1544 | |
| 1545 | template <class _Tp> |
| 1546 | inline _LIBCPP_INLINE_VISIBILITY |
| 1547 | _Tp* |
| 1548 | atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1549 | memory_order __m) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1550 | { |
| 1551 | return __o->fetch_sub(__op, __m); |
| 1552 | } |
| 1553 | |
| 1554 | template <class _Tp> |
| 1555 | inline _LIBCPP_INLINE_VISIBILITY |
| 1556 | _Tp* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1557 | atomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1558 | { |
| 1559 | return __o->fetch_sub(__op, __m); |
| 1560 | } |
| 1561 | |
| 1562 | // atomic_fetch_and |
| 1563 | |
| 1564 | template <class _Tp> |
| 1565 | inline _LIBCPP_INLINE_VISIBILITY |
| 1566 | typename enable_if |
| 1567 | < |
| 1568 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1569 | _Tp |
| 1570 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1571 | atomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1572 | { |
| 1573 | return __o->fetch_and(__op); |
| 1574 | } |
| 1575 | |
| 1576 | template <class _Tp> |
| 1577 | inline _LIBCPP_INLINE_VISIBILITY |
| 1578 | typename enable_if |
| 1579 | < |
| 1580 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1581 | _Tp |
| 1582 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1583 | atomic_fetch_and(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1584 | { |
| 1585 | return __o->fetch_and(__op); |
| 1586 | } |
| 1587 | |
| 1588 | // atomic_fetch_and_explicit |
| 1589 | |
| 1590 | template <class _Tp> |
| 1591 | inline _LIBCPP_INLINE_VISIBILITY |
| 1592 | typename enable_if |
| 1593 | < |
| 1594 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1595 | _Tp |
| 1596 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1597 | atomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1598 | { |
| 1599 | return __o->fetch_and(__op, __m); |
| 1600 | } |
| 1601 | |
| 1602 | template <class _Tp> |
| 1603 | inline _LIBCPP_INLINE_VISIBILITY |
| 1604 | typename enable_if |
| 1605 | < |
| 1606 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1607 | _Tp |
| 1608 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1609 | atomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1610 | { |
| 1611 | return __o->fetch_and(__op, __m); |
| 1612 | } |
| 1613 | |
| 1614 | // atomic_fetch_or |
| 1615 | |
| 1616 | template <class _Tp> |
| 1617 | inline _LIBCPP_INLINE_VISIBILITY |
| 1618 | typename enable_if |
| 1619 | < |
| 1620 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1621 | _Tp |
| 1622 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1623 | atomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1624 | { |
| 1625 | return __o->fetch_or(__op); |
| 1626 | } |
| 1627 | |
| 1628 | template <class _Tp> |
| 1629 | inline _LIBCPP_INLINE_VISIBILITY |
| 1630 | typename enable_if |
| 1631 | < |
| 1632 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1633 | _Tp |
| 1634 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1635 | atomic_fetch_or(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1636 | { |
| 1637 | return __o->fetch_or(__op); |
| 1638 | } |
| 1639 | |
| 1640 | // atomic_fetch_or_explicit |
| 1641 | |
| 1642 | template <class _Tp> |
| 1643 | inline _LIBCPP_INLINE_VISIBILITY |
| 1644 | typename enable_if |
| 1645 | < |
| 1646 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1647 | _Tp |
| 1648 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1649 | atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1650 | { |
| 1651 | return __o->fetch_or(__op, __m); |
| 1652 | } |
| 1653 | |
| 1654 | template <class _Tp> |
| 1655 | inline _LIBCPP_INLINE_VISIBILITY |
| 1656 | typename enable_if |
| 1657 | < |
| 1658 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1659 | _Tp |
| 1660 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1661 | atomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1662 | { |
| 1663 | return __o->fetch_or(__op, __m); |
| 1664 | } |
| 1665 | |
| 1666 | // atomic_fetch_xor |
| 1667 | |
| 1668 | template <class _Tp> |
| 1669 | inline _LIBCPP_INLINE_VISIBILITY |
| 1670 | typename enable_if |
| 1671 | < |
| 1672 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1673 | _Tp |
| 1674 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1675 | atomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1676 | { |
| 1677 | return __o->fetch_xor(__op); |
| 1678 | } |
| 1679 | |
| 1680 | template <class _Tp> |
| 1681 | inline _LIBCPP_INLINE_VISIBILITY |
| 1682 | typename enable_if |
| 1683 | < |
| 1684 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1685 | _Tp |
| 1686 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1687 | atomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1688 | { |
| 1689 | return __o->fetch_xor(__op); |
| 1690 | } |
| 1691 | |
| 1692 | // atomic_fetch_xor_explicit |
| 1693 | |
| 1694 | template <class _Tp> |
| 1695 | inline _LIBCPP_INLINE_VISIBILITY |
| 1696 | typename enable_if |
| 1697 | < |
| 1698 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1699 | _Tp |
| 1700 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1701 | atomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1702 | { |
| 1703 | return __o->fetch_xor(__op, __m); |
| 1704 | } |
| 1705 | |
| 1706 | template <class _Tp> |
| 1707 | inline _LIBCPP_INLINE_VISIBILITY |
| 1708 | typename enable_if |
| 1709 | < |
| 1710 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1711 | _Tp |
| 1712 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1713 | atomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1714 | { |
| 1715 | return __o->fetch_xor(__op, __m); |
| 1716 | } |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1717 | |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1718 | // flag type and operations |
| 1719 | |
| 1720 | typedef struct atomic_flag |
| 1721 | { |
David Chisnall | 83b2c84 | 2011-12-19 11:44:20 +0000 | [diff] [blame] | 1722 | _Atomic(bool) __a_; |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1723 | |
| 1724 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1725 | bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1726 | {return __c11_atomic_exchange(&__a_, true, __m);} |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1727 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1728 | bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1729 | {return __c11_atomic_exchange(&__a_, true, __m);} |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1730 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1731 | void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1732 | {__c11_atomic_store(&__a_, false, __m);} |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1733 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1734 | void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1735 | {__c11_atomic_store(&__a_, false, __m);} |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1736 | |
| 1737 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 8c57032 | 2016-11-18 06:42:17 +0000 | [diff] [blame] | 1738 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 74f4da7 | 2013-05-02 20:18:43 +0000 | [diff] [blame] | 1739 | atomic_flag() _NOEXCEPT = default; |
| 1740 | #else |
| 1741 | atomic_flag() _NOEXCEPT : __a_() {} |
Eric Fiselier | 8c57032 | 2016-11-18 06:42:17 +0000 | [diff] [blame] | 1742 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 74f4da7 | 2013-05-02 20:18:43 +0000 | [diff] [blame] | 1743 | |
Marshall Clow | 727ed61 | 2018-04-25 14:27:29 +0000 | [diff] [blame] | 1744 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Eric Fiselier | 219406e | 2016-05-03 02:12:26 +0000 | [diff] [blame] | 1745 | atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1746 | |
Eric Fiselier | 8eb066a | 2017-01-06 20:58:25 +0000 | [diff] [blame] | 1747 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1748 | atomic_flag(const atomic_flag&) = delete; |
| 1749 | atomic_flag& operator=(const atomic_flag&) = delete; |
| 1750 | atomic_flag& operator=(const atomic_flag&) volatile = delete; |
Eric Fiselier | 8eb066a | 2017-01-06 20:58:25 +0000 | [diff] [blame] | 1751 | #else |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1752 | private: |
| 1753 | atomic_flag(const atomic_flag&); |
| 1754 | atomic_flag& operator=(const atomic_flag&); |
| 1755 | atomic_flag& operator=(const atomic_flag&) volatile; |
Eric Fiselier | 8eb066a | 2017-01-06 20:58:25 +0000 | [diff] [blame] | 1756 | #endif |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1757 | } atomic_flag; |
| 1758 | |
| 1759 | inline _LIBCPP_INLINE_VISIBILITY |
| 1760 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1761 | atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1762 | { |
| 1763 | return __o->test_and_set(); |
| 1764 | } |
| 1765 | |
| 1766 | inline _LIBCPP_INLINE_VISIBILITY |
| 1767 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1768 | atomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1769 | { |
| 1770 | return __o->test_and_set(); |
| 1771 | } |
| 1772 | |
| 1773 | inline _LIBCPP_INLINE_VISIBILITY |
| 1774 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1775 | atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1776 | { |
| 1777 | return __o->test_and_set(__m); |
| 1778 | } |
| 1779 | |
| 1780 | inline _LIBCPP_INLINE_VISIBILITY |
| 1781 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1782 | atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1783 | { |
| 1784 | return __o->test_and_set(__m); |
| 1785 | } |
| 1786 | |
| 1787 | inline _LIBCPP_INLINE_VISIBILITY |
| 1788 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1789 | atomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1790 | { |
| 1791 | __o->clear(); |
| 1792 | } |
| 1793 | |
| 1794 | inline _LIBCPP_INLINE_VISIBILITY |
| 1795 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1796 | atomic_flag_clear(atomic_flag* __o) _NOEXCEPT |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1797 | { |
| 1798 | __o->clear(); |
| 1799 | } |
| 1800 | |
| 1801 | inline _LIBCPP_INLINE_VISIBILITY |
| 1802 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1803 | atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1804 | { |
| 1805 | __o->clear(__m); |
| 1806 | } |
| 1807 | |
| 1808 | inline _LIBCPP_INLINE_VISIBILITY |
| 1809 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1810 | atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1811 | { |
| 1812 | __o->clear(__m); |
| 1813 | } |
| 1814 | |
| 1815 | // fences |
| 1816 | |
| 1817 | inline _LIBCPP_INLINE_VISIBILITY |
| 1818 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1819 | atomic_thread_fence(memory_order __m) _NOEXCEPT |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1820 | { |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1821 | __c11_atomic_thread_fence(__m); |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | inline _LIBCPP_INLINE_VISIBILITY |
| 1825 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1826 | atomic_signal_fence(memory_order __m) _NOEXCEPT |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1827 | { |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1828 | __c11_atomic_signal_fence(__m); |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 1831 | // Atomics for standard typedef types |
| 1832 | |
Howard Hinnant | 6ae4705 | 2013-01-04 18:58:50 +0000 | [diff] [blame] | 1833 | typedef atomic<bool> atomic_bool; |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 1834 | typedef atomic<char> atomic_char; |
| 1835 | typedef atomic<signed char> atomic_schar; |
| 1836 | typedef atomic<unsigned char> atomic_uchar; |
| 1837 | typedef atomic<short> atomic_short; |
| 1838 | typedef atomic<unsigned short> atomic_ushort; |
| 1839 | typedef atomic<int> atomic_int; |
| 1840 | typedef atomic<unsigned int> atomic_uint; |
| 1841 | typedef atomic<long> atomic_long; |
| 1842 | typedef atomic<unsigned long> atomic_ulong; |
| 1843 | typedef atomic<long long> atomic_llong; |
| 1844 | typedef atomic<unsigned long long> atomic_ullong; |
| 1845 | typedef atomic<char16_t> atomic_char16_t; |
| 1846 | typedef atomic<char32_t> atomic_char32_t; |
| 1847 | typedef atomic<wchar_t> atomic_wchar_t; |
| 1848 | |
| 1849 | typedef atomic<int_least8_t> atomic_int_least8_t; |
| 1850 | typedef atomic<uint_least8_t> atomic_uint_least8_t; |
| 1851 | typedef atomic<int_least16_t> atomic_int_least16_t; |
| 1852 | typedef atomic<uint_least16_t> atomic_uint_least16_t; |
| 1853 | typedef atomic<int_least32_t> atomic_int_least32_t; |
| 1854 | typedef atomic<uint_least32_t> atomic_uint_least32_t; |
| 1855 | typedef atomic<int_least64_t> atomic_int_least64_t; |
| 1856 | typedef atomic<uint_least64_t> atomic_uint_least64_t; |
| 1857 | |
| 1858 | typedef atomic<int_fast8_t> atomic_int_fast8_t; |
| 1859 | typedef atomic<uint_fast8_t> atomic_uint_fast8_t; |
| 1860 | typedef atomic<int_fast16_t> atomic_int_fast16_t; |
| 1861 | typedef atomic<uint_fast16_t> atomic_uint_fast16_t; |
| 1862 | typedef atomic<int_fast32_t> atomic_int_fast32_t; |
| 1863 | typedef atomic<uint_fast32_t> atomic_uint_fast32_t; |
| 1864 | typedef atomic<int_fast64_t> atomic_int_fast64_t; |
| 1865 | typedef atomic<uint_fast64_t> atomic_uint_fast64_t; |
| 1866 | |
Marshall Clow | ca89450 | 2016-06-30 15:28:38 +0000 | [diff] [blame] | 1867 | typedef atomic< int8_t> atomic_int8_t; |
| 1868 | typedef atomic<uint8_t> atomic_uint8_t; |
| 1869 | typedef atomic< int16_t> atomic_int16_t; |
| 1870 | typedef atomic<uint16_t> atomic_uint16_t; |
| 1871 | typedef atomic< int32_t> atomic_int32_t; |
| 1872 | typedef atomic<uint32_t> atomic_uint32_t; |
| 1873 | typedef atomic< int64_t> atomic_int64_t; |
| 1874 | typedef atomic<uint64_t> atomic_uint64_t; |
| 1875 | |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 1876 | typedef atomic<intptr_t> atomic_intptr_t; |
| 1877 | typedef atomic<uintptr_t> atomic_uintptr_t; |
| 1878 | typedef atomic<size_t> atomic_size_t; |
| 1879 | typedef atomic<ptrdiff_t> atomic_ptrdiff_t; |
| 1880 | typedef atomic<intmax_t> atomic_intmax_t; |
| 1881 | typedef atomic<uintmax_t> atomic_uintmax_t; |
| 1882 | |
Howard Hinnant | 767ae2b | 2010-09-29 21:20:03 +0000 | [diff] [blame] | 1883 | #define ATOMIC_FLAG_INIT {false} |
Howard Hinnant | 611fdaf | 2010-10-04 18:52:54 +0000 | [diff] [blame] | 1884 | #define ATOMIC_VAR_INIT(__v) {__v} |
| 1885 | |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 1886 | _LIBCPP_END_NAMESPACE_STD |
| 1887 | |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 1888 | #endif // _LIBCPP_ATOMIC |