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 | |
| 529 | #pragma GCC system_header |
| 530 | |
| 531 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 532 | |
Howard Hinnant | 154002b | 2011-03-31 16:39:39 +0000 | [diff] [blame] | 533 | #if !__has_feature(cxx_atomic) |
| 534 | #error <atomic> is not implemented |
| 535 | #else |
| 536 | |
Howard Hinnant | d1176e2 | 2010-09-28 17:13:38 +0000 | [diff] [blame] | 537 | typedef enum memory_order |
| 538 | { |
| 539 | memory_order_relaxed, memory_order_consume, memory_order_acquire, |
| 540 | memory_order_release, memory_order_acq_rel, memory_order_seq_cst |
| 541 | } memory_order; |
| 542 | |
| 543 | template <class _Tp> |
| 544 | inline _LIBCPP_INLINE_VISIBILITY |
| 545 | _Tp |
| 546 | kill_dependency(_Tp __y) |
| 547 | { |
| 548 | return __y; |
| 549 | } |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 550 | |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 551 | // general atomic<T> |
| 552 | |
| 553 | template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value> |
| 554 | struct __atomic_base // false |
| 555 | { |
| 556 | _Tp __a_; |
| 557 | |
| 558 | _LIBCPP_INLINE_VISIBILITY |
| 559 | bool is_lock_free() const volatile |
| 560 | {return __atomic_is_lock_free(_Tp());} |
| 561 | _LIBCPP_INLINE_VISIBILITY |
| 562 | bool is_lock_free() const |
| 563 | {return __atomic_is_lock_free(_Tp());} |
| 564 | _LIBCPP_INLINE_VISIBILITY |
| 565 | void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile |
| 566 | {__atomic_store(&__a_, __d, __m);} |
| 567 | _LIBCPP_INLINE_VISIBILITY |
| 568 | void store(_Tp __d, memory_order __m = memory_order_seq_cst) |
| 569 | {__atomic_store(&__a_, __d, __m);} |
| 570 | _LIBCPP_INLINE_VISIBILITY |
| 571 | _Tp load(memory_order __m = memory_order_seq_cst) const volatile |
| 572 | {return __atomic_load(&__a_, __m);} |
| 573 | _LIBCPP_INLINE_VISIBILITY |
| 574 | _Tp load(memory_order __m = memory_order_seq_cst) const |
| 575 | {return __atomic_load(&__a_, __m);} |
| 576 | _LIBCPP_INLINE_VISIBILITY |
| 577 | operator _Tp() const volatile {return load();} |
| 578 | _LIBCPP_INLINE_VISIBILITY |
| 579 | operator _Tp() const {return load();} |
| 580 | _LIBCPP_INLINE_VISIBILITY |
| 581 | _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile |
| 582 | {return __atomic_exchange(&__a_, __d, __m);} |
| 583 | _LIBCPP_INLINE_VISIBILITY |
| 584 | _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) |
| 585 | {return __atomic_exchange(&__a_, __d, __m);} |
| 586 | _LIBCPP_INLINE_VISIBILITY |
| 587 | bool compare_exchange_weak(_Tp& __e, _Tp __d, |
| 588 | memory_order __s, memory_order __f) volatile |
| 589 | {return __atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} |
| 590 | _LIBCPP_INLINE_VISIBILITY |
| 591 | bool compare_exchange_weak(_Tp& __e, _Tp __d, |
| 592 | memory_order __s, memory_order __f) |
| 593 | {return __atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} |
| 594 | _LIBCPP_INLINE_VISIBILITY |
| 595 | bool compare_exchange_strong(_Tp& __e, _Tp __d, |
| 596 | memory_order __s, memory_order __f) volatile |
| 597 | {return __atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} |
| 598 | _LIBCPP_INLINE_VISIBILITY |
| 599 | bool compare_exchange_strong(_Tp& __e, _Tp __d, |
| 600 | memory_order __s, memory_order __f) |
| 601 | {return __atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} |
| 602 | _LIBCPP_INLINE_VISIBILITY |
| 603 | bool compare_exchange_weak(_Tp& __e, _Tp __d, |
| 604 | memory_order __m = memory_order_seq_cst) volatile |
| 605 | {return __atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);} |
| 606 | _LIBCPP_INLINE_VISIBILITY |
| 607 | bool compare_exchange_weak(_Tp& __e, _Tp __d, |
| 608 | memory_order __m = memory_order_seq_cst) |
| 609 | {return __atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);} |
| 610 | _LIBCPP_INLINE_VISIBILITY |
| 611 | bool compare_exchange_strong(_Tp& __e, _Tp __d, |
| 612 | memory_order __m = memory_order_seq_cst) volatile |
| 613 | {return __atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} |
| 614 | _LIBCPP_INLINE_VISIBILITY |
| 615 | bool compare_exchange_strong(_Tp& __e, _Tp __d, |
| 616 | memory_order __m = memory_order_seq_cst) |
| 617 | {return __atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} |
| 618 | |
| 619 | _LIBCPP_INLINE_VISIBILITY |
| 620 | __atomic_base() {} // = default; |
| 621 | _LIBCPP_INLINE_VISIBILITY |
| 622 | /*constexpr*/ __atomic_base(_Tp __d) : __a_(__d) {} |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 623 | #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 624 | __atomic_base(const __atomic_base&) = delete; |
| 625 | __atomic_base& operator=(const __atomic_base&) = delete; |
| 626 | __atomic_base& operator=(const __atomic_base&) volatile = delete; |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 627 | #else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
| 628 | private: |
| 629 | __atomic_base(const __atomic_base&); |
| 630 | __atomic_base& operator=(const __atomic_base&); |
| 631 | __atomic_base& operator=(const __atomic_base&) volatile; |
| 632 | #endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 633 | }; |
| 634 | |
| 635 | // atomic<Integral> |
| 636 | |
| 637 | template <class _Tp> |
| 638 | struct __atomic_base<_Tp, true> |
| 639 | : public __atomic_base<_Tp, false> |
| 640 | { |
| 641 | typedef __atomic_base<_Tp, false> __base; |
| 642 | _LIBCPP_INLINE_VISIBILITY |
| 643 | __atomic_base() {} // = default; |
| 644 | _LIBCPP_INLINE_VISIBILITY |
| 645 | /*constexpr*/ __atomic_base(_Tp __d) : __base(__d) {} |
| 646 | |
| 647 | _LIBCPP_INLINE_VISIBILITY |
| 648 | _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile |
| 649 | {return __atomic_fetch_add(&this->__a_, __op, __m);} |
| 650 | _LIBCPP_INLINE_VISIBILITY |
| 651 | _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) |
| 652 | {return __atomic_fetch_add(&this->__a_, __op, __m);} |
| 653 | _LIBCPP_INLINE_VISIBILITY |
| 654 | _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile |
| 655 | {return __atomic_fetch_sub(&this->__a_, __op, __m);} |
| 656 | _LIBCPP_INLINE_VISIBILITY |
| 657 | _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) |
| 658 | {return __atomic_fetch_sub(&this->__a_, __op, __m);} |
| 659 | _LIBCPP_INLINE_VISIBILITY |
| 660 | _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile |
| 661 | {return __atomic_fetch_and(&this->__a_, __op, __m);} |
| 662 | _LIBCPP_INLINE_VISIBILITY |
| 663 | _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) |
| 664 | {return __atomic_fetch_and(&this->__a_, __op, __m);} |
| 665 | _LIBCPP_INLINE_VISIBILITY |
| 666 | _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile |
| 667 | {return __atomic_fetch_or(&this->__a_, __op, __m);} |
| 668 | _LIBCPP_INLINE_VISIBILITY |
| 669 | _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) |
| 670 | {return __atomic_fetch_or(&this->__a_, __op, __m);} |
| 671 | _LIBCPP_INLINE_VISIBILITY |
| 672 | _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile |
| 673 | {return __atomic_fetch_xor(&this->__a_, __op, __m);} |
| 674 | _LIBCPP_INLINE_VISIBILITY |
| 675 | _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) |
| 676 | {return __atomic_fetch_xor(&this->__a_, __op, __m);} |
| 677 | |
| 678 | _LIBCPP_INLINE_VISIBILITY |
| 679 | _Tp operator++(int) volatile {return fetch_add(_Tp(1));} |
| 680 | _LIBCPP_INLINE_VISIBILITY |
| 681 | _Tp operator++(int) {return fetch_add(_Tp(1));} |
| 682 | _LIBCPP_INLINE_VISIBILITY |
| 683 | _Tp operator--(int) volatile {return fetch_sub(_Tp(1));} |
| 684 | _LIBCPP_INLINE_VISIBILITY |
| 685 | _Tp operator--(int) {return fetch_sub(_Tp(1));} |
| 686 | _LIBCPP_INLINE_VISIBILITY |
| 687 | _Tp operator++() volatile {return fetch_add(_Tp(1)) + _Tp(1);} |
| 688 | _LIBCPP_INLINE_VISIBILITY |
| 689 | _Tp operator++() {return fetch_add(_Tp(1)) + _Tp(1);} |
| 690 | _LIBCPP_INLINE_VISIBILITY |
| 691 | _Tp operator--() volatile {return fetch_sub(_Tp(1)) - _Tp(1);} |
| 692 | _LIBCPP_INLINE_VISIBILITY |
| 693 | _Tp operator--() {return fetch_sub(_Tp(1)) - _Tp(1);} |
| 694 | _LIBCPP_INLINE_VISIBILITY |
| 695 | _Tp operator+=(_Tp __op) volatile {return fetch_add(__op) + __op;} |
| 696 | _LIBCPP_INLINE_VISIBILITY |
| 697 | _Tp operator+=(_Tp __op) {return fetch_add(__op) + __op;} |
| 698 | _LIBCPP_INLINE_VISIBILITY |
| 699 | _Tp operator-=(_Tp __op) volatile {return fetch_sub(__op) - __op;} |
| 700 | _LIBCPP_INLINE_VISIBILITY |
| 701 | _Tp operator-=(_Tp __op) {return fetch_sub(__op) - __op;} |
| 702 | _LIBCPP_INLINE_VISIBILITY |
| 703 | _Tp operator&=(_Tp __op) volatile {return fetch_and(__op) & __op;} |
| 704 | _LIBCPP_INLINE_VISIBILITY |
| 705 | _Tp operator&=(_Tp __op) {return fetch_and(__op) & __op;} |
| 706 | _LIBCPP_INLINE_VISIBILITY |
| 707 | _Tp operator|=(_Tp __op) volatile {return fetch_or(__op) | __op;} |
| 708 | _LIBCPP_INLINE_VISIBILITY |
| 709 | _Tp operator|=(_Tp __op) {return fetch_or(__op) | __op;} |
| 710 | _LIBCPP_INLINE_VISIBILITY |
| 711 | _Tp operator^=(_Tp __op) volatile {return fetch_xor(__op) ^ __op;} |
| 712 | _LIBCPP_INLINE_VISIBILITY |
| 713 | _Tp operator^=(_Tp __op) {return fetch_xor(__op) ^ __op;} |
| 714 | }; |
| 715 | |
| 716 | // atomic<T> |
| 717 | |
| 718 | template <class _Tp> |
| 719 | struct atomic |
| 720 | : public __atomic_base<_Tp> |
| 721 | { |
| 722 | typedef __atomic_base<_Tp> __base; |
| 723 | _LIBCPP_INLINE_VISIBILITY |
| 724 | atomic() {} // = default; |
| 725 | _LIBCPP_INLINE_VISIBILITY |
| 726 | /*constexpr*/ atomic(_Tp __d) : __base(__d) {} |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 727 | |
| 728 | _LIBCPP_INLINE_VISIBILITY |
| 729 | _Tp operator=(_Tp __d) volatile |
| 730 | {__base::store(__d); return __d;} |
| 731 | _LIBCPP_INLINE_VISIBILITY |
| 732 | _Tp operator=(_Tp __d) |
| 733 | {__base::store(__d); return __d;} |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 734 | }; |
| 735 | |
| 736 | // atomic<T*> |
| 737 | |
| 738 | template <class _Tp> |
| 739 | struct atomic<_Tp*> |
| 740 | : public __atomic_base<_Tp*> |
| 741 | { |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 742 | typedef __atomic_base<_Tp*> __base; |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 743 | _LIBCPP_INLINE_VISIBILITY |
| 744 | atomic() {} // = default; |
| 745 | _LIBCPP_INLINE_VISIBILITY |
| 746 | /*constexpr*/ atomic(_Tp* __d) : __base(__d) {} |
| 747 | |
| 748 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 749 | _Tp* operator=(_Tp* __d) volatile |
| 750 | {__base::store(__d); return __d;} |
| 751 | _LIBCPP_INLINE_VISIBILITY |
| 752 | _Tp* operator=(_Tp* __d) |
| 753 | {__base::store(__d); return __d;} |
| 754 | |
| 755 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 756 | _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) |
| 757 | volatile |
| 758 | {return __atomic_fetch_add(&this->__a_, __op, __m);} |
| 759 | _LIBCPP_INLINE_VISIBILITY |
| 760 | _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) |
| 761 | {return __atomic_fetch_add(&this->__a_, __op, __m);} |
| 762 | _LIBCPP_INLINE_VISIBILITY |
| 763 | _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) |
| 764 | volatile |
| 765 | {return __atomic_fetch_sub(&this->__a_, __op, __m);} |
| 766 | _LIBCPP_INLINE_VISIBILITY |
| 767 | _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) |
| 768 | {return __atomic_fetch_sub(&this->__a_, __op, __m);} |
| 769 | |
| 770 | _LIBCPP_INLINE_VISIBILITY |
| 771 | _Tp* operator++(int) volatile {return fetch_add(1);} |
| 772 | _LIBCPP_INLINE_VISIBILITY |
| 773 | _Tp* operator++(int) {return fetch_add(1);} |
| 774 | _LIBCPP_INLINE_VISIBILITY |
| 775 | _Tp* operator--(int) volatile {return fetch_sub(1);} |
| 776 | _LIBCPP_INLINE_VISIBILITY |
| 777 | _Tp* operator--(int) {return fetch_sub(1);} |
| 778 | _LIBCPP_INLINE_VISIBILITY |
| 779 | _Tp* operator++() volatile {return fetch_add(1) + 1;} |
| 780 | _LIBCPP_INLINE_VISIBILITY |
| 781 | _Tp* operator++() {return fetch_add(1) + 1;} |
| 782 | _LIBCPP_INLINE_VISIBILITY |
| 783 | _Tp* operator--() volatile {return fetch_sub(1) - 1;} |
| 784 | _LIBCPP_INLINE_VISIBILITY |
| 785 | _Tp* operator--() {return fetch_sub(1) - 1;} |
| 786 | _LIBCPP_INLINE_VISIBILITY |
| 787 | _Tp* operator+=(ptrdiff_t __op) volatile {return fetch_add(__op) + __op;} |
| 788 | _LIBCPP_INLINE_VISIBILITY |
| 789 | _Tp* operator+=(ptrdiff_t __op) {return fetch_add(__op) + __op;} |
| 790 | _LIBCPP_INLINE_VISIBILITY |
| 791 | _Tp* operator-=(ptrdiff_t __op) volatile {return fetch_sub(__op) - __op;} |
| 792 | _LIBCPP_INLINE_VISIBILITY |
| 793 | _Tp* operator-=(ptrdiff_t __op) {return fetch_sub(__op) - __op;} |
| 794 | }; |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 795 | |
| 796 | // atomic_is_lock_free |
| 797 | |
| 798 | template <class _Tp> |
| 799 | inline _LIBCPP_INLINE_VISIBILITY |
| 800 | bool |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 801 | atomic_is_lock_free(const volatile atomic<_Tp>* __o) |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 802 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 803 | return __o->is_lock_free(); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | template <class _Tp> |
| 807 | inline _LIBCPP_INLINE_VISIBILITY |
| 808 | bool |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 809 | atomic_is_lock_free(const atomic<_Tp>* __o) |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 810 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 811 | return __o->is_lock_free(); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | // atomic_init |
| 815 | |
| 816 | template <class _Tp> |
| 817 | inline _LIBCPP_INLINE_VISIBILITY |
| 818 | void |
| 819 | atomic_init(volatile atomic<_Tp>* __o, _Tp __d) |
| 820 | { |
| 821 | __o->__a_ = __d; |
| 822 | } |
| 823 | |
| 824 | template <class _Tp> |
| 825 | inline _LIBCPP_INLINE_VISIBILITY |
| 826 | void |
| 827 | atomic_init(atomic<_Tp>* __o, _Tp __d) |
| 828 | { |
| 829 | __o->__a_ = __d; |
| 830 | } |
| 831 | |
| 832 | // atomic_store |
| 833 | |
| 834 | template <class _Tp> |
| 835 | inline _LIBCPP_INLINE_VISIBILITY |
| 836 | void |
| 837 | atomic_store(volatile atomic<_Tp>* __o, _Tp __d) |
| 838 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 839 | __o->store(__d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | template <class _Tp> |
| 843 | inline _LIBCPP_INLINE_VISIBILITY |
| 844 | void |
| 845 | atomic_store(atomic<_Tp>* __o, _Tp __d) |
| 846 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 847 | __o->store(__d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | // atomic_store_explicit |
| 851 | |
| 852 | template <class _Tp> |
| 853 | inline _LIBCPP_INLINE_VISIBILITY |
| 854 | void |
| 855 | atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) |
| 856 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 857 | __o->store(__d, __m); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | template <class _Tp> |
| 861 | inline _LIBCPP_INLINE_VISIBILITY |
| 862 | void |
| 863 | atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) |
| 864 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 865 | __o->store(__d, __m); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | // atomic_load |
| 869 | |
| 870 | template <class _Tp> |
| 871 | inline _LIBCPP_INLINE_VISIBILITY |
| 872 | _Tp |
| 873 | atomic_load(const volatile atomic<_Tp>* __o) |
| 874 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 875 | return __o->load(); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | template <class _Tp> |
| 879 | inline _LIBCPP_INLINE_VISIBILITY |
| 880 | _Tp |
| 881 | atomic_load(const atomic<_Tp>* __o) |
| 882 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 883 | return __o->load(); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | // atomic_load_explicit |
| 887 | |
| 888 | template <class _Tp> |
| 889 | inline _LIBCPP_INLINE_VISIBILITY |
| 890 | _Tp |
| 891 | atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) |
| 892 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 893 | return __o->load(__m); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | template <class _Tp> |
| 897 | inline _LIBCPP_INLINE_VISIBILITY |
| 898 | _Tp |
| 899 | atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) |
| 900 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 901 | return __o->load(__m); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | // atomic_exchange |
| 905 | |
| 906 | template <class _Tp> |
| 907 | inline _LIBCPP_INLINE_VISIBILITY |
| 908 | _Tp |
| 909 | atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) |
| 910 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 911 | return __o->exchange(__d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | template <class _Tp> |
| 915 | inline _LIBCPP_INLINE_VISIBILITY |
| 916 | _Tp |
| 917 | atomic_exchange(atomic<_Tp>* __o, _Tp __d) |
| 918 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 919 | return __o->exchange(__d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | // atomic_exchange_explicit |
| 923 | |
| 924 | template <class _Tp> |
| 925 | inline _LIBCPP_INLINE_VISIBILITY |
| 926 | _Tp |
| 927 | atomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) |
| 928 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 929 | return __o->exchange(__d, __m); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | template <class _Tp> |
| 933 | inline _LIBCPP_INLINE_VISIBILITY |
| 934 | _Tp |
| 935 | atomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) |
| 936 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 937 | return __o->exchange(__d, __m); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | // atomic_compare_exchange_weak |
| 941 | |
| 942 | template <class _Tp> |
| 943 | inline _LIBCPP_INLINE_VISIBILITY |
| 944 | bool |
| 945 | atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) |
| 946 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 947 | return __o->compare_exchange_weak(*__e, __d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | template <class _Tp> |
| 951 | inline _LIBCPP_INLINE_VISIBILITY |
| 952 | bool |
| 953 | atomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) |
| 954 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 955 | return __o->compare_exchange_weak(*__e, __d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | // atomic_compare_exchange_strong |
| 959 | |
| 960 | template <class _Tp> |
| 961 | inline _LIBCPP_INLINE_VISIBILITY |
| 962 | bool |
| 963 | atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) |
| 964 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 965 | return __o->compare_exchange_strong(*__e, __d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | template <class _Tp> |
| 969 | inline _LIBCPP_INLINE_VISIBILITY |
| 970 | bool |
| 971 | atomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) |
| 972 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 973 | return __o->compare_exchange_strong(*__e, __d); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | // atomic_compare_exchange_weak_explicit |
| 977 | |
| 978 | template <class _Tp> |
| 979 | inline _LIBCPP_INLINE_VISIBILITY |
| 980 | bool |
| 981 | atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e, |
| 982 | _Tp __d, |
| 983 | memory_order __s, memory_order __f) |
| 984 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 985 | return __o->compare_exchange_weak(*__e, __d, __s, __f); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | template <class _Tp> |
| 989 | inline _LIBCPP_INLINE_VISIBILITY |
| 990 | bool |
| 991 | atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d, |
| 992 | memory_order __s, memory_order __f) |
| 993 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 994 | return __o->compare_exchange_weak(*__e, __d, __s, __f); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | // atomic_compare_exchange_strong_explicit |
| 998 | |
| 999 | template <class _Tp> |
| 1000 | inline _LIBCPP_INLINE_VISIBILITY |
| 1001 | bool |
| 1002 | atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o, |
| 1003 | _Tp* __e, _Tp __d, |
| 1004 | memory_order __s, memory_order __f) |
| 1005 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1006 | return __o->compare_exchange_strong(*__e, __d, __s, __f); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | template <class _Tp> |
| 1010 | inline _LIBCPP_INLINE_VISIBILITY |
| 1011 | bool |
| 1012 | atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e, |
| 1013 | _Tp __d, |
| 1014 | memory_order __s, memory_order __f) |
| 1015 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1016 | return __o->compare_exchange_strong(*__e, __d, __s, __f); |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1019 | // atomic_fetch_add |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1020 | |
| 1021 | template <class _Tp> |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1022 | inline _LIBCPP_INLINE_VISIBILITY |
| 1023 | typename enable_if |
| 1024 | < |
| 1025 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1026 | _Tp |
| 1027 | >::type |
| 1028 | atomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1029 | { |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1030 | return __o->fetch_add(__op); |
| 1031 | } |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1032 | |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1033 | template <class _Tp> |
| 1034 | inline _LIBCPP_INLINE_VISIBILITY |
| 1035 | typename enable_if |
| 1036 | < |
| 1037 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1038 | _Tp |
| 1039 | >::type |
| 1040 | atomic_fetch_add(atomic<_Tp>* __o, _Tp __op) |
| 1041 | { |
| 1042 | return __o->fetch_add(__op); |
| 1043 | } |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1044 | |
Howard Hinnant | 91e2f26 | 2010-12-07 20:46:14 +0000 | [diff] [blame] | 1045 | template <class _Tp> |
| 1046 | inline _LIBCPP_INLINE_VISIBILITY |
| 1047 | _Tp* |
| 1048 | atomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) |
| 1049 | { |
| 1050 | return __o->fetch_add(__op); |
| 1051 | } |
| 1052 | |
| 1053 | template <class _Tp> |
| 1054 | inline _LIBCPP_INLINE_VISIBILITY |
| 1055 | _Tp* |
| 1056 | atomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) |
| 1057 | { |
| 1058 | return __o->fetch_add(__op); |
| 1059 | } |
| 1060 | |
| 1061 | // atomic_fetch_add_explicit |
| 1062 | |
| 1063 | template <class _Tp> |
| 1064 | inline _LIBCPP_INLINE_VISIBILITY |
| 1065 | typename enable_if |
| 1066 | < |
| 1067 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1068 | _Tp |
| 1069 | >::type |
| 1070 | atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) |
| 1071 | { |
| 1072 | return __o->fetch_add(__op, __m); |
| 1073 | } |
| 1074 | |
| 1075 | template <class _Tp> |
| 1076 | inline _LIBCPP_INLINE_VISIBILITY |
| 1077 | typename enable_if |
| 1078 | < |
| 1079 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1080 | _Tp |
| 1081 | >::type |
| 1082 | atomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) |
| 1083 | { |
| 1084 | return __o->fetch_add(__op, __m); |
| 1085 | } |
| 1086 | |
| 1087 | template <class _Tp> |
| 1088 | inline _LIBCPP_INLINE_VISIBILITY |
| 1089 | _Tp* |
| 1090 | atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op, |
| 1091 | memory_order __m) |
| 1092 | { |
| 1093 | return __o->fetch_add(__op, __m); |
| 1094 | } |
| 1095 | |
| 1096 | template <class _Tp> |
| 1097 | inline _LIBCPP_INLINE_VISIBILITY |
| 1098 | _Tp* |
| 1099 | atomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) |
| 1100 | { |
| 1101 | return __o->fetch_add(__op, __m); |
| 1102 | } |
| 1103 | |
| 1104 | // atomic_fetch_sub |
| 1105 | |
| 1106 | template <class _Tp> |
| 1107 | inline _LIBCPP_INLINE_VISIBILITY |
| 1108 | typename enable_if |
| 1109 | < |
| 1110 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1111 | _Tp |
| 1112 | >::type |
| 1113 | atomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) |
| 1114 | { |
| 1115 | return __o->fetch_sub(__op); |
| 1116 | } |
| 1117 | |
| 1118 | template <class _Tp> |
| 1119 | inline _LIBCPP_INLINE_VISIBILITY |
| 1120 | typename enable_if |
| 1121 | < |
| 1122 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1123 | _Tp |
| 1124 | >::type |
| 1125 | atomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) |
| 1126 | { |
| 1127 | return __o->fetch_sub(__op); |
| 1128 | } |
| 1129 | |
| 1130 | template <class _Tp> |
| 1131 | inline _LIBCPP_INLINE_VISIBILITY |
| 1132 | _Tp* |
| 1133 | atomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) |
| 1134 | { |
| 1135 | return __o->fetch_sub(__op); |
| 1136 | } |
| 1137 | |
| 1138 | template <class _Tp> |
| 1139 | inline _LIBCPP_INLINE_VISIBILITY |
| 1140 | _Tp* |
| 1141 | atomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) |
| 1142 | { |
| 1143 | return __o->fetch_sub(__op); |
| 1144 | } |
| 1145 | |
| 1146 | // atomic_fetch_sub_explicit |
| 1147 | |
| 1148 | template <class _Tp> |
| 1149 | inline _LIBCPP_INLINE_VISIBILITY |
| 1150 | typename enable_if |
| 1151 | < |
| 1152 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1153 | _Tp |
| 1154 | >::type |
| 1155 | atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) |
| 1156 | { |
| 1157 | return __o->fetch_sub(__op, __m); |
| 1158 | } |
| 1159 | |
| 1160 | template <class _Tp> |
| 1161 | inline _LIBCPP_INLINE_VISIBILITY |
| 1162 | typename enable_if |
| 1163 | < |
| 1164 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1165 | _Tp |
| 1166 | >::type |
| 1167 | atomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) |
| 1168 | { |
| 1169 | return __o->fetch_sub(__op, __m); |
| 1170 | } |
| 1171 | |
| 1172 | template <class _Tp> |
| 1173 | inline _LIBCPP_INLINE_VISIBILITY |
| 1174 | _Tp* |
| 1175 | atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op, |
| 1176 | memory_order __m) |
| 1177 | { |
| 1178 | return __o->fetch_sub(__op, __m); |
| 1179 | } |
| 1180 | |
| 1181 | template <class _Tp> |
| 1182 | inline _LIBCPP_INLINE_VISIBILITY |
| 1183 | _Tp* |
| 1184 | atomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) |
| 1185 | { |
| 1186 | return __o->fetch_sub(__op, __m); |
| 1187 | } |
| 1188 | |
| 1189 | // atomic_fetch_and |
| 1190 | |
| 1191 | template <class _Tp> |
| 1192 | inline _LIBCPP_INLINE_VISIBILITY |
| 1193 | typename enable_if |
| 1194 | < |
| 1195 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1196 | _Tp |
| 1197 | >::type |
| 1198 | atomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) |
| 1199 | { |
| 1200 | return __o->fetch_and(__op); |
| 1201 | } |
| 1202 | |
| 1203 | template <class _Tp> |
| 1204 | inline _LIBCPP_INLINE_VISIBILITY |
| 1205 | typename enable_if |
| 1206 | < |
| 1207 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1208 | _Tp |
| 1209 | >::type |
| 1210 | atomic_fetch_and(atomic<_Tp>* __o, _Tp __op) |
| 1211 | { |
| 1212 | return __o->fetch_and(__op); |
| 1213 | } |
| 1214 | |
| 1215 | // atomic_fetch_and_explicit |
| 1216 | |
| 1217 | template <class _Tp> |
| 1218 | inline _LIBCPP_INLINE_VISIBILITY |
| 1219 | typename enable_if |
| 1220 | < |
| 1221 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1222 | _Tp |
| 1223 | >::type |
| 1224 | atomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) |
| 1225 | { |
| 1226 | return __o->fetch_and(__op, __m); |
| 1227 | } |
| 1228 | |
| 1229 | template <class _Tp> |
| 1230 | inline _LIBCPP_INLINE_VISIBILITY |
| 1231 | typename enable_if |
| 1232 | < |
| 1233 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1234 | _Tp |
| 1235 | >::type |
| 1236 | atomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) |
| 1237 | { |
| 1238 | return __o->fetch_and(__op, __m); |
| 1239 | } |
| 1240 | |
| 1241 | // atomic_fetch_or |
| 1242 | |
| 1243 | template <class _Tp> |
| 1244 | inline _LIBCPP_INLINE_VISIBILITY |
| 1245 | typename enable_if |
| 1246 | < |
| 1247 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1248 | _Tp |
| 1249 | >::type |
| 1250 | atomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) |
| 1251 | { |
| 1252 | return __o->fetch_or(__op); |
| 1253 | } |
| 1254 | |
| 1255 | template <class _Tp> |
| 1256 | inline _LIBCPP_INLINE_VISIBILITY |
| 1257 | typename enable_if |
| 1258 | < |
| 1259 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1260 | _Tp |
| 1261 | >::type |
| 1262 | atomic_fetch_or(atomic<_Tp>* __o, _Tp __op) |
| 1263 | { |
| 1264 | return __o->fetch_or(__op); |
| 1265 | } |
| 1266 | |
| 1267 | // atomic_fetch_or_explicit |
| 1268 | |
| 1269 | template <class _Tp> |
| 1270 | inline _LIBCPP_INLINE_VISIBILITY |
| 1271 | typename enable_if |
| 1272 | < |
| 1273 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1274 | _Tp |
| 1275 | >::type |
| 1276 | atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) |
| 1277 | { |
| 1278 | return __o->fetch_or(__op, __m); |
| 1279 | } |
| 1280 | |
| 1281 | template <class _Tp> |
| 1282 | inline _LIBCPP_INLINE_VISIBILITY |
| 1283 | typename enable_if |
| 1284 | < |
| 1285 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1286 | _Tp |
| 1287 | >::type |
| 1288 | atomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) |
| 1289 | { |
| 1290 | return __o->fetch_or(__op, __m); |
| 1291 | } |
| 1292 | |
| 1293 | // atomic_fetch_xor |
| 1294 | |
| 1295 | template <class _Tp> |
| 1296 | inline _LIBCPP_INLINE_VISIBILITY |
| 1297 | typename enable_if |
| 1298 | < |
| 1299 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1300 | _Tp |
| 1301 | >::type |
| 1302 | atomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) |
| 1303 | { |
| 1304 | return __o->fetch_xor(__op); |
| 1305 | } |
| 1306 | |
| 1307 | template <class _Tp> |
| 1308 | inline _LIBCPP_INLINE_VISIBILITY |
| 1309 | typename enable_if |
| 1310 | < |
| 1311 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1312 | _Tp |
| 1313 | >::type |
| 1314 | atomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) |
| 1315 | { |
| 1316 | return __o->fetch_xor(__op); |
| 1317 | } |
| 1318 | |
| 1319 | // atomic_fetch_xor_explicit |
| 1320 | |
| 1321 | template <class _Tp> |
| 1322 | inline _LIBCPP_INLINE_VISIBILITY |
| 1323 | typename enable_if |
| 1324 | < |
| 1325 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1326 | _Tp |
| 1327 | >::type |
| 1328 | atomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) |
| 1329 | { |
| 1330 | return __o->fetch_xor(__op, __m); |
| 1331 | } |
| 1332 | |
| 1333 | template <class _Tp> |
| 1334 | inline _LIBCPP_INLINE_VISIBILITY |
| 1335 | typename enable_if |
| 1336 | < |
| 1337 | is_integral<_Tp>::value && !is_same<_Tp, bool>::value, |
| 1338 | _Tp |
| 1339 | >::type |
| 1340 | atomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) |
| 1341 | { |
| 1342 | return __o->fetch_xor(__op, __m); |
| 1343 | } |
Howard Hinnant | 4777bf2 | 2010-12-06 23:10:08 +0000 | [diff] [blame] | 1344 | |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1345 | // flag type and operations |
| 1346 | |
| 1347 | typedef struct atomic_flag |
| 1348 | { |
| 1349 | bool __a_; |
| 1350 | |
| 1351 | _LIBCPP_INLINE_VISIBILITY |
| 1352 | bool test_and_set(memory_order __m = memory_order_seq_cst) volatile |
| 1353 | {return __atomic_exchange(&__a_, true, __m);} |
| 1354 | _LIBCPP_INLINE_VISIBILITY |
| 1355 | bool test_and_set(memory_order __m = memory_order_seq_cst) |
| 1356 | {return __atomic_exchange(&__a_, true, __m);} |
| 1357 | _LIBCPP_INLINE_VISIBILITY |
| 1358 | void clear(memory_order __m = memory_order_seq_cst) volatile |
| 1359 | {__atomic_store(&__a_, false, __m);} |
| 1360 | _LIBCPP_INLINE_VISIBILITY |
| 1361 | void clear(memory_order __m = memory_order_seq_cst) |
| 1362 | {__atomic_store(&__a_, false, __m);} |
| 1363 | |
| 1364 | _LIBCPP_INLINE_VISIBILITY |
| 1365 | atomic_flag() {} // = default; |
| 1366 | _LIBCPP_INLINE_VISIBILITY |
| 1367 | atomic_flag(bool __b) : __a_(__b) {} |
| 1368 | |
| 1369 | #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
| 1370 | atomic_flag(const atomic_flag&) = delete; |
| 1371 | atomic_flag& operator=(const atomic_flag&) = delete; |
| 1372 | atomic_flag& operator=(const atomic_flag&) volatile = delete; |
| 1373 | #else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
| 1374 | private: |
| 1375 | atomic_flag(const atomic_flag&); |
| 1376 | atomic_flag& operator=(const atomic_flag&); |
| 1377 | atomic_flag& operator=(const atomic_flag&) volatile; |
| 1378 | #endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
| 1379 | } atomic_flag; |
| 1380 | |
| 1381 | inline _LIBCPP_INLINE_VISIBILITY |
| 1382 | bool |
| 1383 | atomic_flag_test_and_set(volatile atomic_flag* __o) |
| 1384 | { |
| 1385 | return __o->test_and_set(); |
| 1386 | } |
| 1387 | |
| 1388 | inline _LIBCPP_INLINE_VISIBILITY |
| 1389 | bool |
| 1390 | atomic_flag_test_and_set(atomic_flag* __o) |
| 1391 | { |
| 1392 | return __o->test_and_set(); |
| 1393 | } |
| 1394 | |
| 1395 | inline _LIBCPP_INLINE_VISIBILITY |
| 1396 | bool |
| 1397 | atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) |
| 1398 | { |
| 1399 | return __o->test_and_set(__m); |
| 1400 | } |
| 1401 | |
| 1402 | inline _LIBCPP_INLINE_VISIBILITY |
| 1403 | bool |
| 1404 | atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) |
| 1405 | { |
| 1406 | return __o->test_and_set(__m); |
| 1407 | } |
| 1408 | |
| 1409 | inline _LIBCPP_INLINE_VISIBILITY |
| 1410 | void |
| 1411 | atomic_flag_clear(volatile atomic_flag* __o) |
| 1412 | { |
| 1413 | __o->clear(); |
| 1414 | } |
| 1415 | |
| 1416 | inline _LIBCPP_INLINE_VISIBILITY |
| 1417 | void |
| 1418 | atomic_flag_clear(atomic_flag* __o) |
| 1419 | { |
| 1420 | __o->clear(); |
| 1421 | } |
| 1422 | |
| 1423 | inline _LIBCPP_INLINE_VISIBILITY |
| 1424 | void |
| 1425 | atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) |
| 1426 | { |
| 1427 | __o->clear(__m); |
| 1428 | } |
| 1429 | |
| 1430 | inline _LIBCPP_INLINE_VISIBILITY |
| 1431 | void |
| 1432 | atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) |
| 1433 | { |
| 1434 | __o->clear(__m); |
| 1435 | } |
| 1436 | |
| 1437 | // fences |
| 1438 | |
| 1439 | inline _LIBCPP_INLINE_VISIBILITY |
| 1440 | void |
| 1441 | atomic_thread_fence(memory_order __m) |
| 1442 | { |
| 1443 | __atomic_thread_fence(__m); |
| 1444 | } |
| 1445 | |
| 1446 | inline _LIBCPP_INLINE_VISIBILITY |
| 1447 | void |
| 1448 | atomic_signal_fence(memory_order __m) |
| 1449 | { |
| 1450 | __atomic_signal_fence(__m); |
| 1451 | } |
| 1452 | |
Howard Hinnant | d2f6afb | 2010-12-07 23:24:41 +0000 | [diff] [blame] | 1453 | // Atomics for standard typedef types |
| 1454 | |
| 1455 | typedef atomic<char> atomic_char; |
| 1456 | typedef atomic<signed char> atomic_schar; |
| 1457 | typedef atomic<unsigned char> atomic_uchar; |
| 1458 | typedef atomic<short> atomic_short; |
| 1459 | typedef atomic<unsigned short> atomic_ushort; |
| 1460 | typedef atomic<int> atomic_int; |
| 1461 | typedef atomic<unsigned int> atomic_uint; |
| 1462 | typedef atomic<long> atomic_long; |
| 1463 | typedef atomic<unsigned long> atomic_ulong; |
| 1464 | typedef atomic<long long> atomic_llong; |
| 1465 | typedef atomic<unsigned long long> atomic_ullong; |
| 1466 | typedef atomic<char16_t> atomic_char16_t; |
| 1467 | typedef atomic<char32_t> atomic_char32_t; |
| 1468 | typedef atomic<wchar_t> atomic_wchar_t; |
| 1469 | |
| 1470 | typedef atomic<int_least8_t> atomic_int_least8_t; |
| 1471 | typedef atomic<uint_least8_t> atomic_uint_least8_t; |
| 1472 | typedef atomic<int_least16_t> atomic_int_least16_t; |
| 1473 | typedef atomic<uint_least16_t> atomic_uint_least16_t; |
| 1474 | typedef atomic<int_least32_t> atomic_int_least32_t; |
| 1475 | typedef atomic<uint_least32_t> atomic_uint_least32_t; |
| 1476 | typedef atomic<int_least64_t> atomic_int_least64_t; |
| 1477 | typedef atomic<uint_least64_t> atomic_uint_least64_t; |
| 1478 | |
| 1479 | typedef atomic<int_fast8_t> atomic_int_fast8_t; |
| 1480 | typedef atomic<uint_fast8_t> atomic_uint_fast8_t; |
| 1481 | typedef atomic<int_fast16_t> atomic_int_fast16_t; |
| 1482 | typedef atomic<uint_fast16_t> atomic_uint_fast16_t; |
| 1483 | typedef atomic<int_fast32_t> atomic_int_fast32_t; |
| 1484 | typedef atomic<uint_fast32_t> atomic_uint_fast32_t; |
| 1485 | typedef atomic<int_fast64_t> atomic_int_fast64_t; |
| 1486 | typedef atomic<uint_fast64_t> atomic_uint_fast64_t; |
| 1487 | |
| 1488 | typedef atomic<intptr_t> atomic_intptr_t; |
| 1489 | typedef atomic<uintptr_t> atomic_uintptr_t; |
| 1490 | typedef atomic<size_t> atomic_size_t; |
| 1491 | typedef atomic<ptrdiff_t> atomic_ptrdiff_t; |
| 1492 | typedef atomic<intmax_t> atomic_intmax_t; |
| 1493 | typedef atomic<uintmax_t> atomic_uintmax_t; |
| 1494 | |
Howard Hinnant | 767ae2b | 2010-09-29 21:20:03 +0000 | [diff] [blame] | 1495 | #define ATOMIC_FLAG_INIT {false} |
Howard Hinnant | 611fdaf | 2010-10-04 18:52:54 +0000 | [diff] [blame] | 1496 | #define ATOMIC_VAR_INIT(__v) {__v} |
| 1497 | |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1498 | // lock-free property |
Howard Hinnant | 611fdaf | 2010-10-04 18:52:54 +0000 | [diff] [blame] | 1499 | |
Howard Hinnant | 770d1c4 | 2010-12-08 17:20:28 +0000 | [diff] [blame] | 1500 | #define ATOMIC_CHAR_LOCK_FREE 0 |
| 1501 | #define ATOMIC_CHAR16_T_LOCK_FREE 0 |
| 1502 | #define ATOMIC_CHAR32_T_LOCK_FREE 0 |
| 1503 | #define ATOMIC_WCHAR_T_LOCK_FREE 0 |
| 1504 | #define ATOMIC_SHORT_LOCK_FREE 0 |
| 1505 | #define ATOMIC_INT_LOCK_FREE 0 |
| 1506 | #define ATOMIC_LONG_LOCK_FREE 0 |
| 1507 | #define ATOMIC_LLONG_LOCK_FREE 0 |
| 1508 | |
Howard Hinnant | 154002b | 2011-03-31 16:39:39 +0000 | [diff] [blame] | 1509 | #endif // !__has_feature(cxx_atomic) |
| 1510 | |
Howard Hinnant | 8f73c63 | 2010-09-27 21:17:38 +0000 | [diff] [blame] | 1511 | _LIBCPP_END_NAMESPACE_STD |
| 1512 | |
| 1513 | #endif // _LIBCPP_ATOMIC |