2 //===--------------------------- atomic -----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_ATOMIC
12 #define _LIBCPP_ATOMIC
20 // order and consistency
22 typedef enum memory_order
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
32 template <class T> T kill_dependency(T y) noexcept;
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
45 // flag type and operations
47 typedef struct atomic_flag
49 bool test_and_set(memory_order m = memory_order_seq_cst) volatile noexcept;
50 bool test_and_set(memory_order m = memory_order_seq_cst) noexcept;
51 void clear(memory_order m = memory_order_seq_cst) volatile noexcept;
52 void clear(memory_order m = memory_order_seq_cst) noexcept;
53 atomic_flag() noexcept = default;
54 atomic_flag(const atomic_flag&) = delete;
55 atomic_flag& operator=(const atomic_flag&) = delete;
56 atomic_flag& operator=(const atomic_flag&) volatile = delete;
60 atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept;
63 atomic_flag_test_and_set(atomic_flag* obj) noexcept;
66 atomic_flag_test_and_set_explicit(volatile atomic_flag* obj,
67 memory_order m) noexcept;
70 atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m) noexcept;
73 atomic_flag_clear(volatile atomic_flag* obj) noexcept;
76 atomic_flag_clear(atomic_flag* obj) noexcept;
79 atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept;
82 atomic_flag_clear_explicit(atomic_flag* obj, memory_order m) noexcept;
84 #define ATOMIC_FLAG_INIT see below
85 #define ATOMIC_VAR_INIT(value) see below
90 bool is_lock_free() const volatile noexcept;
91 bool is_lock_free() const noexcept;
92 void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
93 void store(T desr, memory_order m = memory_order_seq_cst) noexcept;
94 T load(memory_order m = memory_order_seq_cst) const volatile noexcept;
95 T load(memory_order m = memory_order_seq_cst) const noexcept;
96 operator T() const volatile noexcept;
97 operator T() const noexcept;
98 T exchange(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
99 T exchange(T desr, memory_order m = memory_order_seq_cst) noexcept;
100 bool compare_exchange_weak(T& expc, T desr,
101 memory_order s, memory_order f) volatile noexcept;
102 bool compare_exchange_weak(T& expc, T desr, memory_order s, memory_order f) noexcept;
103 bool compare_exchange_strong(T& expc, T desr,
104 memory_order s, memory_order f) volatile noexcept;
105 bool compare_exchange_strong(T& expc, T desr,
106 memory_order s, memory_order f) noexcept;
107 bool compare_exchange_weak(T& expc, T desr,
108 memory_order m = memory_order_seq_cst) volatile noexcept;
109 bool compare_exchange_weak(T& expc, T desr,
110 memory_order m = memory_order_seq_cst) noexcept;
111 bool compare_exchange_strong(T& expc, T desr,
112 memory_order m = memory_order_seq_cst) volatile noexcept;
113 bool compare_exchange_strong(T& expc, T desr,
114 memory_order m = memory_order_seq_cst) noexcept;
116 atomic() noexcept = default;
117 constexpr atomic(T desr) noexcept;
118 atomic(const atomic&) = delete;
119 atomic& operator=(const atomic&) = delete;
120 atomic& operator=(const atomic&) volatile = delete;
121 T operator=(T) volatile noexcept;
122 T operator=(T) noexcept;
126 struct atomic<integral>
128 bool is_lock_free() const volatile noexcept;
129 bool is_lock_free() const noexcept;
130 void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept;
131 void store(integral desr, memory_order m = memory_order_seq_cst) noexcept;
132 integral load(memory_order m = memory_order_seq_cst) const volatile noexcept;
133 integral load(memory_order m = memory_order_seq_cst) const noexcept;
134 operator integral() const volatile noexcept;
135 operator integral() const noexcept;
136 integral exchange(integral desr,
137 memory_order m = memory_order_seq_cst) volatile noexcept;
138 integral exchange(integral desr, memory_order m = memory_order_seq_cst) noexcept;
139 bool compare_exchange_weak(integral& expc, integral desr,
140 memory_order s, memory_order f) volatile noexcept;
141 bool compare_exchange_weak(integral& expc, integral desr,
142 memory_order s, memory_order f) noexcept;
143 bool compare_exchange_strong(integral& expc, integral desr,
144 memory_order s, memory_order f) volatile noexcept;
145 bool compare_exchange_strong(integral& expc, integral desr,
146 memory_order s, memory_order f) noexcept;
147 bool compare_exchange_weak(integral& expc, integral desr,
148 memory_order m = memory_order_seq_cst) volatile noexcept;
149 bool compare_exchange_weak(integral& expc, integral desr,
150 memory_order m = memory_order_seq_cst) noexcept;
151 bool compare_exchange_strong(integral& expc, integral desr,
152 memory_order m = memory_order_seq_cst) volatile noexcept;
153 bool compare_exchange_strong(integral& expc, integral desr,
154 memory_order m = memory_order_seq_cst) noexcept;
157 fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
158 integral fetch_add(integral op, memory_order m = memory_order_seq_cst) noexcept;
160 fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
161 integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) noexcept;
163 fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
164 integral fetch_and(integral op, memory_order m = memory_order_seq_cst) noexcept;
166 fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
167 integral fetch_or(integral op, memory_order m = memory_order_seq_cst) noexcept;
169 fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
170 integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) noexcept;
172 atomic() noexcept = default;
173 constexpr atomic(integral desr) noexcept;
174 atomic(const atomic&) = delete;
175 atomic& operator=(const atomic&) = delete;
176 atomic& operator=(const atomic&) volatile = delete;
177 integral operator=(integral desr) volatile noexcept;
178 integral operator=(integral desr) noexcept;
180 integral operator++(int) volatile noexcept;
181 integral operator++(int) noexcept;
182 integral operator--(int) volatile noexcept;
183 integral operator--(int) noexcept;
184 integral operator++() volatile noexcept;
185 integral operator++() noexcept;
186 integral operator--() volatile noexcept;
187 integral operator--() noexcept;
188 integral operator+=(integral op) volatile noexcept;
189 integral operator+=(integral op) noexcept;
190 integral operator-=(integral op) volatile noexcept;
191 integral operator-=(integral op) noexcept;
192 integral operator&=(integral op) volatile noexcept;
193 integral operator&=(integral op) noexcept;
194 integral operator|=(integral op) volatile noexcept;
195 integral operator|=(integral op) noexcept;
196 integral operator^=(integral op) volatile noexcept;
197 integral operator^=(integral op) noexcept;
203 bool is_lock_free() const volatile noexcept;
204 bool is_lock_free() const noexcept;
205 void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
206 void store(T* desr, memory_order m = memory_order_seq_cst) noexcept;
207 T* load(memory_order m = memory_order_seq_cst) const volatile noexcept;
208 T* load(memory_order m = memory_order_seq_cst) const noexcept;
209 operator T*() const volatile noexcept;
210 operator T*() const noexcept;
211 T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
212 T* exchange(T* desr, memory_order m = memory_order_seq_cst) noexcept;
213 bool compare_exchange_weak(T*& expc, T* desr,
214 memory_order s, memory_order f) volatile noexcept;
215 bool compare_exchange_weak(T*& expc, T* desr,
216 memory_order s, memory_order f) noexcept;
217 bool compare_exchange_strong(T*& expc, T* desr,
218 memory_order s, memory_order f) volatile noexcept;
219 bool compare_exchange_strong(T*& expc, T* desr,
220 memory_order s, memory_order f) noexcept;
221 bool compare_exchange_weak(T*& expc, T* desr,
222 memory_order m = memory_order_seq_cst) volatile noexcept;
223 bool compare_exchange_weak(T*& expc, T* desr,
224 memory_order m = memory_order_seq_cst) noexcept;
225 bool compare_exchange_strong(T*& expc, T* desr,
226 memory_order m = memory_order_seq_cst) volatile noexcept;
227 bool compare_exchange_strong(T*& expc, T* desr,
228 memory_order m = memory_order_seq_cst) noexcept;
229 T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
230 T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
231 T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
232 T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
234 atomic() noexcept = default;
235 constexpr atomic(T* desr) noexcept;
236 atomic(const atomic&) = delete;
237 atomic& operator=(const atomic&) = delete;
238 atomic& operator=(const atomic&) volatile = delete;
240 T* operator=(T*) volatile noexcept;
241 T* operator=(T*) noexcept;
242 T* operator++(int) volatile noexcept;
243 T* operator++(int) noexcept;
244 T* operator--(int) volatile noexcept;
245 T* operator--(int) noexcept;
246 T* operator++() volatile noexcept;
247 T* operator++() noexcept;
248 T* operator--() volatile noexcept;
249 T* operator--() noexcept;
250 T* operator+=(ptrdiff_t op) volatile noexcept;
251 T* operator+=(ptrdiff_t op) noexcept;
252 T* operator-=(ptrdiff_t op) volatile noexcept;
253 T* operator-=(ptrdiff_t op) noexcept;
259 atomic_is_lock_free(const volatile atomic<T>* obj) noexcept;
263 atomic_is_lock_free(const atomic<T>* obj) noexcept;
267 atomic_init(volatile atomic<T>* obj, T desr) noexcept;
271 atomic_init(atomic<T>* obj, T desr) noexcept;
275 atomic_store(volatile atomic<T>* obj, T desr) noexcept;
279 atomic_store(atomic<T>* obj, T desr) noexcept;
283 atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
287 atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
291 atomic_load(const volatile atomic<T>* obj) noexcept;
295 atomic_load(const atomic<T>* obj) noexcept;
299 atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept;
303 atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept;
307 atomic_exchange(volatile atomic<T>* obj, T desr) noexcept;
311 atomic_exchange(atomic<T>* obj, T desr) noexcept;
315 atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
319 atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
323 atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr) noexcept;
327 atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept;
331 atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr) noexcept;
335 atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr) noexcept;
339 atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc,
341 memory_order s, memory_order f) noexcept;
345 atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr,
346 memory_order s, memory_order f) noexcept;
350 atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj,
352 memory_order s, memory_order f) noexcept;
356 atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc,
358 memory_order s, memory_order f) noexcept;
360 template <class Integral>
362 atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept;
364 template <class Integral>
366 atomic_fetch_add(atomic<Integral>* obj, Integral op) noexcept;
368 template <class Integral>
370 atomic_fetch_add_explicit(volatile atomic<Integral>* obj, Integral op,
371 memory_order m) noexcept;
372 template <class Integral>
374 atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op,
375 memory_order m) noexcept;
376 template <class Integral>
378 atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept;
380 template <class Integral>
382 atomic_fetch_sub(atomic<Integral>* obj, Integral op) noexcept;
384 template <class Integral>
386 atomic_fetch_sub_explicit(volatile atomic<Integral>* obj, Integral op,
387 memory_order m) noexcept;
388 template <class Integral>
390 atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op,
391 memory_order m) noexcept;
392 template <class Integral>
394 atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept;
396 template <class Integral>
398 atomic_fetch_and(atomic<Integral>* obj, Integral op) noexcept;
400 template <class Integral>
402 atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op,
403 memory_order m) noexcept;
404 template <class Integral>
406 atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op,
407 memory_order m) noexcept;
408 template <class Integral>
410 atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept;
412 template <class Integral>
414 atomic_fetch_or(atomic<Integral>* obj, Integral op) noexcept;
416 template <class Integral>
418 atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op,
419 memory_order m) noexcept;
420 template <class Integral>
422 atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op,
423 memory_order m) noexcept;
424 template <class Integral>
426 atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept;
428 template <class Integral>
430 atomic_fetch_xor(atomic<Integral>* obj, Integral op) noexcept;
432 template <class Integral>
434 atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op,
435 memory_order m) noexcept;
436 template <class Integral>
438 atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op,
439 memory_order m) noexcept;
443 atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
447 atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op) noexcept;
451 atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
452 memory_order m) noexcept;
455 atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
459 atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
463 atomic_fetch_sub(atomic<T*>* obj, ptrdiff_t op) noexcept;
467 atomic_fetch_sub_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
468 memory_order m) noexcept;
471 atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
473 // Atomics for standard typedef types
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;
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;
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;
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;
517 void atomic_thread_fence(memory_order m) noexcept;
518 void atomic_signal_fence(memory_order m) noexcept;
527 #include <type_traits>
529 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
530 #pragma GCC system_header
533 _LIBCPP_BEGIN_NAMESPACE_STD
535 #if !__has_feature(cxx_atomic)
536 #error <atomic> is not implemented
539 typedef enum memory_order
541 memory_order_relaxed, memory_order_consume, memory_order_acquire,
542 memory_order_release, memory_order_acq_rel, memory_order_seq_cst
546 inline _LIBCPP_INLINE_VISIBILITY
548 kill_dependency(_Tp __y) _NOEXCEPT
555 template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value>
556 struct __atomic_base // false
560 _LIBCPP_INLINE_VISIBILITY
561 bool is_lock_free() const volatile _NOEXCEPT
562 {return __c11_atomic_is_lock_free(sizeof(_Tp));}
563 _LIBCPP_INLINE_VISIBILITY
564 bool is_lock_free() const _NOEXCEPT
565 {return __c11_atomic_is_lock_free(sizeof(_Tp));}
566 _LIBCPP_INLINE_VISIBILITY
567 void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
568 {__c11_atomic_store(&__a_, __d, __m);}
569 _LIBCPP_INLINE_VISIBILITY
570 void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
571 {__c11_atomic_store(&__a_, __d, __m);}
572 _LIBCPP_INLINE_VISIBILITY
573 _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
574 {return __c11_atomic_load(&__a_, __m);}
575 _LIBCPP_INLINE_VISIBILITY
576 _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT
577 {return __c11_atomic_load(&__a_, __m);}
578 _LIBCPP_INLINE_VISIBILITY
579 operator _Tp() const volatile _NOEXCEPT {return load();}
580 _LIBCPP_INLINE_VISIBILITY
581 operator _Tp() const _NOEXCEPT {return load();}
582 _LIBCPP_INLINE_VISIBILITY
583 _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
584 {return __c11_atomic_exchange(&__a_, __d, __m);}
585 _LIBCPP_INLINE_VISIBILITY
586 _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
587 {return __c11_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 _NOEXCEPT
591 {return __c11_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) _NOEXCEPT
595 {return __c11_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 _NOEXCEPT
599 {return __c11_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) _NOEXCEPT
603 {return __c11_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 _NOEXCEPT
607 {return __c11_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) _NOEXCEPT
611 {return __c11_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 _NOEXCEPT
615 {return __c11_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) _NOEXCEPT
619 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
621 _LIBCPP_INLINE_VISIBILITY
622 __atomic_base() _NOEXCEPT {} // = default;
623 _LIBCPP_INLINE_VISIBILITY
624 _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
625 #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
626 __atomic_base(const __atomic_base&) = delete;
627 __atomic_base& operator=(const __atomic_base&) = delete;
628 __atomic_base& operator=(const __atomic_base&) volatile = delete;
629 #else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
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
640 struct __atomic_base<_Tp, true>
641 : public __atomic_base<_Tp, false>
643 typedef __atomic_base<_Tp, false> __base;
644 _LIBCPP_INLINE_VISIBILITY
645 __atomic_base() _NOEXCEPT {} // = default;
646 _LIBCPP_INLINE_VISIBILITY
647 _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
649 _LIBCPP_INLINE_VISIBILITY
650 _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
651 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
652 _LIBCPP_INLINE_VISIBILITY
653 _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
654 {return __c11_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 _NOEXCEPT
657 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
658 _LIBCPP_INLINE_VISIBILITY
659 _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
660 {return __c11_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 _NOEXCEPT
663 {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
664 _LIBCPP_INLINE_VISIBILITY
665 _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
666 {return __c11_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 _NOEXCEPT
669 {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
670 _LIBCPP_INLINE_VISIBILITY
671 _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
672 {return __c11_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 _NOEXCEPT
675 {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
676 _LIBCPP_INLINE_VISIBILITY
677 _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
678 {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
680 _LIBCPP_INLINE_VISIBILITY
681 _Tp operator++(int) volatile _NOEXCEPT {return fetch_add(_Tp(1));}
682 _LIBCPP_INLINE_VISIBILITY
683 _Tp operator++(int) _NOEXCEPT {return fetch_add(_Tp(1));}
684 _LIBCPP_INLINE_VISIBILITY
685 _Tp operator--(int) volatile _NOEXCEPT {return fetch_sub(_Tp(1));}
686 _LIBCPP_INLINE_VISIBILITY
687 _Tp operator--(int) _NOEXCEPT {return fetch_sub(_Tp(1));}
688 _LIBCPP_INLINE_VISIBILITY
689 _Tp operator++() volatile _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);}
690 _LIBCPP_INLINE_VISIBILITY
691 _Tp operator++() _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);}
692 _LIBCPP_INLINE_VISIBILITY
693 _Tp operator--() volatile _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);}
694 _LIBCPP_INLINE_VISIBILITY
695 _Tp operator--() _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);}
696 _LIBCPP_INLINE_VISIBILITY
697 _Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
698 _LIBCPP_INLINE_VISIBILITY
699 _Tp operator+=(_Tp __op) _NOEXCEPT {return fetch_add(__op) + __op;}
700 _LIBCPP_INLINE_VISIBILITY
701 _Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
702 _LIBCPP_INLINE_VISIBILITY
703 _Tp operator-=(_Tp __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
704 _LIBCPP_INLINE_VISIBILITY
705 _Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;}
706 _LIBCPP_INLINE_VISIBILITY
707 _Tp operator&=(_Tp __op) _NOEXCEPT {return fetch_and(__op) & __op;}
708 _LIBCPP_INLINE_VISIBILITY
709 _Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;}
710 _LIBCPP_INLINE_VISIBILITY
711 _Tp operator|=(_Tp __op) _NOEXCEPT {return fetch_or(__op) | __op;}
712 _LIBCPP_INLINE_VISIBILITY
713 _Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;}
714 _LIBCPP_INLINE_VISIBILITY
715 _Tp operator^=(_Tp __op) _NOEXCEPT {return fetch_xor(__op) ^ __op;}
722 : public __atomic_base<_Tp>
724 typedef __atomic_base<_Tp> __base;
725 _LIBCPP_INLINE_VISIBILITY
726 atomic() _NOEXCEPT {} // = default;
727 _LIBCPP_INLINE_VISIBILITY
728 _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
730 _LIBCPP_INLINE_VISIBILITY
731 _Tp operator=(_Tp __d) volatile _NOEXCEPT
732 {__base::store(__d); return __d;}
733 _LIBCPP_INLINE_VISIBILITY
734 _Tp operator=(_Tp __d) _NOEXCEPT
735 {__base::store(__d); return __d;}
742 : public __atomic_base<_Tp*>
744 typedef __atomic_base<_Tp*> __base;
745 _LIBCPP_INLINE_VISIBILITY
746 atomic() _NOEXCEPT {} // = default;
747 _LIBCPP_INLINE_VISIBILITY
748 _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
750 _LIBCPP_INLINE_VISIBILITY
751 _Tp* operator=(_Tp* __d) volatile _NOEXCEPT
752 {__base::store(__d); return __d;}
753 _LIBCPP_INLINE_VISIBILITY
754 _Tp* operator=(_Tp* __d) _NOEXCEPT
755 {__base::store(__d); return __d;}
757 _LIBCPP_INLINE_VISIBILITY
758 _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
760 {return __c11_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) _NOEXCEPT
763 {return __c11_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)
767 {return __c11_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) _NOEXCEPT
770 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
772 _LIBCPP_INLINE_VISIBILITY
773 _Tp* operator++(int) volatile _NOEXCEPT {return fetch_add(1);}
774 _LIBCPP_INLINE_VISIBILITY
775 _Tp* operator++(int) _NOEXCEPT {return fetch_add(1);}
776 _LIBCPP_INLINE_VISIBILITY
777 _Tp* operator--(int) volatile _NOEXCEPT {return fetch_sub(1);}
778 _LIBCPP_INLINE_VISIBILITY
779 _Tp* operator--(int) _NOEXCEPT {return fetch_sub(1);}
780 _LIBCPP_INLINE_VISIBILITY
781 _Tp* operator++() volatile _NOEXCEPT {return fetch_add(1) + 1;}
782 _LIBCPP_INLINE_VISIBILITY
783 _Tp* operator++() _NOEXCEPT {return fetch_add(1) + 1;}
784 _LIBCPP_INLINE_VISIBILITY
785 _Tp* operator--() volatile _NOEXCEPT {return fetch_sub(1) - 1;}
786 _LIBCPP_INLINE_VISIBILITY
787 _Tp* operator--() _NOEXCEPT {return fetch_sub(1) - 1;}
788 _LIBCPP_INLINE_VISIBILITY
789 _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
790 _LIBCPP_INLINE_VISIBILITY
791 _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT {return fetch_add(__op) + __op;}
792 _LIBCPP_INLINE_VISIBILITY
793 _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
794 _LIBCPP_INLINE_VISIBILITY
795 _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
798 // atomic_is_lock_free
801 inline _LIBCPP_INLINE_VISIBILITY
803 atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
805 return __o->is_lock_free();
809 inline _LIBCPP_INLINE_VISIBILITY
811 atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
813 return __o->is_lock_free();
819 inline _LIBCPP_INLINE_VISIBILITY
821 atomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
823 __c11_atomic_init(&__o->__a_, __d);
827 inline _LIBCPP_INLINE_VISIBILITY
829 atomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
831 __c11_atomic_init(&__o->__a_, __d);
837 inline _LIBCPP_INLINE_VISIBILITY
839 atomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
845 inline _LIBCPP_INLINE_VISIBILITY
847 atomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
852 // atomic_store_explicit
855 inline _LIBCPP_INLINE_VISIBILITY
857 atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
859 __o->store(__d, __m);
863 inline _LIBCPP_INLINE_VISIBILITY
865 atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
867 __o->store(__d, __m);
873 inline _LIBCPP_INLINE_VISIBILITY
875 atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT
881 inline _LIBCPP_INLINE_VISIBILITY
883 atomic_load(const atomic<_Tp>* __o) _NOEXCEPT
888 // atomic_load_explicit
891 inline _LIBCPP_INLINE_VISIBILITY
893 atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
895 return __o->load(__m);
899 inline _LIBCPP_INLINE_VISIBILITY
901 atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
903 return __o->load(__m);
909 inline _LIBCPP_INLINE_VISIBILITY
911 atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
913 return __o->exchange(__d);
917 inline _LIBCPP_INLINE_VISIBILITY
919 atomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
921 return __o->exchange(__d);
924 // atomic_exchange_explicit
927 inline _LIBCPP_INLINE_VISIBILITY
929 atomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
931 return __o->exchange(__d, __m);
935 inline _LIBCPP_INLINE_VISIBILITY
937 atomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
939 return __o->exchange(__d, __m);
942 // atomic_compare_exchange_weak
945 inline _LIBCPP_INLINE_VISIBILITY
947 atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
949 return __o->compare_exchange_weak(*__e, __d);
953 inline _LIBCPP_INLINE_VISIBILITY
955 atomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
957 return __o->compare_exchange_weak(*__e, __d);
960 // atomic_compare_exchange_strong
963 inline _LIBCPP_INLINE_VISIBILITY
965 atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
967 return __o->compare_exchange_strong(*__e, __d);
971 inline _LIBCPP_INLINE_VISIBILITY
973 atomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
975 return __o->compare_exchange_strong(*__e, __d);
978 // atomic_compare_exchange_weak_explicit
981 inline _LIBCPP_INLINE_VISIBILITY
983 atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e,
985 memory_order __s, memory_order __f) _NOEXCEPT
987 return __o->compare_exchange_weak(*__e, __d, __s, __f);
991 inline _LIBCPP_INLINE_VISIBILITY
993 atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d,
994 memory_order __s, memory_order __f) _NOEXCEPT
996 return __o->compare_exchange_weak(*__e, __d, __s, __f);
999 // atomic_compare_exchange_strong_explicit
1001 template <class _Tp>
1002 inline _LIBCPP_INLINE_VISIBILITY
1004 atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o,
1006 memory_order __s, memory_order __f) _NOEXCEPT
1008 return __o->compare_exchange_strong(*__e, __d, __s, __f);
1011 template <class _Tp>
1012 inline _LIBCPP_INLINE_VISIBILITY
1014 atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e,
1016 memory_order __s, memory_order __f) _NOEXCEPT
1018 return __o->compare_exchange_strong(*__e, __d, __s, __f);
1023 template <class _Tp>
1024 inline _LIBCPP_INLINE_VISIBILITY
1027 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1030 atomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1032 return __o->fetch_add(__op);
1035 template <class _Tp>
1036 inline _LIBCPP_INLINE_VISIBILITY
1039 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1042 atomic_fetch_add(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1044 return __o->fetch_add(__op);
1047 template <class _Tp>
1048 inline _LIBCPP_INLINE_VISIBILITY
1050 atomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
1052 return __o->fetch_add(__op);
1055 template <class _Tp>
1056 inline _LIBCPP_INLINE_VISIBILITY
1058 atomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
1060 return __o->fetch_add(__op);
1063 // atomic_fetch_add_explicit
1065 template <class _Tp>
1066 inline _LIBCPP_INLINE_VISIBILITY
1069 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1072 atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1074 return __o->fetch_add(__op, __m);
1077 template <class _Tp>
1078 inline _LIBCPP_INLINE_VISIBILITY
1081 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1084 atomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1086 return __o->fetch_add(__op, __m);
1089 template <class _Tp>
1090 inline _LIBCPP_INLINE_VISIBILITY
1092 atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
1093 memory_order __m) _NOEXCEPT
1095 return __o->fetch_add(__op, __m);
1098 template <class _Tp>
1099 inline _LIBCPP_INLINE_VISIBILITY
1101 atomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
1103 return __o->fetch_add(__op, __m);
1108 template <class _Tp>
1109 inline _LIBCPP_INLINE_VISIBILITY
1112 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1115 atomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1117 return __o->fetch_sub(__op);
1120 template <class _Tp>
1121 inline _LIBCPP_INLINE_VISIBILITY
1124 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1127 atomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1129 return __o->fetch_sub(__op);
1132 template <class _Tp>
1133 inline _LIBCPP_INLINE_VISIBILITY
1135 atomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
1137 return __o->fetch_sub(__op);
1140 template <class _Tp>
1141 inline _LIBCPP_INLINE_VISIBILITY
1143 atomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
1145 return __o->fetch_sub(__op);
1148 // atomic_fetch_sub_explicit
1150 template <class _Tp>
1151 inline _LIBCPP_INLINE_VISIBILITY
1154 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1157 atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1159 return __o->fetch_sub(__op, __m);
1162 template <class _Tp>
1163 inline _LIBCPP_INLINE_VISIBILITY
1166 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1169 atomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1171 return __o->fetch_sub(__op, __m);
1174 template <class _Tp>
1175 inline _LIBCPP_INLINE_VISIBILITY
1177 atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
1178 memory_order __m) _NOEXCEPT
1180 return __o->fetch_sub(__op, __m);
1183 template <class _Tp>
1184 inline _LIBCPP_INLINE_VISIBILITY
1186 atomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
1188 return __o->fetch_sub(__op, __m);
1193 template <class _Tp>
1194 inline _LIBCPP_INLINE_VISIBILITY
1197 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1200 atomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1202 return __o->fetch_and(__op);
1205 template <class _Tp>
1206 inline _LIBCPP_INLINE_VISIBILITY
1209 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1212 atomic_fetch_and(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1214 return __o->fetch_and(__op);
1217 // atomic_fetch_and_explicit
1219 template <class _Tp>
1220 inline _LIBCPP_INLINE_VISIBILITY
1223 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1226 atomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1228 return __o->fetch_and(__op, __m);
1231 template <class _Tp>
1232 inline _LIBCPP_INLINE_VISIBILITY
1235 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1238 atomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1240 return __o->fetch_and(__op, __m);
1245 template <class _Tp>
1246 inline _LIBCPP_INLINE_VISIBILITY
1249 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1252 atomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1254 return __o->fetch_or(__op);
1257 template <class _Tp>
1258 inline _LIBCPP_INLINE_VISIBILITY
1261 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1264 atomic_fetch_or(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1266 return __o->fetch_or(__op);
1269 // atomic_fetch_or_explicit
1271 template <class _Tp>
1272 inline _LIBCPP_INLINE_VISIBILITY
1275 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1278 atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1280 return __o->fetch_or(__op, __m);
1283 template <class _Tp>
1284 inline _LIBCPP_INLINE_VISIBILITY
1287 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1290 atomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1292 return __o->fetch_or(__op, __m);
1297 template <class _Tp>
1298 inline _LIBCPP_INLINE_VISIBILITY
1301 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1304 atomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1306 return __o->fetch_xor(__op);
1309 template <class _Tp>
1310 inline _LIBCPP_INLINE_VISIBILITY
1313 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1316 atomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1318 return __o->fetch_xor(__op);
1321 // atomic_fetch_xor_explicit
1323 template <class _Tp>
1324 inline _LIBCPP_INLINE_VISIBILITY
1327 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1330 atomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1332 return __o->fetch_xor(__op, __m);
1335 template <class _Tp>
1336 inline _LIBCPP_INLINE_VISIBILITY
1339 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1342 atomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1344 return __o->fetch_xor(__op, __m);
1347 // flag type and operations
1349 typedef struct atomic_flag
1353 _LIBCPP_INLINE_VISIBILITY
1354 bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
1355 {return __c11_atomic_exchange(&__a_, true, __m);}
1356 _LIBCPP_INLINE_VISIBILITY
1357 bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT
1358 {return __c11_atomic_exchange(&__a_, true, __m);}
1359 _LIBCPP_INLINE_VISIBILITY
1360 void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
1361 {__c11_atomic_store(&__a_, false, __m);}
1362 _LIBCPP_INLINE_VISIBILITY
1363 void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT
1364 {__c11_atomic_store(&__a_, false, __m);}
1366 _LIBCPP_INLINE_VISIBILITY
1367 atomic_flag() _NOEXCEPT {} // = default;
1368 _LIBCPP_INLINE_VISIBILITY
1369 atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {}
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
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
1383 inline _LIBCPP_INLINE_VISIBILITY
1385 atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT
1387 return __o->test_and_set();
1390 inline _LIBCPP_INLINE_VISIBILITY
1392 atomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT
1394 return __o->test_and_set();
1397 inline _LIBCPP_INLINE_VISIBILITY
1399 atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
1401 return __o->test_and_set(__m);
1404 inline _LIBCPP_INLINE_VISIBILITY
1406 atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
1408 return __o->test_and_set(__m);
1411 inline _LIBCPP_INLINE_VISIBILITY
1413 atomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT
1418 inline _LIBCPP_INLINE_VISIBILITY
1420 atomic_flag_clear(atomic_flag* __o) _NOEXCEPT
1425 inline _LIBCPP_INLINE_VISIBILITY
1427 atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
1432 inline _LIBCPP_INLINE_VISIBILITY
1434 atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
1441 inline _LIBCPP_INLINE_VISIBILITY
1443 atomic_thread_fence(memory_order __m) _NOEXCEPT
1445 __c11_atomic_thread_fence(__m);
1448 inline _LIBCPP_INLINE_VISIBILITY
1450 atomic_signal_fence(memory_order __m) _NOEXCEPT
1452 __c11_atomic_signal_fence(__m);
1455 // Atomics for standard typedef types
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;
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;
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;
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;
1497 #define ATOMIC_FLAG_INIT {false}
1498 #define ATOMIC_VAR_INIT(__v) {__v}
1500 // lock-free property
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
1511 #endif // !__has_feature(cxx_atomic)
1513 _LIBCPP_END_NAMESPACE_STD
1515 #endif // _LIBCPP_ATOMIC