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