32 #ifndef _GLIBCXX_ATOMIC
33 #define _GLIBCXX_ATOMIC 1
35 #pragma GCC system_header
37 #ifndef __GXX_EXPERIMENTAL_CXX0X__
45 namespace std _GLIBCXX_VISIBILITY(default)
47 _GLIBCXX_BEGIN_NAMESPACE_VERSION
59 __atomic_base<bool> _M_base;
72 {
return _M_base.operator=(__i); }
75 {
return _M_base.load(); }
77 operator bool()
const volatile
78 {
return _M_base.load(); }
81 is_lock_free()
const {
return _M_base.is_lock_free(); }
84 is_lock_free()
const volatile {
return _M_base.is_lock_free(); }
88 { _M_base.store(__i, __m); }
91 store(
bool __i,
memory_order __m = memory_order_seq_cst)
volatile
92 { _M_base.store(__i, __m); }
96 {
return _M_base.load(__m); }
99 load(
memory_order __m = memory_order_seq_cst)
const volatile
100 {
return _M_base.load(__m); }
103 exchange(
bool __i,
memory_order __m = memory_order_seq_cst)
104 {
return _M_base.exchange(__i, __m); }
107 exchange(
bool __i,
memory_order __m = memory_order_seq_cst)
volatile
108 {
return _M_base.exchange(__i, __m); }
111 compare_exchange_weak(
bool& __i1,
bool __i2,
memory_order __m1,
113 {
return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); }
116 compare_exchange_weak(
bool& __i1,
bool __i2,
memory_order __m1,
118 {
return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); }
121 compare_exchange_weak(
bool& __i1,
bool __i2,
123 {
return _M_base.compare_exchange_weak(__i1, __i2, __m); }
126 compare_exchange_weak(
bool& __i1,
bool __i2,
128 {
return _M_base.compare_exchange_weak(__i1, __i2, __m); }
131 compare_exchange_strong(
bool& __i1,
bool __i2,
memory_order __m1,
133 {
return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); }
136 compare_exchange_strong(
bool& __i1,
bool __i2,
memory_order __m1,
138 {
return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); }
141 compare_exchange_strong(
bool& __i1,
bool __i2,
143 {
return _M_base.compare_exchange_strong(__i1, __i2, __m); }
146 compare_exchange_strong(
bool& __i1,
bool __i2,
148 {
return _M_base.compare_exchange_strong(__i1, __i2, __m); }
154 template<
typename _Tp>
167 constexpr
atomic(_Tp __i) : _M_i(__i) { }
169 operator _Tp()
const;
171 operator _Tp()
const volatile;
174 operator=(_Tp __i) { store(__i);
return __i; }
177 operator=(_Tp __i)
volatile { store(__i);
return __i; }
180 is_lock_free()
const;
183 is_lock_free()
const volatile;
189 store(_Tp,
memory_order = memory_order_seq_cst)
volatile;
195 load(
memory_order = memory_order_seq_cst)
const volatile;
201 exchange(_Tp __i,
memory_order = memory_order_seq_cst)
volatile;
210 compare_exchange_weak(_Tp&, _Tp,
memory_order = memory_order_seq_cst);
213 compare_exchange_weak(_Tp&, _Tp,
223 compare_exchange_strong(_Tp&, _Tp,
memory_order = memory_order_seq_cst);
226 compare_exchange_strong(_Tp&, _Tp,
232 template<
typename _Tp>
235 typedef _Tp* __pointer_type;
236 typedef __atomic_base<_Tp*> __base_type;
245 constexpr
atomic(__pointer_type __p) : _M_b(__p) { }
247 operator __pointer_type()
const
248 {
return __pointer_type(_M_b); }
250 operator __pointer_type()
const volatile
251 {
return __pointer_type(_M_b); }
254 operator=(__pointer_type __p)
255 {
return _M_b.operator=(__p); }
258 operator=(__pointer_type __p)
volatile
259 {
return _M_b.operator=(__p); }
266 operator++(
int)
volatile
274 operator--(
int)
volatile
282 operator++()
volatile
290 operator--()
volatile
294 operator+=(ptrdiff_t __d)
295 {
return _M_b.operator+=(__d); }
298 operator+=(ptrdiff_t __d)
volatile
299 {
return _M_b.operator+=(__d); }
302 operator-=(ptrdiff_t __d)
303 {
return _M_b.operator-=(__d); }
306 operator-=(ptrdiff_t __d)
volatile
307 {
return _M_b.operator-=(__d); }
311 {
return _M_b.is_lock_free(); }
314 is_lock_free()
const volatile
315 {
return _M_b.is_lock_free(); }
318 store(__pointer_type __p,
memory_order __m = memory_order_seq_cst)
319 {
return _M_b.store(__p, __m); }
322 store(__pointer_type __p,
324 {
return _M_b.store(__p, __m); }
328 {
return _M_b.load(__m); }
331 load(
memory_order __m = memory_order_seq_cst)
const volatile
332 {
return _M_b.load(__m); }
335 exchange(__pointer_type __p,
memory_order __m = memory_order_seq_cst)
336 {
return _M_b.exchange(__p, __m); }
339 exchange(__pointer_type __p,
341 {
return _M_b.exchange(__p, __m); }
344 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
346 {
return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
349 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
351 {
return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
354 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
357 return compare_exchange_weak(__p1, __p2, __m,
358 __calculate_memory_order(__m));
362 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
365 return compare_exchange_weak(__p1, __p2, __m,
366 __calculate_memory_order(__m));
370 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
372 {
return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
375 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
377 {
return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
380 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
383 return _M_b.compare_exchange_strong(__p1, __p2, __m,
384 __calculate_memory_order(__m));
388 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
391 return _M_b.compare_exchange_strong(__p1, __p2, __m,
392 __calculate_memory_order(__m));
396 fetch_add(ptrdiff_t __d,
memory_order __m = memory_order_seq_cst)
397 {
return _M_b.fetch_add(__d, __m); }
400 fetch_add(ptrdiff_t __d,
402 {
return _M_b.fetch_add(__d, __m); }
405 fetch_sub(ptrdiff_t __d,
memory_order __m = memory_order_seq_cst)
406 {
return _M_b.fetch_sub(__d, __m); }
409 fetch_sub(ptrdiff_t __d,
411 {
return _M_b.fetch_sub(__d, __m); }
419 typedef bool __integral_type;
430 using __base_type::operator __integral_type;
431 using __base_type::operator=;
438 typedef char __integral_type;
447 constexpr
atomic(__integral_type __i) : __base_type(__i) { }
449 using __base_type::operator __integral_type;
450 using __base_type::operator=;
457 typedef signed char __integral_type;
466 constexpr
atomic(__integral_type __i) : __base_type(__i) { }
468 using __base_type::operator __integral_type;
469 using __base_type::operator=;
476 typedef unsigned char __integral_type;
485 constexpr
atomic(__integral_type __i) : __base_type(__i) { }
487 using __base_type::operator __integral_type;
488 using __base_type::operator=;
495 typedef short __integral_type;
504 constexpr
atomic(__integral_type __i) : __base_type(__i) { }
506 using __base_type::operator __integral_type;
507 using __base_type::operator=;
514 typedef unsigned short __integral_type;
523 constexpr
atomic(__integral_type __i) : __base_type(__i) { }
525 using __base_type::operator __integral_type;
526 using __base_type::operator=;
533 typedef int __integral_type;
542 constexpr
atomic(__integral_type __i) : __base_type(__i) { }
544 using __base_type::operator __integral_type;
545 using __base_type::operator=;
552 typedef unsigned int __integral_type;
561 constexpr
atomic(__integral_type __i) : __base_type(__i) { }
563 using __base_type::operator __integral_type;
564 using __base_type::operator=;
571 typedef long __integral_type;
580 constexpr
atomic(__integral_type __i) : __base_type(__i) { }
582 using __base_type::operator __integral_type;
583 using __base_type::operator=;
590 typedef unsigned long __integral_type;
599 constexpr
atomic(__integral_type __i) : __base_type(__i) { }
601 using __base_type::operator __integral_type;
602 using __base_type::operator=;
609 typedef long long __integral_type;
618 constexpr
atomic(__integral_type __i) : __base_type(__i) { }
620 using __base_type::operator __integral_type;
621 using __base_type::operator=;
628 typedef unsigned long long __integral_type;
637 constexpr
atomic(__integral_type __i) : __base_type(__i) { }
639 using __base_type::operator __integral_type;
640 using __base_type::operator=;
647 typedef wchar_t __integral_type;
656 constexpr
atomic(__integral_type __i) : __base_type(__i) { }
658 using __base_type::operator __integral_type;
659 using __base_type::operator=;
666 typedef char16_t __integral_type;
675 constexpr
atomic(__integral_type __i) : __base_type(__i) { }
677 using __base_type::operator __integral_type;
678 using __base_type::operator=;
685 typedef char32_t __integral_type;
694 constexpr
atomic(__integral_type __i) : __base_type(__i) { }
696 using __base_type::operator __integral_type;
697 using __base_type::operator=;
703 atomic_flag_test_and_set_explicit(atomic_flag* __a,
memory_order __m)
704 {
return __a->test_and_set(__m); }
707 atomic_flag_test_and_set_explicit(
volatile atomic_flag* __a,
709 {
return __a->test_and_set(__m); }
712 atomic_flag_clear_explicit(atomic_flag* __a,
memory_order __m)
716 atomic_flag_clear_explicit(
volatile atomic_flag* __a,
memory_order __m)
720 atomic_flag_test_and_set(atomic_flag* __a)
721 {
return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
724 atomic_flag_test_and_set(
volatile atomic_flag* __a)
725 {
return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
728 atomic_flag_clear(atomic_flag* __a)
729 { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
732 atomic_flag_clear(
volatile atomic_flag* __a)
733 { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
737 template<
typename _ITp>
739 atomic_is_lock_free(
const atomic<_ITp>* __a)
740 {
return __a->is_lock_free(); }
742 template<
typename _ITp>
744 atomic_is_lock_free(
const volatile atomic<_ITp>* __a)
745 {
return __a->is_lock_free(); }
747 template<
typename _ITp>
749 atomic_init(atomic<_ITp>* __a, _ITp __i);
751 template<
typename _ITp>
753 atomic_init(
volatile atomic<_ITp>* __a, _ITp __i);
755 template<
typename _ITp>
757 atomic_store_explicit(atomic<_ITp>* __a, _ITp __i,
memory_order __m)
758 { __a->store(__i, __m); }
760 template<
typename _ITp>
762 atomic_store_explicit(
volatile atomic<_ITp>* __a, _ITp __i,
764 { __a->store(__i, __m); }
766 template<
typename _ITp>
768 atomic_load_explicit(
const atomic<_ITp>* __a,
memory_order __m)
769 {
return __a->load(__m); }
771 template<
typename _ITp>
773 atomic_load_explicit(
const volatile atomic<_ITp>* __a,
775 {
return __a->load(__m); }
777 template<
typename _ITp>
779 atomic_exchange_explicit(atomic<_ITp>* __a, _ITp __i,
781 {
return __a->exchange(__i, __m); }
783 template<
typename _ITp>
785 atomic_exchange_explicit(
volatile atomic<_ITp>* __a, _ITp __i,
787 {
return __a->exchange(__i, __m); }
789 template<
typename _ITp>
791 atomic_compare_exchange_weak_explicit(atomic<_ITp>* __a,
792 _ITp* __i1, _ITp __i2,
794 {
return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
796 template<
typename _ITp>
798 atomic_compare_exchange_weak_explicit(
volatile atomic<_ITp>* __a,
799 _ITp* __i1, _ITp __i2,
801 {
return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
803 template<
typename _ITp>
805 atomic_compare_exchange_strong_explicit(atomic<_ITp>* __a,
806 _ITp* __i1, _ITp __i2,
809 {
return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
811 template<
typename _ITp>
813 atomic_compare_exchange_strong_explicit(
volatile atomic<_ITp>* __a,
814 _ITp* __i1, _ITp __i2,
817 {
return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
820 template<
typename _ITp>
822 atomic_store(atomic<_ITp>* __a, _ITp __i)
823 { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
825 template<
typename _ITp>
827 atomic_store(
volatile atomic<_ITp>* __a, _ITp __i)
828 { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
830 template<
typename _ITp>
832 atomic_load(
const atomic<_ITp>* __a)
833 {
return atomic_load_explicit(__a, memory_order_seq_cst); }
835 template<
typename _ITp>
837 atomic_load(
const volatile atomic<_ITp>* __a)
838 {
return atomic_load_explicit(__a, memory_order_seq_cst); }
840 template<
typename _ITp>
842 atomic_exchange(atomic<_ITp>* __a, _ITp __i)
843 {
return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
845 template<
typename _ITp>
847 atomic_exchange(
volatile atomic<_ITp>* __a, _ITp __i)
848 {
return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
850 template<
typename _ITp>
852 atomic_compare_exchange_weak(atomic<_ITp>* __a,
853 _ITp* __i1, _ITp __i2)
855 return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
856 memory_order_seq_cst,
857 memory_order_seq_cst);
860 template<
typename _ITp>
862 atomic_compare_exchange_weak(
volatile atomic<_ITp>* __a,
863 _ITp* __i1, _ITp __i2)
865 return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
866 memory_order_seq_cst,
867 memory_order_seq_cst);
870 template<
typename _ITp>
872 atomic_compare_exchange_strong(atomic<_ITp>* __a,
873 _ITp* __i1, _ITp __i2)
875 return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
876 memory_order_seq_cst,
877 memory_order_seq_cst);
880 template<
typename _ITp>
882 atomic_compare_exchange_strong(
volatile atomic<_ITp>* __a,
883 _ITp* __i1, _ITp __i2)
885 return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
886 memory_order_seq_cst,
887 memory_order_seq_cst);
894 template<
typename _ITp>
896 atomic_fetch_add_explicit(__atomic_base<_ITp>* __a, _ITp __i,
898 {
return __a->fetch_add(__i, __m); }
900 template<
typename _ITp>
902 atomic_fetch_add_explicit(
volatile __atomic_base<_ITp>* __a, _ITp __i,
904 {
return __a->fetch_add(__i, __m); }
906 template<
typename _ITp>
908 atomic_fetch_sub_explicit(__atomic_base<_ITp>* __a, _ITp __i,
910 {
return __a->fetch_sub(__i, __m); }
912 template<
typename _ITp>
914 atomic_fetch_sub_explicit(
volatile __atomic_base<_ITp>* __a, _ITp __i,
916 {
return __a->fetch_sub(__i, __m); }
918 template<
typename _ITp>
920 atomic_fetch_and_explicit(__atomic_base<_ITp>* __a, _ITp __i,
922 {
return __a->fetch_and(__i, __m); }
924 template<
typename _ITp>
926 atomic_fetch_and_explicit(
volatile __atomic_base<_ITp>* __a, _ITp __i,
928 {
return __a->fetch_and(__i, __m); }
930 template<
typename _ITp>
932 atomic_fetch_or_explicit(__atomic_base<_ITp>* __a, _ITp __i,
934 {
return __a->fetch_or(__i, __m); }
936 template<
typename _ITp>
938 atomic_fetch_or_explicit(
volatile __atomic_base<_ITp>* __a, _ITp __i,
940 {
return __a->fetch_or(__i, __m); }
942 template<
typename _ITp>
944 atomic_fetch_xor_explicit(__atomic_base<_ITp>* __a, _ITp __i,
946 {
return __a->fetch_xor(__i, __m); }
948 template<
typename _ITp>
950 atomic_fetch_xor_explicit(
volatile __atomic_base<_ITp>* __a, _ITp __i,
952 {
return __a->fetch_xor(__i, __m); }
954 template<
typename _ITp>
956 atomic_fetch_add(__atomic_base<_ITp>* __a, _ITp __i)
957 {
return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
959 template<
typename _ITp>
961 atomic_fetch_add(
volatile __atomic_base<_ITp>* __a, _ITp __i)
962 {
return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
964 template<
typename _ITp>
966 atomic_fetch_sub(__atomic_base<_ITp>* __a, _ITp __i)
967 {
return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
969 template<
typename _ITp>
971 atomic_fetch_sub(
volatile __atomic_base<_ITp>* __a, _ITp __i)
972 {
return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
974 template<
typename _ITp>
976 atomic_fetch_and(__atomic_base<_ITp>* __a, _ITp __i)
977 {
return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
979 template<
typename _ITp>
981 atomic_fetch_and(
volatile __atomic_base<_ITp>* __a, _ITp __i)
982 {
return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
984 template<
typename _ITp>
986 atomic_fetch_or(__atomic_base<_ITp>* __a, _ITp __i)
987 {
return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
989 template<
typename _ITp>
991 atomic_fetch_or(
volatile __atomic_base<_ITp>* __a, _ITp __i)
992 {
return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
994 template<
typename _ITp>
996 atomic_fetch_xor(__atomic_base<_ITp>* __a, _ITp __i)
997 {
return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
999 template<
typename _ITp>
1001 atomic_fetch_xor(
volatile __atomic_base<_ITp>* __a, _ITp __i)
1002 {
return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
1006 template<
typename _ITp>
1008 atomic_fetch_add_explicit(atomic<_ITp*>* __a, ptrdiff_t __d,
1010 {
return __a->fetch_add(__d, __m); }
1012 template<
typename _ITp>
1014 atomic_fetch_add_explicit(
volatile atomic<_ITp*>* __a, ptrdiff_t __d,
1016 {
return __a->fetch_add(__d, __m); }
1018 template<
typename _ITp>
1020 atomic_fetch_add(
volatile atomic<_ITp*>* __a, ptrdiff_t __d)
1021 {
return __a->fetch_add(__d); }
1023 template<
typename _ITp>
1025 atomic_fetch_add(atomic<_ITp*>* __a, ptrdiff_t __d)
1026 {
return __a->fetch_add(__d); }
1028 template<
typename _ITp>
1030 atomic_fetch_sub_explicit(
volatile atomic<_ITp*>* __a,
1032 {
return __a->fetch_sub(__d, __m); }
1034 template<
typename _ITp>
1036 atomic_fetch_sub_explicit(atomic<_ITp*>* __a, ptrdiff_t __d,
1038 {
return __a->fetch_sub(__d, __m); }
1040 template<
typename _ITp>
1042 atomic_fetch_sub(
volatile atomic<_ITp*>* __a, ptrdiff_t __d)
1043 {
return __a->fetch_sub(__d); }
1045 template<
typename _ITp>
1047 atomic_fetch_sub(atomic<_ITp*>* __a, ptrdiff_t __d)
1048 {
return __a->fetch_sub(__d); }
1051 _GLIBCXX_END_NAMESPACE_VERSION