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 | |
| 20 | // order and consistency |
| 21 | |
| 22 | typedef enum memory_order |
| 23 | { |
Howard Hinnant | d1176e2 | 2010-09-28 17:13:38 +0000 | [diff] [blame] | 24 | memory_order_relaxed, |
| 25 | memory_order_consume, // load-consume |
| 26 | memory_order_acquire, // load-acquire |
| 27 | memory_order_release, // store-release |
| 28 | memory_order_acq_rel, // store-release load-acquire |
| 29 | memory_order_seq_cst // store-release load-acquire |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 30 | } memory_order; |
| 31 | |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 32 | template <class T> T kill_dependency(T y) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 33 | |
| 34 | // lock-free property |
| 35 | |
| 36 | #define ATOMIC_CHAR_LOCK_FREE unspecified |
| 37 | #define ATOMIC_CHAR16_T_LOCK_FREE unspecified |
| 38 | #define ATOMIC_CHAR32_T_LOCK_FREE unspecified |
| 39 | #define ATOMIC_WCHAR_T_LOCK_FREE unspecified |
| 40 | #define ATOMIC_SHORT_LOCK_FREE unspecified |
| 41 | #define ATOMIC_INT_LOCK_FREE unspecified |
| 42 | #define ATOMIC_LONG_LOCK_FREE unspecified |
| 43 | #define ATOMIC_LLONG_LOCK_FREE unspecified |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 44 | |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 45 | // flag type and operations |
| 46 | |
| 47 | typedef struct atomic_flag |
| 48 | { |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 49 | bool test_and_set(memory_order m = memory_order_seq_cst) volatile noexcept; |
| 50 | bool test_and_set(memory_order m = memory_order_seq_cst) noexcept; |
| 51 | void clear(memory_order m = memory_order_seq_cst) volatile noexcept; |
| 52 | void clear(memory_order m = memory_order_seq_cst) noexcept; |
| 53 | atomic_flag() noexcept = default; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 54 | atomic_flag(const atomic_flag&) = delete; |
| 55 | atomic_flag& operator=(const atomic_flag&) = delete; |
| 56 | atomic_flag& operator=(const atomic_flag&) volatile = delete; |
| 57 | } atomic_flag; |
| 58 | |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 59 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 60 | atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 61 | |
| 62 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 63 | atomic_flag_test_and_set(atomic_flag* obj) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 64 | |
| 65 | bool |
| 66 | atomic_flag_test_and_set_explicit(volatile atomic_flag* obj, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 67 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 68 | |
| 69 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 70 | 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] | 71 | |
| 72 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 73 | atomic_flag_clear(volatile atomic_flag* obj) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 74 | |
| 75 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 76 | atomic_flag_clear(atomic_flag* obj) 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_explicit(volatile atomic_flag* obj, memory_order m) 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_explicit(atomic_flag* obj, memory_order m) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 83 | |
| 84 | #define ATOMIC_FLAG_INIT see below |
Howard Hinnant | e738501 | 2010-10-19 16:51:18 +0000 | [diff] [blame] | 85 | #define ATOMIC_VAR_INIT(value) see below |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 86 | |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 87 | template <class T> |
| 88 | struct atomic |
| 89 | { |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 90 | bool is_lock_free() const volatile noexcept; |
| 91 | bool is_lock_free() const noexcept; |
| 92 | void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 93 | void store(T desr, memory_order m = memory_order_seq_cst) noexcept; |
| 94 | T load(memory_order m = memory_order_seq_cst) const volatile noexcept; |
| 95 | T load(memory_order m = memory_order_seq_cst) const noexcept; |
| 96 | operator T() const volatile noexcept; |
| 97 | operator T() const noexcept; |
| 98 | T exchange(T desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 99 | T exchange(T desr, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 100 | bool compare_exchange_weak(T& expc, T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 101 | memory_order s, memory_order f) volatile noexcept; |
| 102 | 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] | 103 | bool compare_exchange_strong(T& expc, T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 104 | memory_order s, memory_order f) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 105 | bool compare_exchange_strong(T& expc, T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 106 | memory_order s, memory_order f) 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 m = memory_order_seq_cst) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 109 | bool compare_exchange_weak(T& expc, T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 110 | memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 111 | bool compare_exchange_strong(T& expc, T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 112 | memory_order m = memory_order_seq_cst) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 113 | bool compare_exchange_strong(T& expc, T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 114 | memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 115 | |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 116 | atomic() noexcept = default; |
| 117 | constexpr atomic(T desr) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 118 | atomic(const atomic&) = delete; |
| 119 | atomic& operator=(const atomic&) = delete; |
| 120 | atomic& operator=(const atomic&) volatile = delete; |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 121 | T operator=(T) volatile noexcept; |
| 122 | T operator=(T) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | template <> |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 126 | struct atomic<integral> |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 127 | { |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 128 | bool is_lock_free() const volatile noexcept; |
| 129 | bool is_lock_free() const noexcept; |
| 130 | void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 131 | void store(integral desr, memory_order m = memory_order_seq_cst) noexcept; |
| 132 | integral load(memory_order m = memory_order_seq_cst) const volatile noexcept; |
| 133 | integral load(memory_order m = memory_order_seq_cst) const noexcept; |
| 134 | operator integral() const volatile noexcept; |
| 135 | operator integral() const noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 136 | integral exchange(integral desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 137 | memory_order m = memory_order_seq_cst) volatile noexcept; |
| 138 | integral exchange(integral desr, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 139 | bool compare_exchange_weak(integral& expc, integral desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 140 | memory_order s, memory_order f) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 141 | bool compare_exchange_weak(integral& expc, integral desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 142 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 143 | bool compare_exchange_strong(integral& expc, integral desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 144 | memory_order s, memory_order f) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 145 | bool compare_exchange_strong(integral& expc, integral desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 146 | memory_order s, memory_order f) 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 m = memory_order_seq_cst) 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 m = memory_order_seq_cst) 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 m = memory_order_seq_cst) 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 m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 155 | |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 156 | integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 157 | fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 158 | integral fetch_add(integral op, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 159 | integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 160 | fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 161 | 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] | 162 | integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 163 | fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 164 | 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] | 165 | integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 166 | fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 167 | 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] | 168 | integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 169 | fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 170 | 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] | 171 | |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 172 | atomic() noexcept = default; |
| 173 | constexpr atomic(integral desr) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 174 | atomic(const atomic&) = delete; |
| 175 | atomic& operator=(const atomic&) = delete; |
| 176 | atomic& operator=(const atomic&) volatile = delete; |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 177 | integral operator=(integral desr) volatile noexcept; |
| 178 | integral operator=(integral desr) 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 | integral operator++(int) volatile noexcept; |
| 181 | integral operator++(int) noexcept; |
| 182 | integral operator--(int) volatile noexcept; |
| 183 | integral operator--(int) noexcept; |
| 184 | integral operator++() volatile noexcept; |
| 185 | integral operator++() noexcept; |
| 186 | integral operator--() volatile noexcept; |
| 187 | integral operator--() noexcept; |
| 188 | integral operator+=(integral op) volatile noexcept; |
| 189 | integral operator+=(integral op) noexcept; |
| 190 | integral operator-=(integral op) volatile noexcept; |
| 191 | integral operator-=(integral op) noexcept; |
| 192 | integral operator&=(integral op) volatile noexcept; |
| 193 | integral operator&=(integral op) noexcept; |
| 194 | integral operator|=(integral op) volatile noexcept; |
| 195 | integral operator|=(integral op) noexcept; |
| 196 | integral operator^=(integral op) volatile noexcept; |
| 197 | integral operator^=(integral op) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | template <class T> |
| 201 | struct atomic<T*> |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 202 | { |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 203 | bool is_lock_free() const volatile noexcept; |
| 204 | bool is_lock_free() const noexcept; |
| 205 | void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 206 | void store(T* desr, memory_order m = memory_order_seq_cst) noexcept; |
| 207 | T* load(memory_order m = memory_order_seq_cst) const volatile noexcept; |
| 208 | T* load(memory_order m = memory_order_seq_cst) const noexcept; |
| 209 | operator T*() const volatile noexcept; |
| 210 | operator T*() const noexcept; |
| 211 | T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 212 | T* exchange(T* desr, memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 213 | bool compare_exchange_weak(T*& expc, T* desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 214 | memory_order s, memory_order f) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 215 | bool compare_exchange_weak(T*& expc, T* desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 216 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 217 | bool compare_exchange_strong(T*& expc, T* desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 218 | memory_order s, memory_order f) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 219 | bool compare_exchange_strong(T*& expc, T* desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 220 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 221 | bool compare_exchange_weak(T*& expc, T* desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 222 | memory_order m = memory_order_seq_cst) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 223 | bool compare_exchange_weak(T*& expc, T* desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 224 | memory_order m = memory_order_seq_cst) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 225 | bool compare_exchange_strong(T*& expc, T* desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 226 | memory_order m = memory_order_seq_cst) volatile noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 227 | bool compare_exchange_strong(T*& expc, T* desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 228 | memory_order m = memory_order_seq_cst) noexcept; |
| 229 | T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 230 | T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept; |
| 231 | T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept; |
| 232 | 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] | 233 | |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 234 | atomic() noexcept = default; |
| 235 | constexpr atomic(T* desr) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 236 | atomic(const atomic&) = delete; |
| 237 | atomic& operator=(const atomic&) = delete; |
| 238 | atomic& operator=(const atomic&) volatile = delete; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 239 | |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 240 | T* operator=(T*) volatile noexcept; |
| 241 | T* operator=(T*) noexcept; |
| 242 | T* operator++(int) volatile noexcept; |
| 243 | T* operator++(int) noexcept; |
| 244 | T* operator--(int) volatile noexcept; |
| 245 | T* operator--(int) noexcept; |
| 246 | T* operator++() volatile noexcept; |
| 247 | T* operator++() noexcept; |
| 248 | T* operator--() volatile noexcept; |
| 249 | T* operator--() noexcept; |
| 250 | T* operator+=(ptrdiff_t op) volatile noexcept; |
| 251 | T* operator+=(ptrdiff_t op) noexcept; |
| 252 | T* operator-=(ptrdiff_t op) volatile noexcept; |
| 253 | T* operator-=(ptrdiff_t op) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 254 | }; |
| 255 | |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 256 | |
| 257 | template <class T> |
| 258 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 259 | atomic_is_lock_free(const volatile atomic<T>* obj) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 260 | |
| 261 | template <class T> |
| 262 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 263 | atomic_is_lock_free(const atomic<T>* obj) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 264 | |
| 265 | template <class T> |
| 266 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 267 | atomic_init(volatile atomic<T>* obj, T desr) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 268 | |
| 269 | template <class T> |
| 270 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 271 | atomic_init(atomic<T>* obj, T desr) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 272 | |
| 273 | template <class T> |
| 274 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 275 | atomic_store(volatile atomic<T>* obj, T desr) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 276 | |
| 277 | template <class T> |
| 278 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 279 | atomic_store(atomic<T>* obj, T desr) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 280 | |
| 281 | template <class T> |
| 282 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 283 | 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] | 284 | |
| 285 | template <class T> |
| 286 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 287 | atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 288 | |
| 289 | template <class T> |
| 290 | T |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 291 | atomic_load(const volatile atomic<T>* obj) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 292 | |
| 293 | template <class T> |
| 294 | T |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 295 | atomic_load(const atomic<T>* obj) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 296 | |
| 297 | template <class T> |
| 298 | T |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 299 | atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 300 | |
| 301 | template <class T> |
| 302 | T |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 303 | atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 304 | |
| 305 | template <class T> |
| 306 | T |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 307 | atomic_exchange(volatile atomic<T>* obj, T desr) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 308 | |
| 309 | template <class T> |
| 310 | T |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 311 | atomic_exchange(atomic<T>* obj, T desr) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 312 | |
| 313 | template <class T> |
| 314 | T |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 315 | 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] | 316 | |
| 317 | template <class T> |
| 318 | T |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 319 | atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 320 | |
| 321 | template <class T> |
| 322 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 323 | 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] | 324 | |
| 325 | template <class T> |
| 326 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 327 | atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 328 | |
| 329 | template <class T> |
| 330 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 331 | 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] | 332 | |
| 333 | template <class T> |
| 334 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 335 | atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 336 | |
| 337 | template <class T> |
| 338 | bool |
| 339 | atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc, |
| 340 | T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 341 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 342 | |
| 343 | template <class T> |
| 344 | bool |
| 345 | atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 346 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 347 | |
| 348 | template <class T> |
| 349 | bool |
| 350 | atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj, |
| 351 | T* expc, T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 352 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 353 | |
| 354 | template <class T> |
| 355 | bool |
| 356 | atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc, |
| 357 | T desr, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 358 | memory_order s, memory_order f) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 359 | |
| 360 | template <class Integral> |
| 361 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 362 | atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 363 | |
| 364 | template <class Integral> |
| 365 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 366 | atomic_fetch_add(atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 367 | |
| 368 | template <class Integral> |
| 369 | Integral |
| 370 | atomic_fetch_add_explicit(volatile atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 371 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 372 | template <class Integral> |
| 373 | Integral |
| 374 | atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 375 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 376 | template <class Integral> |
| 377 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 378 | atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 379 | |
| 380 | template <class Integral> |
| 381 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 382 | atomic_fetch_sub(atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 383 | |
| 384 | template <class Integral> |
| 385 | Integral |
| 386 | atomic_fetch_sub_explicit(volatile atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 387 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 388 | template <class Integral> |
| 389 | Integral |
| 390 | atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 391 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 392 | template <class Integral> |
| 393 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 394 | atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 395 | |
| 396 | template <class Integral> |
| 397 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 398 | atomic_fetch_and(atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 399 | |
| 400 | template <class Integral> |
| 401 | Integral |
| 402 | atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 403 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 404 | template <class Integral> |
| 405 | Integral |
| 406 | atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 407 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 408 | template <class Integral> |
| 409 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 410 | atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 411 | |
| 412 | template <class Integral> |
| 413 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 414 | atomic_fetch_or(atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 415 | |
| 416 | template <class Integral> |
| 417 | Integral |
| 418 | atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 419 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 420 | template <class Integral> |
| 421 | Integral |
| 422 | atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 423 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 424 | template <class Integral> |
| 425 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 426 | atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 427 | |
| 428 | template <class Integral> |
| 429 | Integral |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 430 | atomic_fetch_xor(atomic<Integral>* obj, Integral op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 431 | |
| 432 | template <class Integral> |
| 433 | Integral |
| 434 | atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 435 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 436 | template <class Integral> |
| 437 | Integral |
| 438 | atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 439 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 440 | |
| 441 | template <class T> |
| 442 | T* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 443 | atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 444 | |
| 445 | template <class T> |
| 446 | T* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 447 | atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 448 | |
| 449 | template <class T> |
| 450 | T* |
| 451 | atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 452 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 453 | template <class T> |
| 454 | T* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 455 | 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] | 456 | |
| 457 | template <class T> |
| 458 | T* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 459 | atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 460 | |
| 461 | template <class T> |
| 462 | T* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 463 | atomic_fetch_sub(atomic<T*>* obj, ptrdiff_t op) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 464 | |
| 465 | template <class T> |
| 466 | T* |
| 467 | atomic_fetch_sub_explicit(volatile atomic<T*>* obj, ptrdiff_t op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 468 | memory_order m) noexcept; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 469 | template <class T> |
| 470 | T* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 471 | 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] | 472 | |
| 473 | // Atomics for standard typedef types |
| 474 | |
Howard Hinnant | 6ae4705 | 2013-01-04 18:58:50 +0000 | [diff] [blame^] | 475 | typedef atomic<bool> atomic_bool; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 476 | typedef atomic<char> atomic_char; |
| 477 | typedef atomic<signed char> atomic_schar; |
| 478 | typedef atomic<unsigned char> atomic_uchar; |
| 479 | typedef atomic<short> atomic_short; |
| 480 | typedef atomic<unsigned short> atomic_ushort; |
| 481 | typedef atomic<int> atomic_int; |
| 482 | typedef atomic<unsigned int> atomic_uint; |
| 483 | typedef atomic<long> atomic_long; |
| 484 | typedef atomic<unsigned long> atomic_ulong; |
| 485 | typedef atomic<long long> atomic_llong; |
| 486 | typedef atomic<unsigned long long> atomic_ullong; |
| 487 | typedef atomic<char16_t> atomic_char16_t; |
| 488 | typedef atomic<char32_t> atomic_char32_t; |
| 489 | typedef atomic<wchar_t> atomic_wchar_t; |
| 490 | |
| 491 | typedef atomic<int_least8_t> atomic_int_least8_t; |
| 492 | typedef atomic<uint_least8_t> atomic_uint_least8_t; |
| 493 | typedef atomic<int_least16_t> atomic_int_least16_t; |
| 494 | typedef atomic<uint_least16_t> atomic_uint_least16_t; |
| 495 | typedef atomic<int_least32_t> atomic_int_least32_t; |
| 496 | typedef atomic<uint_least32_t> atomic_uint_least32_t; |
| 497 | typedef atomic<int_least64_t> atomic_int_least64_t; |
| 498 | typedef atomic<uint_least64_t> atomic_uint_least64_t; |
| 499 | |
| 500 | typedef atomic<int_fast8_t> atomic_int_fast8_t; |
| 501 | typedef atomic<uint_fast8_t> atomic_uint_fast8_t; |
| 502 | typedef atomic<int_fast16_t> atomic_int_fast16_t; |
| 503 | typedef atomic<uint_fast16_t> atomic_uint_fast16_t; |
| 504 | typedef atomic<int_fast32_t> atomic_int_fast32_t; |
| 505 | typedef atomic<uint_fast32_t> atomic_uint_fast32_t; |
| 506 | typedef atomic<int_fast64_t> atomic_int_fast64_t; |
| 507 | typedef atomic<uint_fast64_t> atomic_uint_fast64_t; |
| 508 | |
| 509 | typedef atomic<intptr_t> atomic_intptr_t; |
| 510 | typedef atomic<uintptr_t> atomic_uintptr_t; |
| 511 | typedef atomic<size_t> atomic_size_t; |
| 512 | typedef atomic<ptrdiff_t> atomic_ptrdiff_t; |
| 513 | typedef atomic<intmax_t> atomic_intmax_t; |
| 514 | typedef atomic<uintmax_t> atomic_uintmax_t; |
| 515 | |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 516 | // fences |
| 517 | |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 518 | void atomic_thread_fence(memory_order m) noexcept; |
| 519 | void atomic_signal_fence(memory_order m) noexcept; |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 520 | |
| 521 | } // std |
| 522 | |
| 523 | */ |
| 524 | |
| 525 | #include <__config> |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 526 | #include <cstddef> |
| 527 | #include <cstdint> |
| 528 | #include <type_traits> |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 529 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 530 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 531 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 532 | #endif |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 533 | |
| 534 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 535 | |
Howard Hinnant | 154002b | 2011-03-31 16:39:39 +0000 | [diff] [blame] | 536 | #if !__has_feature(cxx_atomic) |
| 537 | #error <atomic> is not implemented |
| 538 | #else |
| 539 | |
Howard Hinnant | d1176e2 | 2010-09-28 17:13:38 +0000 | [diff] [blame] | 540 | typedef enum memory_order |
| 541 | { |
| 542 | memory_order_relaxed, memory_order_consume, memory_order_acquire, |
| 543 | memory_order_release, memory_order_acq_rel, memory_order_seq_cst |
| 544 | } memory_order; |
| 545 | |
| 546 | template <class _Tp> |
| 547 | inline _LIBCPP_INLINE_VISIBILITY |
| 548 | _Tp |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 549 | kill_dependency(_Tp __y) _NOEXCEPT |
Howard Hinnant | d1176e2 | 2010-09-28 17:13:38 +0000 | [diff] [blame] | 550 | { |
| 551 | return __y; |
| 552 | } |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 553 | |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 554 | // general atomic<T> |
| 555 | |
| 556 | template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value> |
| 557 | struct __atomic_base // false |
| 558 | { |
Howard Hinnant | 7eb9f1e | 2012-09-16 20:33:09 +0000 | [diff] [blame] | 559 | mutable _Atomic(_Tp) __a_; |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 560 | |
| 561 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 562 | bool is_lock_free() const volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 563 | {return __c11_atomic_is_lock_free(sizeof(_Tp));} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 564 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 565 | bool is_lock_free() const _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 566 | {return __c11_atomic_is_lock_free(sizeof(_Tp));} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 567 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 568 | void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 569 | {__c11_atomic_store(&__a_, __d, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 570 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 571 | void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 572 | {__c11_atomic_store(&__a_, __d, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 573 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 574 | _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 575 | {return __c11_atomic_load(&__a_, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 576 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 577 | _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 578 | {return __c11_atomic_load(&__a_, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 579 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 580 | operator _Tp() const volatile _NOEXCEPT {return load();} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 581 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 582 | operator _Tp() const _NOEXCEPT {return load();} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 583 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 584 | _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] | 585 | {return __c11_atomic_exchange(&__a_, __d, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 586 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 587 | _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 588 | {return __c11_atomic_exchange(&__a_, __d, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 589 | _LIBCPP_INLINE_VISIBILITY |
| 590 | bool compare_exchange_weak(_Tp& __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 591 | memory_order __s, memory_order __f) volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 592 | {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 593 | _LIBCPP_INLINE_VISIBILITY |
| 594 | bool compare_exchange_weak(_Tp& __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 595 | memory_order __s, memory_order __f) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 596 | {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 597 | _LIBCPP_INLINE_VISIBILITY |
| 598 | bool compare_exchange_strong(_Tp& __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 599 | memory_order __s, memory_order __f) volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 600 | {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 601 | _LIBCPP_INLINE_VISIBILITY |
| 602 | bool compare_exchange_strong(_Tp& __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 603 | memory_order __s, memory_order __f) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 604 | {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 605 | _LIBCPP_INLINE_VISIBILITY |
| 606 | bool compare_exchange_weak(_Tp& __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 607 | memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 608 | {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 609 | _LIBCPP_INLINE_VISIBILITY |
| 610 | bool compare_exchange_weak(_Tp& __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 611 | memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 612 | {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 613 | _LIBCPP_INLINE_VISIBILITY |
| 614 | bool compare_exchange_strong(_Tp& __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 615 | memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 616 | {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 617 | _LIBCPP_INLINE_VISIBILITY |
| 618 | bool compare_exchange_strong(_Tp& __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 619 | memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 620 | {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 621 | |
| 622 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 623 | __atomic_base() _NOEXCEPT {} // = default; |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 624 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 625 | _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {} |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 626 | #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 627 | __atomic_base(const __atomic_base&) = delete; |
| 628 | __atomic_base& operator=(const __atomic_base&) = delete; |
| 629 | __atomic_base& operator=(const __atomic_base&) volatile = delete; |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 630 | #else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
| 631 | private: |
| 632 | __atomic_base(const __atomic_base&); |
| 633 | __atomic_base& operator=(const __atomic_base&); |
| 634 | __atomic_base& operator=(const __atomic_base&) volatile; |
| 635 | #endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 636 | }; |
| 637 | |
| 638 | // atomic<Integral> |
| 639 | |
| 640 | template <class _Tp> |
| 641 | struct __atomic_base<_Tp, true> |
| 642 | : public __atomic_base<_Tp, false> |
| 643 | { |
| 644 | typedef __atomic_base<_Tp, false> __base; |
| 645 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 646 | __atomic_base() _NOEXCEPT {} // = default; |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 647 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 648 | _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 649 | |
| 650 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 651 | _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] | 652 | {return __c11_atomic_fetch_add(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 653 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 654 | _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] | 655 | {return __c11_atomic_fetch_add(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 656 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 657 | _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] | 658 | {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 659 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 660 | _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] | 661 | {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 662 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 663 | _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] | 664 | {return __c11_atomic_fetch_and(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 665 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 666 | _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] | 667 | {return __c11_atomic_fetch_and(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 668 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 669 | _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] | 670 | {return __c11_atomic_fetch_or(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 671 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 672 | _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] | 673 | {return __c11_atomic_fetch_or(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 674 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 675 | _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] | 676 | {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 677 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 678 | _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] | 679 | {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 680 | |
| 681 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 682 | _Tp operator++(int) volatile _NOEXCEPT {return fetch_add(_Tp(1));} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 683 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 684 | _Tp operator++(int) _NOEXCEPT {return fetch_add(_Tp(1));} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 685 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 686 | _Tp operator--(int) volatile _NOEXCEPT {return fetch_sub(_Tp(1));} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 687 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 688 | _Tp operator--(int) _NOEXCEPT {return fetch_sub(_Tp(1));} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 689 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 690 | _Tp operator++() volatile _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 691 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 692 | _Tp operator++() _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 693 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 694 | _Tp operator--() volatile _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 695 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 696 | _Tp operator--() _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 697 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 698 | _Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 699 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 700 | _Tp operator+=(_Tp __op) _NOEXCEPT {return fetch_add(__op) + __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 701 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 702 | _Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 703 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 704 | _Tp operator-=(_Tp __op) _NOEXCEPT {return fetch_sub(__op) - __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 705 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 706 | _Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 707 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 708 | _Tp operator&=(_Tp __op) _NOEXCEPT {return fetch_and(__op) & __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 709 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 710 | _Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 711 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 712 | _Tp operator|=(_Tp __op) _NOEXCEPT {return fetch_or(__op) | __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 713 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 714 | _Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 715 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 716 | _Tp operator^=(_Tp __op) _NOEXCEPT {return fetch_xor(__op) ^ __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 717 | }; |
| 718 | |
| 719 | // atomic<T> |
| 720 | |
| 721 | template <class _Tp> |
| 722 | struct atomic |
| 723 | : public __atomic_base<_Tp> |
| 724 | { |
| 725 | typedef __atomic_base<_Tp> __base; |
| 726 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 727 | atomic() _NOEXCEPT {} // = default; |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 728 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 729 | _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {} |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 730 | |
| 731 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 732 | _Tp operator=(_Tp __d) volatile _NOEXCEPT |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 733 | {__base::store(__d); return __d;} |
| 734 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 735 | _Tp operator=(_Tp __d) _NOEXCEPT |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 736 | {__base::store(__d); return __d;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 737 | }; |
| 738 | |
| 739 | // atomic<T*> |
| 740 | |
| 741 | template <class _Tp> |
| 742 | struct atomic<_Tp*> |
| 743 | : public __atomic_base<_Tp*> |
| 744 | { |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 745 | typedef __atomic_base<_Tp*> __base; |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 746 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 747 | atomic() _NOEXCEPT {} // = default; |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 748 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 749 | _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 750 | |
| 751 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 752 | _Tp* operator=(_Tp* __d) volatile _NOEXCEPT |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 753 | {__base::store(__d); return __d;} |
| 754 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 755 | _Tp* operator=(_Tp* __d) _NOEXCEPT |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 756 | {__base::store(__d); return __d;} |
| 757 | |
| 758 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 759 | _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] | 760 | volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 761 | {return __c11_atomic_fetch_add(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 762 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 763 | _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] | 764 | {return __c11_atomic_fetch_add(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 765 | _LIBCPP_INLINE_VISIBILITY |
| 766 | _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] | 767 | volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 768 | {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 769 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 770 | _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] | 771 | {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 772 | |
| 773 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 774 | _Tp* operator++(int) volatile _NOEXCEPT {return fetch_add(1);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 775 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 776 | _Tp* operator++(int) _NOEXCEPT {return fetch_add(1);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 777 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 778 | _Tp* operator--(int) volatile _NOEXCEPT {return fetch_sub(1);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 779 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 780 | _Tp* operator--(int) _NOEXCEPT {return fetch_sub(1);} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 781 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 782 | _Tp* operator++() volatile _NOEXCEPT {return fetch_add(1) + 1;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 783 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 784 | _Tp* operator++() _NOEXCEPT {return fetch_add(1) + 1;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 785 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 786 | _Tp* operator--() volatile _NOEXCEPT {return fetch_sub(1) - 1;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 787 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 788 | _Tp* operator--() _NOEXCEPT {return fetch_sub(1) - 1;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 789 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 790 | _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 791 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 792 | _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT {return fetch_add(__op) + __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 793 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 794 | _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 795 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 796 | _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT {return fetch_sub(__op) - __op;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 797 | }; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 798 | |
| 799 | // atomic_is_lock_free |
| 800 | |
| 801 | template <class _Tp> |
| 802 | inline _LIBCPP_INLINE_VISIBILITY |
| 803 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 804 | atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 805 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 806 | return __o->is_lock_free(); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | template <class _Tp> |
| 810 | inline _LIBCPP_INLINE_VISIBILITY |
| 811 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 812 | atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 813 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 814 | return __o->is_lock_free(); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | // atomic_init |
| 818 | |
| 819 | template <class _Tp> |
| 820 | inline _LIBCPP_INLINE_VISIBILITY |
| 821 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 822 | atomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 823 | { |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 824 | __c11_atomic_init(&__o->__a_, __d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | template <class _Tp> |
| 828 | inline _LIBCPP_INLINE_VISIBILITY |
| 829 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 830 | atomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 831 | { |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 832 | __c11_atomic_init(&__o->__a_, __d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | // atomic_store |
| 836 | |
| 837 | template <class _Tp> |
| 838 | inline _LIBCPP_INLINE_VISIBILITY |
| 839 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 840 | atomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 841 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 842 | __o->store(__d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | template <class _Tp> |
| 846 | inline _LIBCPP_INLINE_VISIBILITY |
| 847 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 848 | atomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 849 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 850 | __o->store(__d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | // atomic_store_explicit |
| 854 | |
| 855 | template <class _Tp> |
| 856 | inline _LIBCPP_INLINE_VISIBILITY |
| 857 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 858 | atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 859 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 860 | __o->store(__d, __m); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | template <class _Tp> |
| 864 | inline _LIBCPP_INLINE_VISIBILITY |
| 865 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 866 | atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 867 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 868 | __o->store(__d, __m); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | // atomic_load |
| 872 | |
| 873 | template <class _Tp> |
| 874 | inline _LIBCPP_INLINE_VISIBILITY |
| 875 | _Tp |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 876 | atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 877 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 878 | return __o->load(); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | template <class _Tp> |
| 882 | inline _LIBCPP_INLINE_VISIBILITY |
| 883 | _Tp |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 884 | atomic_load(const atomic<_Tp>* __o) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 885 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 886 | return __o->load(); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | // atomic_load_explicit |
| 890 | |
| 891 | template <class _Tp> |
| 892 | inline _LIBCPP_INLINE_VISIBILITY |
| 893 | _Tp |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 894 | atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 895 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 896 | return __o->load(__m); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | template <class _Tp> |
| 900 | inline _LIBCPP_INLINE_VISIBILITY |
| 901 | _Tp |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 902 | atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 903 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 904 | return __o->load(__m); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | // atomic_exchange |
| 908 | |
| 909 | template <class _Tp> |
| 910 | inline _LIBCPP_INLINE_VISIBILITY |
| 911 | _Tp |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 912 | atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 913 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 914 | return __o->exchange(__d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | template <class _Tp> |
| 918 | inline _LIBCPP_INLINE_VISIBILITY |
| 919 | _Tp |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 920 | atomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 921 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 922 | return __o->exchange(__d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | // atomic_exchange_explicit |
| 926 | |
| 927 | template <class _Tp> |
| 928 | inline _LIBCPP_INLINE_VISIBILITY |
| 929 | _Tp |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 930 | 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] | 931 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 932 | return __o->exchange(__d, __m); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | template <class _Tp> |
| 936 | inline _LIBCPP_INLINE_VISIBILITY |
| 937 | _Tp |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 938 | atomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 939 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 940 | return __o->exchange(__d, __m); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | // atomic_compare_exchange_weak |
| 944 | |
| 945 | template <class _Tp> |
| 946 | inline _LIBCPP_INLINE_VISIBILITY |
| 947 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 948 | 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] | 949 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 950 | return __o->compare_exchange_weak(*__e, __d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | template <class _Tp> |
| 954 | inline _LIBCPP_INLINE_VISIBILITY |
| 955 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 956 | atomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 957 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 958 | return __o->compare_exchange_weak(*__e, __d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | // atomic_compare_exchange_strong |
| 962 | |
| 963 | template <class _Tp> |
| 964 | inline _LIBCPP_INLINE_VISIBILITY |
| 965 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 966 | 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] | 967 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 968 | return __o->compare_exchange_strong(*__e, __d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | template <class _Tp> |
| 972 | inline _LIBCPP_INLINE_VISIBILITY |
| 973 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 974 | atomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 975 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 976 | return __o->compare_exchange_strong(*__e, __d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | // atomic_compare_exchange_weak_explicit |
| 980 | |
| 981 | template <class _Tp> |
| 982 | inline _LIBCPP_INLINE_VISIBILITY |
| 983 | bool |
| 984 | atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e, |
| 985 | _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 986 | memory_order __s, memory_order __f) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 987 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 988 | return __o->compare_exchange_weak(*__e, __d, __s, __f); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | template <class _Tp> |
| 992 | inline _LIBCPP_INLINE_VISIBILITY |
| 993 | bool |
| 994 | atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 995 | memory_order __s, memory_order __f) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 996 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 997 | return __o->compare_exchange_weak(*__e, __d, __s, __f); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | // atomic_compare_exchange_strong_explicit |
| 1001 | |
| 1002 | template <class _Tp> |
| 1003 | inline _LIBCPP_INLINE_VISIBILITY |
| 1004 | bool |
| 1005 | atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o, |
| 1006 | _Tp* __e, _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1007 | memory_order __s, memory_order __f) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1008 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1009 | return __o->compare_exchange_strong(*__e, __d, __s, __f); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | template <class _Tp> |
| 1013 | inline _LIBCPP_INLINE_VISIBILITY |
| 1014 | bool |
| 1015 | atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e, |
| 1016 | _Tp __d, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1017 | memory_order __s, memory_order __f) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1018 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1019 | return __o->compare_exchange_strong(*__e, __d, __s, __f); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1022 | // atomic_fetch_add |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1023 | |
| 1024 | template <class _Tp> |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1025 | inline _LIBCPP_INLINE_VISIBILITY |
| 1026 | typename enable_if |
| 1027 | < |
| 1028 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1029 | _Tp |
| 1030 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1031 | atomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1032 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1033 | return __o->fetch_add(__op); |
| 1034 | } |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1035 | |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1036 | template <class _Tp> |
| 1037 | inline _LIBCPP_INLINE_VISIBILITY |
| 1038 | typename enable_if |
| 1039 | < |
| 1040 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1041 | _Tp |
| 1042 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1043 | atomic_fetch_add(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1044 | { |
| 1045 | return __o->fetch_add(__op); |
| 1046 | } |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1047 | |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1048 | template <class _Tp> |
| 1049 | inline _LIBCPP_INLINE_VISIBILITY |
| 1050 | _Tp* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1051 | atomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1052 | { |
| 1053 | return __o->fetch_add(__op); |
| 1054 | } |
| 1055 | |
| 1056 | template <class _Tp> |
| 1057 | inline _LIBCPP_INLINE_VISIBILITY |
| 1058 | _Tp* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1059 | atomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1060 | { |
| 1061 | return __o->fetch_add(__op); |
| 1062 | } |
| 1063 | |
| 1064 | // atomic_fetch_add_explicit |
| 1065 | |
| 1066 | template <class _Tp> |
| 1067 | inline _LIBCPP_INLINE_VISIBILITY |
| 1068 | typename enable_if |
| 1069 | < |
| 1070 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1071 | _Tp |
| 1072 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1073 | 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] | 1074 | { |
| 1075 | return __o->fetch_add(__op, __m); |
| 1076 | } |
| 1077 | |
| 1078 | template <class _Tp> |
| 1079 | inline _LIBCPP_INLINE_VISIBILITY |
| 1080 | typename enable_if |
| 1081 | < |
| 1082 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1083 | _Tp |
| 1084 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1085 | 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] | 1086 | { |
| 1087 | return __o->fetch_add(__op, __m); |
| 1088 | } |
| 1089 | |
| 1090 | template <class _Tp> |
| 1091 | inline _LIBCPP_INLINE_VISIBILITY |
| 1092 | _Tp* |
| 1093 | atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1094 | memory_order __m) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1095 | { |
| 1096 | return __o->fetch_add(__op, __m); |
| 1097 | } |
| 1098 | |
| 1099 | template <class _Tp> |
| 1100 | inline _LIBCPP_INLINE_VISIBILITY |
| 1101 | _Tp* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1102 | 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] | 1103 | { |
| 1104 | return __o->fetch_add(__op, __m); |
| 1105 | } |
| 1106 | |
| 1107 | // atomic_fetch_sub |
| 1108 | |
| 1109 | template <class _Tp> |
| 1110 | inline _LIBCPP_INLINE_VISIBILITY |
| 1111 | typename enable_if |
| 1112 | < |
| 1113 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1114 | _Tp |
| 1115 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1116 | atomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1117 | { |
| 1118 | return __o->fetch_sub(__op); |
| 1119 | } |
| 1120 | |
| 1121 | template <class _Tp> |
| 1122 | inline _LIBCPP_INLINE_VISIBILITY |
| 1123 | typename enable_if |
| 1124 | < |
| 1125 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1126 | _Tp |
| 1127 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1128 | atomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1129 | { |
| 1130 | return __o->fetch_sub(__op); |
| 1131 | } |
| 1132 | |
| 1133 | template <class _Tp> |
| 1134 | inline _LIBCPP_INLINE_VISIBILITY |
| 1135 | _Tp* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1136 | atomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1137 | { |
| 1138 | return __o->fetch_sub(__op); |
| 1139 | } |
| 1140 | |
| 1141 | template <class _Tp> |
| 1142 | inline _LIBCPP_INLINE_VISIBILITY |
| 1143 | _Tp* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1144 | atomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1145 | { |
| 1146 | return __o->fetch_sub(__op); |
| 1147 | } |
| 1148 | |
| 1149 | // atomic_fetch_sub_explicit |
| 1150 | |
| 1151 | template <class _Tp> |
| 1152 | inline _LIBCPP_INLINE_VISIBILITY |
| 1153 | typename enable_if |
| 1154 | < |
| 1155 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1156 | _Tp |
| 1157 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1158 | 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] | 1159 | { |
| 1160 | return __o->fetch_sub(__op, __m); |
| 1161 | } |
| 1162 | |
| 1163 | template <class _Tp> |
| 1164 | inline _LIBCPP_INLINE_VISIBILITY |
| 1165 | typename enable_if |
| 1166 | < |
| 1167 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1168 | _Tp |
| 1169 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1170 | 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] | 1171 | { |
| 1172 | return __o->fetch_sub(__op, __m); |
| 1173 | } |
| 1174 | |
| 1175 | template <class _Tp> |
| 1176 | inline _LIBCPP_INLINE_VISIBILITY |
| 1177 | _Tp* |
| 1178 | atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op, |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1179 | memory_order __m) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1180 | { |
| 1181 | return __o->fetch_sub(__op, __m); |
| 1182 | } |
| 1183 | |
| 1184 | template <class _Tp> |
| 1185 | inline _LIBCPP_INLINE_VISIBILITY |
| 1186 | _Tp* |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1187 | 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] | 1188 | { |
| 1189 | return __o->fetch_sub(__op, __m); |
| 1190 | } |
| 1191 | |
| 1192 | // atomic_fetch_and |
| 1193 | |
| 1194 | template <class _Tp> |
| 1195 | inline _LIBCPP_INLINE_VISIBILITY |
| 1196 | typename enable_if |
| 1197 | < |
| 1198 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1199 | _Tp |
| 1200 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1201 | atomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1202 | { |
| 1203 | return __o->fetch_and(__op); |
| 1204 | } |
| 1205 | |
| 1206 | template <class _Tp> |
| 1207 | inline _LIBCPP_INLINE_VISIBILITY |
| 1208 | typename enable_if |
| 1209 | < |
| 1210 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1211 | _Tp |
| 1212 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1213 | atomic_fetch_and(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1214 | { |
| 1215 | return __o->fetch_and(__op); |
| 1216 | } |
| 1217 | |
| 1218 | // atomic_fetch_and_explicit |
| 1219 | |
| 1220 | template <class _Tp> |
| 1221 | inline _LIBCPP_INLINE_VISIBILITY |
| 1222 | typename enable_if |
| 1223 | < |
| 1224 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1225 | _Tp |
| 1226 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1227 | 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] | 1228 | { |
| 1229 | return __o->fetch_and(__op, __m); |
| 1230 | } |
| 1231 | |
| 1232 | template <class _Tp> |
| 1233 | inline _LIBCPP_INLINE_VISIBILITY |
| 1234 | typename enable_if |
| 1235 | < |
| 1236 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1237 | _Tp |
| 1238 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1239 | 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] | 1240 | { |
| 1241 | return __o->fetch_and(__op, __m); |
| 1242 | } |
| 1243 | |
| 1244 | // atomic_fetch_or |
| 1245 | |
| 1246 | template <class _Tp> |
| 1247 | inline _LIBCPP_INLINE_VISIBILITY |
| 1248 | typename enable_if |
| 1249 | < |
| 1250 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1251 | _Tp |
| 1252 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1253 | atomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1254 | { |
| 1255 | return __o->fetch_or(__op); |
| 1256 | } |
| 1257 | |
| 1258 | template <class _Tp> |
| 1259 | inline _LIBCPP_INLINE_VISIBILITY |
| 1260 | typename enable_if |
| 1261 | < |
| 1262 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1263 | _Tp |
| 1264 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1265 | atomic_fetch_or(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1266 | { |
| 1267 | return __o->fetch_or(__op); |
| 1268 | } |
| 1269 | |
| 1270 | // atomic_fetch_or_explicit |
| 1271 | |
| 1272 | template <class _Tp> |
| 1273 | inline _LIBCPP_INLINE_VISIBILITY |
| 1274 | typename enable_if |
| 1275 | < |
| 1276 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1277 | _Tp |
| 1278 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1279 | 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] | 1280 | { |
| 1281 | return __o->fetch_or(__op, __m); |
| 1282 | } |
| 1283 | |
| 1284 | template <class _Tp> |
| 1285 | inline _LIBCPP_INLINE_VISIBILITY |
| 1286 | typename enable_if |
| 1287 | < |
| 1288 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1289 | _Tp |
| 1290 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1291 | 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] | 1292 | { |
| 1293 | return __o->fetch_or(__op, __m); |
| 1294 | } |
| 1295 | |
| 1296 | // atomic_fetch_xor |
| 1297 | |
| 1298 | template <class _Tp> |
| 1299 | inline _LIBCPP_INLINE_VISIBILITY |
| 1300 | typename enable_if |
| 1301 | < |
| 1302 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1303 | _Tp |
| 1304 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1305 | atomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1306 | { |
| 1307 | return __o->fetch_xor(__op); |
| 1308 | } |
| 1309 | |
| 1310 | template <class _Tp> |
| 1311 | inline _LIBCPP_INLINE_VISIBILITY |
| 1312 | typename enable_if |
| 1313 | < |
| 1314 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1315 | _Tp |
| 1316 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1317 | atomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1318 | { |
| 1319 | return __o->fetch_xor(__op); |
| 1320 | } |
| 1321 | |
| 1322 | // atomic_fetch_xor_explicit |
| 1323 | |
| 1324 | template <class _Tp> |
| 1325 | inline _LIBCPP_INLINE_VISIBILITY |
| 1326 | typename enable_if |
| 1327 | < |
| 1328 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1329 | _Tp |
| 1330 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1331 | 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] | 1332 | { |
| 1333 | return __o->fetch_xor(__op, __m); |
| 1334 | } |
| 1335 | |
| 1336 | template <class _Tp> |
| 1337 | inline _LIBCPP_INLINE_VISIBILITY |
| 1338 | typename enable_if |
| 1339 | < |
| 1340 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1341 | _Tp |
| 1342 | >::type |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1343 | 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] | 1344 | { |
| 1345 | return __o->fetch_xor(__op, __m); |
| 1346 | } |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1347 | |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1348 | // flag type and operations |
| 1349 | |
| 1350 | typedef struct atomic_flag |
| 1351 | { |
David Chisnall | 83b2c84 | 2011-12-19 11:44:20 +0000 | [diff] [blame] | 1352 | _Atomic(bool) __a_; |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1353 | |
| 1354 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1355 | 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] | 1356 | {return __c11_atomic_exchange(&__a_, true, __m);} |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1357 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1358 | bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1359 | {return __c11_atomic_exchange(&__a_, true, __m);} |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1360 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1361 | void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1362 | {__c11_atomic_store(&__a_, false, __m);} |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1363 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1364 | void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1365 | {__c11_atomic_store(&__a_, false, __m);} |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1366 | |
| 1367 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1368 | atomic_flag() _NOEXCEPT {} // = default; |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1369 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1370 | atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1371 | |
| 1372 | #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
| 1373 | atomic_flag(const atomic_flag&) = delete; |
| 1374 | atomic_flag& operator=(const atomic_flag&) = delete; |
| 1375 | atomic_flag& operator=(const atomic_flag&) volatile = delete; |
| 1376 | #else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
| 1377 | private: |
| 1378 | atomic_flag(const atomic_flag&); |
| 1379 | atomic_flag& operator=(const atomic_flag&); |
| 1380 | atomic_flag& operator=(const atomic_flag&) volatile; |
| 1381 | #endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
| 1382 | } atomic_flag; |
| 1383 | |
| 1384 | inline _LIBCPP_INLINE_VISIBILITY |
| 1385 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1386 | atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1387 | { |
| 1388 | return __o->test_and_set(); |
| 1389 | } |
| 1390 | |
| 1391 | inline _LIBCPP_INLINE_VISIBILITY |
| 1392 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1393 | atomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1394 | { |
| 1395 | return __o->test_and_set(); |
| 1396 | } |
| 1397 | |
| 1398 | inline _LIBCPP_INLINE_VISIBILITY |
| 1399 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1400 | 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] | 1401 | { |
| 1402 | return __o->test_and_set(__m); |
| 1403 | } |
| 1404 | |
| 1405 | inline _LIBCPP_INLINE_VISIBILITY |
| 1406 | bool |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1407 | 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] | 1408 | { |
| 1409 | return __o->test_and_set(__m); |
| 1410 | } |
| 1411 | |
| 1412 | inline _LIBCPP_INLINE_VISIBILITY |
| 1413 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1414 | atomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1415 | { |
| 1416 | __o->clear(); |
| 1417 | } |
| 1418 | |
| 1419 | inline _LIBCPP_INLINE_VISIBILITY |
| 1420 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1421 | atomic_flag_clear(atomic_flag* __o) _NOEXCEPT |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1422 | { |
| 1423 | __o->clear(); |
| 1424 | } |
| 1425 | |
| 1426 | inline _LIBCPP_INLINE_VISIBILITY |
| 1427 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1428 | atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1429 | { |
| 1430 | __o->clear(__m); |
| 1431 | } |
| 1432 | |
| 1433 | inline _LIBCPP_INLINE_VISIBILITY |
| 1434 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1435 | atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1436 | { |
| 1437 | __o->clear(__m); |
| 1438 | } |
| 1439 | |
| 1440 | // fences |
| 1441 | |
| 1442 | inline _LIBCPP_INLINE_VISIBILITY |
| 1443 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1444 | atomic_thread_fence(memory_order __m) _NOEXCEPT |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1445 | { |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1446 | __c11_atomic_thread_fence(__m); |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1447 | } |
| 1448 | |
| 1449 | inline _LIBCPP_INLINE_VISIBILITY |
| 1450 | void |
Howard Hinnant | 300c67a | 2012-04-11 20:14:21 +0000 | [diff] [blame] | 1451 | atomic_signal_fence(memory_order __m) _NOEXCEPT |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1452 | { |
Richard Smith | 6186c7f | 2012-04-11 18:55:46 +0000 | [diff] [blame] | 1453 | __c11_atomic_signal_fence(__m); |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1454 | } |
| 1455 | |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 1456 | // Atomics for standard typedef types |
| 1457 | |
Howard Hinnant | 6ae4705 | 2013-01-04 18:58:50 +0000 | [diff] [blame^] | 1458 | typedef atomic<bool> atomic_bool; |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 1459 | typedef atomic<char> atomic_char; |
| 1460 | typedef atomic<signed char> atomic_schar; |
| 1461 | typedef atomic<unsigned char> atomic_uchar; |
| 1462 | typedef atomic<short> atomic_short; |
| 1463 | typedef atomic<unsigned short> atomic_ushort; |
| 1464 | typedef atomic<int> atomic_int; |
| 1465 | typedef atomic<unsigned int> atomic_uint; |
| 1466 | typedef atomic<long> atomic_long; |
| 1467 | typedef atomic<unsigned long> atomic_ulong; |
| 1468 | typedef atomic<long long> atomic_llong; |
| 1469 | typedef atomic<unsigned long long> atomic_ullong; |
| 1470 | typedef atomic<char16_t> atomic_char16_t; |
| 1471 | typedef atomic<char32_t> atomic_char32_t; |
| 1472 | typedef atomic<wchar_t> atomic_wchar_t; |
| 1473 | |
| 1474 | typedef atomic<int_least8_t> atomic_int_least8_t; |
| 1475 | typedef atomic<uint_least8_t> atomic_uint_least8_t; |
| 1476 | typedef atomic<int_least16_t> atomic_int_least16_t; |
| 1477 | typedef atomic<uint_least16_t> atomic_uint_least16_t; |
| 1478 | typedef atomic<int_least32_t> atomic_int_least32_t; |
| 1479 | typedef atomic<uint_least32_t> atomic_uint_least32_t; |
| 1480 | typedef atomic<int_least64_t> atomic_int_least64_t; |
| 1481 | typedef atomic<uint_least64_t> atomic_uint_least64_t; |
| 1482 | |
| 1483 | typedef atomic<int_fast8_t> atomic_int_fast8_t; |
| 1484 | typedef atomic<uint_fast8_t> atomic_uint_fast8_t; |
| 1485 | typedef atomic<int_fast16_t> atomic_int_fast16_t; |
| 1486 | typedef atomic<uint_fast16_t> atomic_uint_fast16_t; |
| 1487 | typedef atomic<int_fast32_t> atomic_int_fast32_t; |
| 1488 | typedef atomic<uint_fast32_t> atomic_uint_fast32_t; |
| 1489 | typedef atomic<int_fast64_t> atomic_int_fast64_t; |
| 1490 | typedef atomic<uint_fast64_t> atomic_uint_fast64_t; |
| 1491 | |
| 1492 | typedef atomic<intptr_t> atomic_intptr_t; |
| 1493 | typedef atomic<uintptr_t> atomic_uintptr_t; |
| 1494 | typedef atomic<size_t> atomic_size_t; |
| 1495 | typedef atomic<ptrdiff_t> atomic_ptrdiff_t; |
| 1496 | typedef atomic<intmax_t> atomic_intmax_t; |
| 1497 | typedef atomic<uintmax_t> atomic_uintmax_t; |
| 1498 | |
Howard Hinnant | 767ae2b | 2010-09-29 21:20:03 +0000 | [diff] [blame] | 1499 | #define ATOMIC_FLAG_INIT {false} |
Howard Hinnant | 611fdaf | 2010-10-04 18:52:54 +0000 | [diff] [blame] | 1500 | #define ATOMIC_VAR_INIT(__v) {__v} |
| 1501 | |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1502 | // lock-free property |
Howard Hinnant | 611fdaf | 2010-10-04 18:52:54 +0000 | [diff] [blame] | 1503 | |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1504 | #define ATOMIC_CHAR_LOCK_FREE 0 |
| 1505 | #define ATOMIC_CHAR16_T_LOCK_FREE 0 |
| 1506 | #define ATOMIC_CHAR32_T_LOCK_FREE 0 |
| 1507 | #define ATOMIC_WCHAR_T_LOCK_FREE 0 |
| 1508 | #define ATOMIC_SHORT_LOCK_FREE 0 |
| 1509 | #define ATOMIC_INT_LOCK_FREE 0 |
| 1510 | #define ATOMIC_LONG_LOCK_FREE 0 |
| 1511 | #define ATOMIC_LLONG_LOCK_FREE 0 |
| 1512 | |
Howard Hinnant | 154002b | 2011-03-31 16:39:39 +0000 | [diff] [blame] | 1513 | #endif // !__has_feature(cxx_atomic) |
| 1514 | |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 1515 | _LIBCPP_END_NAMESPACE_STD |
| 1516 | |
| 1517 | #endif // _LIBCPP_ATOMIC |