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