32#ifndef _GLIBCXX_ATOMIC
33#define _GLIBCXX_ATOMIC 1
35#pragma GCC system_header
37#if __cplusplus < 201103L
43namespace std _GLIBCXX_VISIBILITY(default)
45_GLIBCXX_BEGIN_NAMESPACE_VERSION
52#if __cplusplus >= 201703L
53# define __cpp_lib_atomic_is_always_lock_free 201603L
56 template<
typename _Tp>
64 using value_type = bool;
67 __atomic_base<bool> _M_base;
70 atomic()
noexcept =
default;
71 ~atomic()
noexcept =
default;
72 atomic(
const atomic&) =
delete;
73 atomic& operator=(
const atomic&) =
delete;
74 atomic& operator=(
const atomic&)
volatile =
delete;
76 constexpr atomic(
bool __i) noexcept : _M_base(__i) { }
79 operator=(
bool __i)
noexcept
80 {
return _M_base.operator=(__i); }
83 operator=(
bool __i)
volatile noexcept
84 {
return _M_base.operator=(__i); }
86 operator bool()
const noexcept
87 {
return _M_base.load(); }
89 operator bool()
const volatile noexcept
90 {
return _M_base.load(); }
93 is_lock_free()
const noexcept {
return _M_base.is_lock_free(); }
96 is_lock_free()
const volatile noexcept {
return _M_base.is_lock_free(); }
98#if __cplusplus >= 201703L
103 store(
bool __i,
memory_order __m = memory_order_seq_cst)
noexcept
104 { _M_base.store(__i, __m); }
107 store(
bool __i,
memory_order __m = memory_order_seq_cst)
volatile noexcept
108 { _M_base.store(__i, __m); }
111 load(
memory_order __m = memory_order_seq_cst)
const noexcept
112 {
return _M_base.load(__m); }
115 load(
memory_order __m = memory_order_seq_cst)
const volatile noexcept
116 {
return _M_base.load(__m); }
119 exchange(
bool __i,
memory_order __m = memory_order_seq_cst)
noexcept
120 {
return _M_base.exchange(__i, __m); }
124 memory_order __m = memory_order_seq_cst)
volatile noexcept
125 {
return _M_base.exchange(__i, __m); }
128 compare_exchange_weak(
bool& __i1,
bool __i2,
memory_order __m1,
130 {
return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); }
133 compare_exchange_weak(
bool& __i1,
bool __i2,
memory_order __m1,
135 {
return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); }
138 compare_exchange_weak(
bool& __i1,
bool __i2,
140 {
return _M_base.compare_exchange_weak(__i1, __i2, __m); }
143 compare_exchange_weak(
bool& __i1,
bool __i2,
144 memory_order __m = memory_order_seq_cst)
volatile noexcept
145 {
return _M_base.compare_exchange_weak(__i1, __i2, __m); }
148 compare_exchange_strong(
bool& __i1,
bool __i2,
memory_order __m1,
150 {
return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); }
153 compare_exchange_strong(
bool& __i1,
bool __i2,
memory_order __m1,
155 {
return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); }
158 compare_exchange_strong(
bool& __i1,
bool __i2,
160 {
return _M_base.compare_exchange_strong(__i1, __i2, __m); }
163 compare_exchange_strong(
bool& __i1,
bool __i2,
164 memory_order __m = memory_order_seq_cst)
volatile noexcept
165 {
return _M_base.compare_exchange_strong(__i1, __i2, __m); }
167#if __cpp_lib_atomic_wait
169 wait(
bool __old,
memory_order __m = memory_order_seq_cst)
const noexcept
170 { _M_base.wait(__old, __m); }
175 notify_one()
noexcept
176 { _M_base.notify_one(); }
179 notify_all()
noexcept
180 { _M_base.notify_all(); }
185#if __cpp_lib_atomic_value_initialization
186# define _GLIBCXX20_INIT(I) = I
188# define _GLIBCXX20_INIT(I)
197 template<
typename _Tp>
200 using value_type = _Tp;
204 static constexpr int _S_min_alignment
205 = (
sizeof(_Tp) & (
sizeof(_Tp) - 1)) ||
sizeof(_Tp) > 16
208 static constexpr int _S_alignment
209 = _S_min_alignment >
alignof(_Tp) ? _S_min_alignment :
alignof(_Tp);
211 alignas(_S_alignment) _Tp _M_i _GLIBCXX20_INIT(_Tp());
213 static_assert(__is_trivially_copyable(_Tp),
214 "std::atomic requires a trivially copyable type");
216 static_assert(
sizeof(_Tp) > 0,
217 "Incomplete or zero-sized types are not supported");
219#if __cplusplus > 201703L
220 static_assert(is_copy_constructible_v<_Tp>);
221 static_assert(is_move_constructible_v<_Tp>);
222 static_assert(is_copy_assignable_v<_Tp>);
223 static_assert(is_move_assignable_v<_Tp>);
228 ~atomic()
noexcept =
default;
229 atomic(
const atomic&) =
delete;
230 atomic& operator=(
const atomic&) =
delete;
231 atomic& operator=(
const atomic&)
volatile =
delete;
233#pragma GCC diagnostic push
234#pragma GCC diagnostic ignored "-Wc++14-extensions"
235 constexpr atomic(_Tp __i) noexcept : _M_i(__i)
237#if __has_builtin(__builtin_clear_padding)
238 if _GLIBCXX17_CONSTEXPR (__atomic_impl::__maybe_has_padding<_Tp>())
239 if (!std::__is_constant_evaluated())
243#pragma GCC diagnostic pop
245 operator _Tp()
const noexcept
248 operator _Tp()
const volatile noexcept
252 operator=(_Tp __i)
noexcept
253 { store(__i);
return __i; }
256 operator=(_Tp __i)
volatile noexcept
257 { store(__i);
return __i; }
260 is_lock_free()
const noexcept
263 return __atomic_is_lock_free(
sizeof(_M_i),
264 reinterpret_cast<void *
>(-_S_alignment));
268 is_lock_free()
const volatile noexcept
271 return __atomic_is_lock_free(
sizeof(_M_i),
272 reinterpret_cast<void *
>(-_S_alignment));
275#if __cplusplus >= 201703L
276 static constexpr bool is_always_lock_free
277 = __atomic_always_lock_free(
sizeof(_M_i), 0);
281 store(_Tp __i,
memory_order __m = memory_order_seq_cst)
noexcept
284 __atomic_impl::__clear_padding(__i),
289 store(_Tp __i,
memory_order __m = memory_order_seq_cst)
volatile noexcept
292 __atomic_impl::__clear_padding(__i),
297 load(
memory_order __m = memory_order_seq_cst)
const noexcept
299 alignas(_Tp)
unsigned char __buf[
sizeof(_Tp)];
300 _Tp* __ptr =
reinterpret_cast<_Tp*
>(__buf);
306 load(
memory_order __m = memory_order_seq_cst)
const volatile noexcept
308 alignas(_Tp)
unsigned char __buf[
sizeof(_Tp)];
309 _Tp* __ptr =
reinterpret_cast<_Tp*
>(__buf);
315 exchange(_Tp __i,
memory_order __m = memory_order_seq_cst)
noexcept
317 alignas(_Tp)
unsigned char __buf[
sizeof(_Tp)];
318 _Tp* __ptr =
reinterpret_cast<_Tp*
>(__buf);
320 __atomic_impl::__clear_padding(__i),
327 memory_order __m = memory_order_seq_cst)
volatile noexcept
329 alignas(_Tp)
unsigned char __buf[
sizeof(_Tp)];
330 _Tp* __ptr =
reinterpret_cast<_Tp*
>(__buf);
332 __atomic_impl::__clear_padding(__i),
338 compare_exchange_weak(_Tp& __e, _Tp __i,
memory_order __s,
341 return __atomic_impl::__compare_exchange(_M_i, __e, __i,
true,
346 compare_exchange_weak(_Tp& __e, _Tp __i,
memory_order __s,
349 return __atomic_impl::__compare_exchange(_M_i, __e, __i,
true,
354 compare_exchange_weak(_Tp& __e, _Tp __i,
356 {
return compare_exchange_weak(__e, __i, __m,
357 __cmpexch_failure_order(__m)); }
360 compare_exchange_weak(_Tp& __e, _Tp __i,
361 memory_order __m = memory_order_seq_cst)
volatile noexcept
362 {
return compare_exchange_weak(__e, __i, __m,
363 __cmpexch_failure_order(__m)); }
366 compare_exchange_strong(_Tp& __e, _Tp __i,
memory_order __s,
369 return __atomic_impl::__compare_exchange(_M_i, __e, __i,
false,
374 compare_exchange_strong(_Tp& __e, _Tp __i,
memory_order __s,
377 return __atomic_impl::__compare_exchange(_M_i, __e, __i,
false,
382 compare_exchange_strong(_Tp& __e, _Tp __i,
384 {
return compare_exchange_strong(__e, __i, __m,
385 __cmpexch_failure_order(__m)); }
388 compare_exchange_strong(_Tp& __e, _Tp __i,
389 memory_order __m = memory_order_seq_cst)
volatile noexcept
390 {
return compare_exchange_strong(__e, __i, __m,
391 __cmpexch_failure_order(__m)); }
393#if __cpp_lib_atomic_wait
395 wait(_Tp __old,
memory_order __m = memory_order_seq_cst)
const noexcept
398 [__m,
this] {
return this->load(__m); });
404 notify_one()
noexcept
408 notify_all()
noexcept
412#undef _GLIBCXX20_INIT
415 template<
typename _Tp>
418 using value_type = _Tp*;
419 using difference_type = ptrdiff_t;
421 typedef _Tp* __pointer_type;
422 typedef __atomic_base<_Tp*> __base_type;
425 atomic()
noexcept =
default;
426 ~atomic()
noexcept =
default;
427 atomic(
const atomic&) =
delete;
428 atomic& operator=(
const atomic&) =
delete;
429 atomic& operator=(
const atomic&)
volatile =
delete;
431 constexpr atomic(__pointer_type __p) noexcept : _M_b(__p) { }
433 operator __pointer_type()
const noexcept
434 {
return __pointer_type(_M_b); }
436 operator __pointer_type()
const volatile noexcept
437 {
return __pointer_type(_M_b); }
440 operator=(__pointer_type __p)
noexcept
441 {
return _M_b.operator=(__p); }
444 operator=(__pointer_type __p)
volatile noexcept
445 {
return _M_b.operator=(__p); }
448 operator++(
int)
noexcept
450#if __cplusplus >= 201703L
457 operator++(
int)
volatile noexcept
459#if __cplusplus >= 201703L
466 operator--(
int)
noexcept
468#if __cplusplus >= 201703L
475 operator--(
int)
volatile noexcept
477#if __cplusplus >= 201703L
484 operator++()
noexcept
486#if __cplusplus >= 201703L
493 operator++()
volatile noexcept
495#if __cplusplus >= 201703L
502 operator--()
noexcept
504#if __cplusplus >= 201703L
511 operator--()
volatile noexcept
513#if __cplusplus >= 201703L
520 operator+=(ptrdiff_t __d)
noexcept
522#if __cplusplus >= 201703L
525 return _M_b.operator+=(__d);
529 operator+=(ptrdiff_t __d)
volatile noexcept
531#if __cplusplus >= 201703L
534 return _M_b.operator+=(__d);
538 operator-=(ptrdiff_t __d)
noexcept
540#if __cplusplus >= 201703L
543 return _M_b.operator-=(__d);
547 operator-=(ptrdiff_t __d)
volatile noexcept
549#if __cplusplus >= 201703L
552 return _M_b.operator-=(__d);
556 is_lock_free()
const noexcept
557 {
return _M_b.is_lock_free(); }
560 is_lock_free()
const volatile noexcept
561 {
return _M_b.is_lock_free(); }
563#if __cplusplus >= 201703L
564 static constexpr bool is_always_lock_free
565 = ATOMIC_POINTER_LOCK_FREE == 2;
569 store(__pointer_type __p,
571 {
return _M_b.store(__p, __m); }
574 store(__pointer_type __p,
575 memory_order __m = memory_order_seq_cst)
volatile noexcept
576 {
return _M_b.store(__p, __m); }
579 load(
memory_order __m = memory_order_seq_cst)
const noexcept
580 {
return _M_b.load(__m); }
583 load(
memory_order __m = memory_order_seq_cst)
const volatile noexcept
584 {
return _M_b.load(__m); }
589 {
return _M_b.exchange(__p, __m); }
593 memory_order __m = memory_order_seq_cst)
volatile noexcept
594 {
return _M_b.exchange(__p, __m); }
597 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
599 {
return _M_b.compare_exchange_weak(__p1, __p2, __m1, __m2); }
602 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
605 {
return _M_b.compare_exchange_weak(__p1, __p2, __m1, __m2); }
608 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
611 return compare_exchange_weak(__p1, __p2, __m,
612 __cmpexch_failure_order(__m));
616 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
617 memory_order __m = memory_order_seq_cst)
volatile noexcept
619 return compare_exchange_weak(__p1, __p2, __m,
620 __cmpexch_failure_order(__m));
624 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
626 {
return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
629 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
632 {
return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
635 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
638 return _M_b.compare_exchange_strong(__p1, __p2, __m,
639 __cmpexch_failure_order(__m));
643 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
644 memory_order __m = memory_order_seq_cst)
volatile noexcept
646 return _M_b.compare_exchange_strong(__p1, __p2, __m,
647 __cmpexch_failure_order(__m));
650#if __cpp_lib_atomic_wait
652 wait(__pointer_type __old,
memory_order __m = memory_order_seq_cst)
const noexcept
653 { _M_b.wait(__old, __m); }
658 notify_one()
noexcept
659 { _M_b.notify_one(); }
662 notify_all()
noexcept
663 { _M_b.notify_all(); }
667 fetch_add(ptrdiff_t __d,
670#if __cplusplus >= 201703L
673 return _M_b.fetch_add(__d, __m);
677 fetch_add(ptrdiff_t __d,
678 memory_order __m = memory_order_seq_cst)
volatile noexcept
680#if __cplusplus >= 201703L
683 return _M_b.fetch_add(__d, __m);
687 fetch_sub(ptrdiff_t __d,
690#if __cplusplus >= 201703L
693 return _M_b.fetch_sub(__d, __m);
697 fetch_sub(ptrdiff_t __d,
698 memory_order __m = memory_order_seq_cst)
volatile noexcept
700#if __cplusplus >= 201703L
703 return _M_b.fetch_sub(__d, __m);
710 struct atomic<char> : __atomic_base<char>
712 typedef char __integral_type;
713 typedef __atomic_base<char> __base_type;
715 atomic()
noexcept =
default;
716 ~atomic()
noexcept =
default;
717 atomic(
const atomic&) =
delete;
718 atomic& operator=(
const atomic&) =
delete;
719 atomic& operator=(
const atomic&)
volatile =
delete;
721 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
723 using __base_type::operator __integral_type;
724 using __base_type::operator=;
726#if __cplusplus >= 201703L
727 static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
733 struct atomic<signed char> : __atomic_base<signed char>
735 typedef signed char __integral_type;
736 typedef __atomic_base<signed char> __base_type;
738 atomic()
noexcept=
default;
739 ~atomic()
noexcept =
default;
740 atomic(
const atomic&) =
delete;
741 atomic& operator=(
const atomic&) =
delete;
742 atomic& operator=(
const atomic&)
volatile =
delete;
744 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
746 using __base_type::operator __integral_type;
747 using __base_type::operator=;
749#if __cplusplus >= 201703L
750 static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
756 struct atomic<unsigned char> : __atomic_base<unsigned char>
758 typedef unsigned char __integral_type;
759 typedef __atomic_base<unsigned char> __base_type;
761 atomic()
noexcept=
default;
762 ~atomic()
noexcept =
default;
763 atomic(
const atomic&) =
delete;
764 atomic& operator=(
const atomic&) =
delete;
765 atomic& operator=(
const atomic&)
volatile =
delete;
767 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
769 using __base_type::operator __integral_type;
770 using __base_type::operator=;
772#if __cplusplus >= 201703L
773 static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
779 struct atomic<short> : __atomic_base<short>
781 typedef short __integral_type;
782 typedef __atomic_base<short> __base_type;
784 atomic()
noexcept =
default;
785 ~atomic()
noexcept =
default;
786 atomic(
const atomic&) =
delete;
787 atomic& operator=(
const atomic&) =
delete;
788 atomic& operator=(
const atomic&)
volatile =
delete;
790 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
792 using __base_type::operator __integral_type;
793 using __base_type::operator=;
795#if __cplusplus >= 201703L
796 static constexpr bool is_always_lock_free = ATOMIC_SHORT_LOCK_FREE == 2;
802 struct atomic<unsigned short> : __atomic_base<unsigned short>
804 typedef unsigned short __integral_type;
805 typedef __atomic_base<unsigned short> __base_type;
807 atomic()
noexcept =
default;
808 ~atomic()
noexcept =
default;
809 atomic(
const atomic&) =
delete;
810 atomic& operator=(
const atomic&) =
delete;
811 atomic& operator=(
const atomic&)
volatile =
delete;
813 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
815 using __base_type::operator __integral_type;
816 using __base_type::operator=;
818#if __cplusplus >= 201703L
819 static constexpr bool is_always_lock_free = ATOMIC_SHORT_LOCK_FREE == 2;
825 struct atomic<int> : __atomic_base<int>
827 typedef int __integral_type;
828 typedef __atomic_base<int> __base_type;
830 atomic()
noexcept =
default;
831 ~atomic()
noexcept =
default;
832 atomic(
const atomic&) =
delete;
833 atomic& operator=(
const atomic&) =
delete;
834 atomic& operator=(
const atomic&)
volatile =
delete;
836 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
838 using __base_type::operator __integral_type;
839 using __base_type::operator=;
841#if __cplusplus >= 201703L
842 static constexpr bool is_always_lock_free = ATOMIC_INT_LOCK_FREE == 2;
848 struct atomic<unsigned int> : __atomic_base<unsigned int>
850 typedef unsigned int __integral_type;
851 typedef __atomic_base<unsigned int> __base_type;
853 atomic()
noexcept =
default;
854 ~atomic()
noexcept =
default;
855 atomic(
const atomic&) =
delete;
856 atomic& operator=(
const atomic&) =
delete;
857 atomic& operator=(
const atomic&)
volatile =
delete;
859 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
861 using __base_type::operator __integral_type;
862 using __base_type::operator=;
864#if __cplusplus >= 201703L
865 static constexpr bool is_always_lock_free = ATOMIC_INT_LOCK_FREE == 2;
871 struct atomic<long> : __atomic_base<long>
873 typedef long __integral_type;
874 typedef __atomic_base<long> __base_type;
876 atomic()
noexcept =
default;
877 ~atomic()
noexcept =
default;
878 atomic(
const atomic&) =
delete;
879 atomic& operator=(
const atomic&) =
delete;
880 atomic& operator=(
const atomic&)
volatile =
delete;
882 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
884 using __base_type::operator __integral_type;
885 using __base_type::operator=;
887#if __cplusplus >= 201703L
888 static constexpr bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2;
894 struct atomic<unsigned long> : __atomic_base<unsigned long>
896 typedef unsigned long __integral_type;
897 typedef __atomic_base<unsigned long> __base_type;
899 atomic()
noexcept =
default;
900 ~atomic()
noexcept =
default;
901 atomic(
const atomic&) =
delete;
902 atomic& operator=(
const atomic&) =
delete;
903 atomic& operator=(
const atomic&)
volatile =
delete;
905 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
907 using __base_type::operator __integral_type;
908 using __base_type::operator=;
910#if __cplusplus >= 201703L
911 static constexpr bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2;
917 struct atomic<long long> : __atomic_base<long long>
919 typedef long long __integral_type;
920 typedef __atomic_base<long long> __base_type;
922 atomic()
noexcept =
default;
923 ~atomic()
noexcept =
default;
924 atomic(
const atomic&) =
delete;
925 atomic& operator=(
const atomic&) =
delete;
926 atomic& operator=(
const atomic&)
volatile =
delete;
928 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
930 using __base_type::operator __integral_type;
931 using __base_type::operator=;
933#if __cplusplus >= 201703L
934 static constexpr bool is_always_lock_free = ATOMIC_LLONG_LOCK_FREE == 2;
940 struct atomic<unsigned long long> : __atomic_base<unsigned long long>
942 typedef unsigned long long __integral_type;
943 typedef __atomic_base<unsigned long long> __base_type;
945 atomic()
noexcept =
default;
946 ~atomic()
noexcept =
default;
947 atomic(
const atomic&) =
delete;
948 atomic& operator=(
const atomic&) =
delete;
949 atomic& operator=(
const atomic&)
volatile =
delete;
951 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
953 using __base_type::operator __integral_type;
954 using __base_type::operator=;
956#if __cplusplus >= 201703L
957 static constexpr bool is_always_lock_free = ATOMIC_LLONG_LOCK_FREE == 2;
963 struct atomic<wchar_t> : __atomic_base<wchar_t>
965 typedef wchar_t __integral_type;
966 typedef __atomic_base<wchar_t> __base_type;
968 atomic()
noexcept =
default;
969 ~atomic()
noexcept =
default;
970 atomic(
const atomic&) =
delete;
971 atomic& operator=(
const atomic&) =
delete;
972 atomic& operator=(
const atomic&)
volatile =
delete;
974 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
976 using __base_type::operator __integral_type;
977 using __base_type::operator=;
979#if __cplusplus >= 201703L
980 static constexpr bool is_always_lock_free = ATOMIC_WCHAR_T_LOCK_FREE == 2;
984#ifdef _GLIBCXX_USE_CHAR8_T
987 struct atomic<char8_t> : __atomic_base<char8_t>
989 typedef char8_t __integral_type;
990 typedef __atomic_base<char8_t> __base_type;
992 atomic() noexcept = default;
993 ~
atomic() noexcept = default;
998 constexpr
atomic(__integral_type __i) noexcept : __base_type(__i) { }
1000 using __base_type::operator __integral_type;
1001 using __base_type::operator=;
1003#if __cplusplus > 201402L
1004 static constexpr bool is_always_lock_free
1005 = ATOMIC_CHAR8_T_LOCK_FREE == 2;
1012 struct atomic<char16_t> : __atomic_base<char16_t>
1014 typedef char16_t __integral_type;
1015 typedef __atomic_base<char16_t> __base_type;
1017 atomic()
noexcept =
default;
1018 ~atomic()
noexcept =
default;
1019 atomic(
const atomic&) =
delete;
1020 atomic& operator=(
const atomic&) =
delete;
1021 atomic& operator=(
const atomic&)
volatile =
delete;
1023 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
1025 using __base_type::operator __integral_type;
1026 using __base_type::operator=;
1028#if __cplusplus >= 201703L
1029 static constexpr bool is_always_lock_free
1030 = ATOMIC_CHAR16_T_LOCK_FREE == 2;
1036 struct atomic<char32_t> : __atomic_base<char32_t>
1038 typedef char32_t __integral_type;
1039 typedef __atomic_base<char32_t> __base_type;
1041 atomic()
noexcept =
default;
1042 ~atomic()
noexcept =
default;
1043 atomic(
const atomic&) =
delete;
1044 atomic& operator=(
const atomic&) =
delete;
1045 atomic& operator=(
const atomic&)
volatile =
delete;
1047 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
1049 using __base_type::operator __integral_type;
1050 using __base_type::operator=;
1052#if __cplusplus >= 201703L
1053 static constexpr bool is_always_lock_free
1054 = ATOMIC_CHAR32_T_LOCK_FREE == 2;
1098#ifdef _GLIBCXX_USE_CHAR8_T
1109#ifdef _GLIBCXX_USE_C99_STDINT_TR1
1201#ifdef _GLIBCXX_USE_C99_STDINT_TR1
1211 atomic_flag_test_and_set_explicit(
atomic_flag* __a,
1213 {
return __a->test_and_set(__m); }
1216 atomic_flag_test_and_set_explicit(
volatile atomic_flag* __a,
1218 {
return __a->test_and_set(__m); }
1220#if __cpp_lib_atomic_flag_test
1223 {
return __a->test(); }
1226 atomic_flag_test(
const volatile atomic_flag* __a)
noexcept
1227 {
return __a->test(); }
1232 {
return __a->test(__m); }
1235 atomic_flag_test_explicit(
const volatile atomic_flag* __a,
1237 {
return __a->test(__m); }
1242 { __a->clear(__m); }
1245 atomic_flag_clear_explicit(
volatile atomic_flag* __a,
1247 { __a->clear(__m); }
1250 atomic_flag_test_and_set(
atomic_flag* __a)
noexcept
1251 {
return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
1254 atomic_flag_test_and_set(
volatile atomic_flag* __a)
noexcept
1255 {
return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
1259 { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
1262 atomic_flag_clear(
volatile atomic_flag* __a)
noexcept
1263 { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
1265#if __cpp_lib_atomic_wait
1267 atomic_flag_wait(
atomic_flag* __a,
bool __old)
noexcept
1268 { __a->wait(__old); }
1271 atomic_flag_wait_explicit(
atomic_flag* __a,
bool __old,
1273 { __a->wait(__old, __m); }
1277 { __a->notify_one(); }
1281 { __a->notify_all(); }
1287 template<
typename _Tp>
1288 using __atomic_val_t = __type_identity_t<_Tp>;
1289 template<
typename _Tp>
1295 template<
typename _ITp>
1298 {
return __a->is_lock_free(); }
1300 template<
typename _ITp>
1302 atomic_is_lock_free(
const volatile atomic<_ITp>* __a)
noexcept
1303 {
return __a->is_lock_free(); }
1305 template<
typename _ITp>
1307 atomic_init(
atomic<_ITp>* __a, __atomic_val_t<_ITp> __i)
noexcept
1308 { __a->store(__i, memory_order_relaxed); }
1310 template<
typename _ITp>
1312 atomic_init(
volatile atomic<_ITp>* __a, __atomic_val_t<_ITp> __i)
noexcept
1313 { __a->store(__i, memory_order_relaxed); }
1315 template<
typename _ITp>
1317 atomic_store_explicit(
atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1319 { __a->store(__i, __m); }
1321 template<
typename _ITp>
1323 atomic_store_explicit(
volatile atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1325 { __a->store(__i, __m); }
1327 template<
typename _ITp>
1330 {
return __a->load(__m); }
1332 template<
typename _ITp>
1336 {
return __a->load(__m); }
1338 template<
typename _ITp>
1340 atomic_exchange_explicit(
atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1342 {
return __a->exchange(__i, __m); }
1344 template<
typename _ITp>
1347 __atomic_val_t<_ITp> __i,
1349 {
return __a->exchange(__i, __m); }
1351 template<
typename _ITp>
1353 atomic_compare_exchange_weak_explicit(
atomic<_ITp>* __a,
1354 __atomic_val_t<_ITp>* __i1,
1355 __atomic_val_t<_ITp> __i2,
1358 {
return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
1360 template<
typename _ITp>
1362 atomic_compare_exchange_weak_explicit(
volatile atomic<_ITp>* __a,
1363 __atomic_val_t<_ITp>* __i1,
1364 __atomic_val_t<_ITp> __i2,
1367 {
return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
1369 template<
typename _ITp>
1371 atomic_compare_exchange_strong_explicit(
atomic<_ITp>* __a,
1372 __atomic_val_t<_ITp>* __i1,
1373 __atomic_val_t<_ITp> __i2,
1376 {
return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
1378 template<
typename _ITp>
1380 atomic_compare_exchange_strong_explicit(
volatile atomic<_ITp>* __a,
1381 __atomic_val_t<_ITp>* __i1,
1382 __atomic_val_t<_ITp> __i2,
1385 {
return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
1388 template<
typename _ITp>
1390 atomic_store(
atomic<_ITp>* __a, __atomic_val_t<_ITp> __i)
noexcept
1391 { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
1393 template<
typename _ITp>
1395 atomic_store(
volatile atomic<_ITp>* __a, __atomic_val_t<_ITp> __i)
noexcept
1396 { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
1398 template<
typename _ITp>
1401 {
return atomic_load_explicit(__a, memory_order_seq_cst); }
1403 template<
typename _ITp>
1406 {
return atomic_load_explicit(__a, memory_order_seq_cst); }
1408 template<
typename _ITp>
1410 atomic_exchange(
atomic<_ITp>* __a, __atomic_val_t<_ITp> __i)
noexcept
1411 {
return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
1413 template<
typename _ITp>
1416 __atomic_val_t<_ITp> __i)
noexcept
1417 {
return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
1419 template<
typename _ITp>
1422 __atomic_val_t<_ITp>* __i1,
1423 __atomic_val_t<_ITp> __i2)
noexcept
1425 return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
1426 memory_order_seq_cst,
1427 memory_order_seq_cst);
1430 template<
typename _ITp>
1432 atomic_compare_exchange_weak(
volatile atomic<_ITp>* __a,
1433 __atomic_val_t<_ITp>* __i1,
1434 __atomic_val_t<_ITp> __i2)
noexcept
1436 return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
1437 memory_order_seq_cst,
1438 memory_order_seq_cst);
1441 template<
typename _ITp>
1444 __atomic_val_t<_ITp>* __i1,
1445 __atomic_val_t<_ITp> __i2)
noexcept
1447 return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
1448 memory_order_seq_cst,
1449 memory_order_seq_cst);
1452 template<
typename _ITp>
1454 atomic_compare_exchange_strong(
volatile atomic<_ITp>* __a,
1455 __atomic_val_t<_ITp>* __i1,
1456 __atomic_val_t<_ITp> __i2)
noexcept
1458 return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
1459 memory_order_seq_cst,
1460 memory_order_seq_cst);
1464#if __cpp_lib_atomic_wait
1465 template<
typename _Tp>
1468 typename std::atomic<_Tp>::value_type __old)
noexcept
1469 { __a->wait(__old); }
1471 template<
typename _Tp>
1474 typename std::atomic<_Tp>::value_type __old,
1476 { __a->wait(__old, __m); }
1478 template<
typename _Tp>
1481 { __a->notify_one(); }
1483 template<
typename _Tp>
1486 { __a->notify_all(); }
1493 template<
typename _ITp>
1496 __atomic_diff_t<_ITp> __i,
1498 {
return __a->fetch_add(__i, __m); }
1500 template<
typename _ITp>
1503 __atomic_diff_t<_ITp> __i,
1505 {
return __a->fetch_add(__i, __m); }
1507 template<
typename _ITp>
1510 __atomic_diff_t<_ITp> __i,
1512 {
return __a->fetch_sub(__i, __m); }
1514 template<
typename _ITp>
1517 __atomic_diff_t<_ITp> __i,
1519 {
return __a->fetch_sub(__i, __m); }
1521 template<
typename _ITp>
1523 atomic_fetch_and_explicit(__atomic_base<_ITp>* __a,
1524 __atomic_val_t<_ITp> __i,
1526 {
return __a->fetch_and(__i, __m); }
1528 template<
typename _ITp>
1530 atomic_fetch_and_explicit(
volatile __atomic_base<_ITp>* __a,
1531 __atomic_val_t<_ITp> __i,
1533 {
return __a->fetch_and(__i, __m); }
1535 template<
typename _ITp>
1537 atomic_fetch_or_explicit(__atomic_base<_ITp>* __a,
1538 __atomic_val_t<_ITp> __i,
1540 {
return __a->fetch_or(__i, __m); }
1542 template<
typename _ITp>
1544 atomic_fetch_or_explicit(
volatile __atomic_base<_ITp>* __a,
1545 __atomic_val_t<_ITp> __i,
1547 {
return __a->fetch_or(__i, __m); }
1549 template<
typename _ITp>
1551 atomic_fetch_xor_explicit(__atomic_base<_ITp>* __a,
1552 __atomic_val_t<_ITp> __i,
1554 {
return __a->fetch_xor(__i, __m); }
1556 template<
typename _ITp>
1558 atomic_fetch_xor_explicit(
volatile __atomic_base<_ITp>* __a,
1559 __atomic_val_t<_ITp> __i,
1561 {
return __a->fetch_xor(__i, __m); }
1563 template<
typename _ITp>
1566 __atomic_diff_t<_ITp> __i)
noexcept
1567 {
return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
1569 template<
typename _ITp>
1572 __atomic_diff_t<_ITp> __i)
noexcept
1573 {
return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
1575 template<
typename _ITp>
1578 __atomic_diff_t<_ITp> __i)
noexcept
1579 {
return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
1581 template<
typename _ITp>
1584 __atomic_diff_t<_ITp> __i)
noexcept
1585 {
return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
1587 template<
typename _ITp>
1589 atomic_fetch_and(__atomic_base<_ITp>* __a,
1590 __atomic_val_t<_ITp> __i)
noexcept
1591 {
return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
1593 template<
typename _ITp>
1595 atomic_fetch_and(
volatile __atomic_base<_ITp>* __a,
1596 __atomic_val_t<_ITp> __i)
noexcept
1597 {
return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
1599 template<
typename _ITp>
1601 atomic_fetch_or(__atomic_base<_ITp>* __a,
1602 __atomic_val_t<_ITp> __i)
noexcept
1603 {
return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
1605 template<
typename _ITp>
1607 atomic_fetch_or(
volatile __atomic_base<_ITp>* __a,
1608 __atomic_val_t<_ITp> __i)
noexcept
1609 {
return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
1611 template<
typename _ITp>
1613 atomic_fetch_xor(__atomic_base<_ITp>* __a,
1614 __atomic_val_t<_ITp> __i)
noexcept
1615 {
return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
1617 template<
typename _ITp>
1619 atomic_fetch_xor(
volatile __atomic_base<_ITp>* __a,
1620 __atomic_val_t<_ITp> __i)
noexcept
1621 {
return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
1623#if __cplusplus > 201703L
1624#define __cpp_lib_atomic_float 201711L
1626 struct atomic<float> : __atomic_float<float>
1628 atomic() noexcept = default;
1631 atomic(
float __fp) noexcept : __atomic_float<
float>(__fp)
1634 atomic& operator=(
const atomic&)
volatile =
delete;
1635 atomic& operator=(
const atomic&) =
delete;
1637 using __atomic_float<
float>::operator=;
1641 struct atomic<double> : __atomic_float<double>
1643 atomic() noexcept = default;
1646 atomic(
double __fp) noexcept : __atomic_float<
double>(__fp)
1649 atomic& operator=(
const atomic&)
volatile =
delete;
1650 atomic& operator=(
const atomic&) =
delete;
1652 using __atomic_float<
double>::operator=;
1656 struct atomic<long double> : __atomic_float<long double>
1658 atomic() noexcept = default;
1661 atomic(
long double __fp) noexcept : __atomic_float<
long double>(__fp)
1664 atomic& operator=(
const atomic&)
volatile =
delete;
1665 atomic& operator=(
const atomic&) =
delete;
1667 using __atomic_float<
long double>::operator=;
1670#ifdef __STDCPP_FLOAT16_T__
1672 struct atomic<_Float16> : __atomic_float<_Float16>
1674 atomic() noexcept = default;
1677 atomic(_Float16 __fp) noexcept : __atomic_float<_Float16>(__fp)
1680 atomic& operator=(
const atomic&)
volatile =
delete;
1681 atomic& operator=(
const atomic&) =
delete;
1683 using __atomic_float<_Float16>::operator=;
1687#ifdef __STDCPP_FLOAT32_T__
1689 struct atomic<_Float32> : __atomic_float<_Float32>
1691 atomic() noexcept = default;
1694 atomic(_Float32 __fp) noexcept : __atomic_float<_Float32>(__fp)
1697 atomic& operator=(
const atomic&)
volatile =
delete;
1698 atomic& operator=(
const atomic&) =
delete;
1700 using __atomic_float<_Float32>::operator=;
1704#ifdef __STDCPP_FLOAT64_T__
1706 struct atomic<_Float64> : __atomic_float<_Float64>
1708 atomic() noexcept = default;
1711 atomic(_Float64 __fp) noexcept : __atomic_float<_Float64>(__fp)
1714 atomic& operator=(
const atomic&)
volatile =
delete;
1715 atomic& operator=(
const atomic&) =
delete;
1717 using __atomic_float<_Float64>::operator=;
1721#ifdef __STDCPP_FLOAT128_T__
1723 struct atomic<_Float128> : __atomic_float<_Float128>
1725 atomic() noexcept = default;
1728 atomic(_Float128 __fp) noexcept : __atomic_float<_Float128>(__fp)
1731 atomic& operator=(
const atomic&)
volatile =
delete;
1732 atomic& operator=(
const atomic&) =
delete;
1734 using __atomic_float<_Float128>::operator=;
1738#ifdef __STDCPP_BFLOAT16_T__
1740 struct atomic<__gnu_cxx::__bfloat16_t> : __atomic_float<__gnu_cxx::__bfloat16_t>
1742 atomic() noexcept = default;
1745 atomic(__gnu_cxx::__bfloat16_t __fp) noexcept : __atomic_float<__gnu_cxx::__bfloat16_t>(__fp)
1748 atomic& operator=(
const atomic&)
volatile =
delete;
1749 atomic& operator=(
const atomic&) =
delete;
1751 using __atomic_float<__gnu_cxx::__bfloat16_t>::operator=;
1755#define __cpp_lib_atomic_ref 201806L
1758 template<
typename _Tp>
1759 struct atomic_ref : __atomic_ref<_Tp>
1762 atomic_ref(_Tp& __t) noexcept : __atomic_ref<_Tp>(__t)
1765 atomic_ref& operator=(
const atomic_ref&) =
delete;
1767 atomic_ref(
const atomic_ref&) =
default;
1769 using __atomic_ref<_Tp>::operator=;
1772#define __cpp_lib_atomic_lock_free_type_aliases 201907L
1773#ifdef _GLIBCXX_HAVE_PLATFORM_WAIT
1774 using atomic_signed_lock_free
1776 using atomic_unsigned_lock_free
1778#elif ATOMIC_INT_LOCK_FREE || !(ATOMIC_LONG_LOCK_FREE || ATOMIC_CHAR_LOCK_FREE)
1781#elif ATOMIC_LONG_LOCK_FREE
1784#elif ATOMIC_CHAR_LOCK_FREE
1793_GLIBCXX_END_NAMESPACE_VERSION
constexpr _Tp * addressof(_Tp &__r) noexcept
Returns the actual address of the object or function referenced by r, even in the presence of an over...
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
atomic< unsigned long > atomic_ulong
atomic_ulong
atomic< intmax_t > atomic_intmax_t
atomic_intmax_t
atomic< uintptr_t > atomic_uintptr_t
atomic_uintptr_t
atomic< signed char > atomic_schar
atomic_schar
atomic< int_least8_t > atomic_int_least8_t
atomic_int_least8_t
atomic< unsigned long long > atomic_ullong
atomic_ullong
atomic< uint_fast8_t > atomic_uint_fast8_t
atomic_uint_fast8_t
atomic< intptr_t > atomic_intptr_t
atomic_intptr_t
atomic< int16_t > atomic_int16_t
atomic_int16_t
atomic< size_t > atomic_size_t
atomic_size_t
atomic< long > atomic_long
atomic_long
atomic< uint_least8_t > atomic_uint_least8_t
atomic_uint_least8_t
atomic< short > atomic_short
atomic_short
atomic< uint_least16_t > atomic_uint_least16_t
atomic_uint_least16_t
atomic< uint16_t > atomic_uint16_t
atomic_uint16_t
atomic< uint64_t > atomic_uint64_t
atomic_uint64_t
atomic< int_least32_t > atomic_int_least32_t
atomic_int_least32_t
atomic< uint8_t > atomic_uint8_t
atomic_uint8_t
#define ATOMIC_BOOL_LOCK_FREE
atomic< wchar_t > atomic_wchar_t
atomic_wchar_t
atomic< unsigned int > atomic_uint
atomic_uint
atomic< uint_least32_t > atomic_uint_least32_t
atomic_uint_least32_t
atomic< uint_fast64_t > atomic_uint_fast64_t
atomic_uint_fast64_t
atomic< int_fast32_t > atomic_int_fast32_t
atomic_int_fast32_t
atomic< char > atomic_char
atomic_char
atomic< int > atomic_int
atomic_int
atomic< uint_least64_t > atomic_uint_least64_t
atomic_uint_least64_t
atomic< int64_t > atomic_int64_t
atomic_int64_t
atomic< uintmax_t > atomic_uintmax_t
atomic_uintmax_t
atomic< int_fast16_t > atomic_int_fast16_t
atomic_int_fast16_t
atomic< int32_t > atomic_int32_t
atomic_int32_t
atomic< uint_fast16_t > atomic_uint_fast16_t
atomic_uint_fast16_t
atomic< int8_t > atomic_int8_t
atomic_int8_t
atomic< long long > atomic_llong
atomic_llong
atomic< char16_t > atomic_char16_t
atomic_char16_t
atomic< int_fast64_t > atomic_int_fast64_t
atomic_int_fast64_t
atomic< ptrdiff_t > atomic_ptrdiff_t
atomic_ptrdiff_t
atomic< char32_t > atomic_char32_t
atomic_char32_t
atomic< int_least16_t > atomic_int_least16_t
atomic_int_least16_t
atomic< unsigned char > atomic_uchar
atomic_uchar
atomic< int_fast8_t > atomic_int_fast8_t
atomic_int_fast8_t
memory_order
Enumeration for memory_order.
atomic< unsigned short > atomic_ushort
atomic_ushort
atomic< int_least64_t > atomic_int_least64_t
atomic_int_least64_t
atomic< bool > atomic_bool
atomic_bool
atomic< uint_fast32_t > atomic_uint_fast32_t
atomic_uint_fast32_t
atomic< uint32_t > atomic_uint32_t
atomic_uint32_t
ISO C++ entities toplevel namespace is std.
constexpr _Tp exchange(_Tp &__obj, _Up &&__new_val) noexcept(__and_< is_nothrow_move_constructible< _Tp >, is_nothrow_assignable< _Tp &, _Up > >::value)
Assign __new_val to __obj and return its previous value.
Generic atomic type, primary class template.