32 #ifndef _GLIBCXX_ATOMIC 33 #define _GLIBCXX_ATOMIC 1 35 #ifdef _GLIBCXX_SYSHDR 36 #pragma GCC system_header 39 #if __cplusplus < 201103L 43 #define __glibcxx_want_atomic_is_always_lock_free 44 #define __glibcxx_want_atomic_flag_test 45 #define __glibcxx_want_atomic_float 46 #define __glibcxx_want_atomic_min_max 47 #define __glibcxx_want_atomic_ref 48 #define __glibcxx_want_atomic_lock_free_type_aliases 49 #define __glibcxx_want_atomic_value_initialization 50 #define __glibcxx_want_atomic_wait 57 namespace std _GLIBCXX_VISIBILITY(default)
59 _GLIBCXX_BEGIN_NAMESPACE_VERSION
66 template<
typename _Tp>
74 using value_type = bool;
77 __atomic_base<bool> _M_base;
80 atomic() noexcept =
default;
81 ~
atomic() noexcept =
default;
86 constexpr
atomic(
bool __i) noexcept : _M_base(__i) { }
89 operator=(
bool __i) noexcept
90 {
return _M_base.operator=(__i); }
93 operator=(
bool __i)
volatile noexcept
94 {
return _M_base.operator=(__i); }
96 operator bool()
const noexcept
97 {
return _M_base.load(); }
99 operator bool()
const volatile noexcept
100 {
return _M_base.load(); }
103 is_lock_free()
const noexcept {
return _M_base.is_lock_free(); }
106 is_lock_free()
const volatile noexcept {
return _M_base.is_lock_free(); }
108 #ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17 113 store(
bool __i,
memory_order __m = memory_order_seq_cst) noexcept
114 { _M_base.store(__i, __m); }
117 store(
bool __i,
memory_order __m = memory_order_seq_cst)
volatile noexcept
118 { _M_base.store(__i, __m); }
121 load(
memory_order __m = memory_order_seq_cst)
const noexcept
122 {
return _M_base.load(__m); }
125 load(
memory_order __m = memory_order_seq_cst)
const volatile noexcept
126 {
return _M_base.load(__m); }
129 exchange(
bool __i,
memory_order __m = memory_order_seq_cst) noexcept
130 {
return _M_base.exchange(__i, __m); }
134 memory_order __m = memory_order_seq_cst)
volatile noexcept
135 {
return _M_base.exchange(__i, __m); }
138 compare_exchange_weak(
bool& __i1,
bool __i2,
memory_order __m1,
140 {
return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); }
143 compare_exchange_weak(
bool& __i1,
bool __i2,
memory_order __m1,
145 {
return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); }
148 compare_exchange_weak(
bool& __i1,
bool __i2,
150 {
return _M_base.compare_exchange_weak(__i1, __i2, __m); }
153 compare_exchange_weak(
bool& __i1,
bool __i2,
154 memory_order __m = memory_order_seq_cst)
volatile noexcept
155 {
return _M_base.compare_exchange_weak(__i1, __i2, __m); }
158 compare_exchange_strong(
bool& __i1,
bool __i2,
memory_order __m1,
160 {
return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); }
163 compare_exchange_strong(
bool& __i1,
bool __i2,
memory_order __m1,
165 {
return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); }
168 compare_exchange_strong(
bool& __i1,
bool __i2,
170 {
return _M_base.compare_exchange_strong(__i1, __i2, __m); }
173 compare_exchange_strong(
bool& __i1,
bool __i2,
174 memory_order __m = memory_order_seq_cst)
volatile noexcept
175 {
return _M_base.compare_exchange_strong(__i1, __i2, __m); }
177 #if __cpp_lib_atomic_wait 179 wait(
bool __old,
memory_order __m = memory_order_seq_cst)
const noexcept
180 { _M_base.wait(__old, __m); }
185 notify_one() noexcept
186 { _M_base.notify_one(); }
189 notify_all() noexcept
190 { _M_base.notify_all(); }
191 #endif // __cpp_lib_atomic_wait 199 template<
typename _Tp>
202 using value_type = _Tp;
206 static constexpr
int _S_min_alignment
207 = (
sizeof(_Tp) & (
sizeof(_Tp) - 1)) ||
sizeof(_Tp) > 16
210 static constexpr
int _S_alignment
211 = _S_min_alignment >
alignof(_Tp) ? _S_min_alignment :
alignof(_Tp);
213 alignas(_S_alignment) _Tp _M_i;
215 static_assert(__is_trivially_copyable(_Tp),
216 "std::atomic requires a trivially copyable type");
218 static_assert(
sizeof(_Tp) > 0,
219 "Incomplete or zero-sized types are not supported");
223 static_assert(
is_same<_Tp,
typename remove_cv<_Tp>::type>::value,
224 "template argument for std::atomic must not be const or volatile");
226 #if __cplusplus > 201703L 227 static_assert(is_copy_constructible_v<_Tp>);
228 static_assert(is_move_constructible_v<_Tp>);
229 static_assert(is_copy_assignable_v<_Tp>);
230 static_assert(is_move_assignable_v<_Tp>);
234 #if __cpp_lib_atomic_value_initialization 237 constexpr
atomic() noexcept(is_nothrow_default_constructible_v<_Tp>)
238 requires is_default_constructible_v<_Tp>
245 ~
atomic() noexcept =
default;
250 #pragma GCC diagnostic push 251 #pragma GCC diagnostic ignored "-Wc++14-extensions" // constexpr ctor body 252 constexpr
atomic(_Tp __i) noexcept : _M_i(__i)
254 #if __has_builtin(__builtin_clear_padding) 255 if _GLIBCXX17_CONSTEXPR (__atomic_impl::__maybe_has_padding<_Tp>())
256 if (!std::__is_constant_evaluated())
260 #pragma GCC diagnostic pop 262 operator _Tp()
const noexcept
265 operator _Tp()
const volatile noexcept
269 operator=(_Tp __i) noexcept
270 { store(__i);
return __i; }
273 operator=(_Tp __i)
volatile noexcept
274 { store(__i);
return __i; }
277 is_lock_free()
const noexcept
280 return __atomic_is_lock_free(
sizeof(_M_i),
281 reinterpret_cast<void *>(-_S_alignment));
285 is_lock_free()
const volatile noexcept
288 return __atomic_is_lock_free(
sizeof(_M_i),
289 reinterpret_cast<void *>(-_S_alignment));
292 #ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17 293 static constexpr
bool is_always_lock_free
294 = __atomic_always_lock_free(
sizeof(_M_i), 0);
298 store(_Tp __i,
memory_order __m = memory_order_seq_cst) noexcept
301 __atomic_impl::__clear_padding(__i),
306 store(_Tp __i,
memory_order __m = memory_order_seq_cst)
volatile noexcept
309 __atomic_impl::__clear_padding(__i),
314 load(
memory_order __m = memory_order_seq_cst)
const noexcept
316 alignas(_Tp)
unsigned char __buf[
sizeof(_Tp)];
317 _Tp* __ptr =
reinterpret_cast<_Tp*
>(__buf);
323 load(
memory_order __m = memory_order_seq_cst)
const volatile noexcept
325 alignas(_Tp)
unsigned char __buf[
sizeof(_Tp)];
326 _Tp* __ptr =
reinterpret_cast<_Tp*
>(__buf);
332 exchange(_Tp __i,
memory_order __m = memory_order_seq_cst) noexcept
334 alignas(_Tp)
unsigned char __buf[
sizeof(_Tp)];
335 _Tp* __ptr =
reinterpret_cast<_Tp*
>(__buf);
337 __atomic_impl::__clear_padding(__i),
344 memory_order __m = memory_order_seq_cst)
volatile noexcept
346 alignas(_Tp)
unsigned char __buf[
sizeof(_Tp)];
347 _Tp* __ptr =
reinterpret_cast<_Tp*
>(__buf);
349 __atomic_impl::__clear_padding(__i),
355 compare_exchange_weak(_Tp& __e, _Tp __i,
memory_order __s,
358 return __atomic_impl::__compare_exchange(_M_i, __e, __i,
true,
363 compare_exchange_weak(_Tp& __e, _Tp __i,
memory_order __s,
366 return __atomic_impl::__compare_exchange(_M_i, __e, __i,
true,
371 compare_exchange_weak(_Tp& __e, _Tp __i,
373 {
return compare_exchange_weak(__e, __i, __m,
374 __cmpexch_failure_order(__m)); }
377 compare_exchange_weak(_Tp& __e, _Tp __i,
378 memory_order __m = memory_order_seq_cst)
volatile noexcept
379 {
return compare_exchange_weak(__e, __i, __m,
380 __cmpexch_failure_order(__m)); }
383 compare_exchange_strong(_Tp& __e, _Tp __i,
memory_order __s,
386 return __atomic_impl::__compare_exchange(_M_i, __e, __i,
false,
391 compare_exchange_strong(_Tp& __e, _Tp __i,
memory_order __s,
394 return __atomic_impl::__compare_exchange(_M_i, __e, __i,
false,
399 compare_exchange_strong(_Tp& __e, _Tp __i,
401 {
return compare_exchange_strong(__e, __i, __m,
402 __cmpexch_failure_order(__m)); }
405 compare_exchange_strong(_Tp& __e, _Tp __i,
406 memory_order __m = memory_order_seq_cst)
volatile noexcept
407 {
return compare_exchange_strong(__e, __i, __m,
408 __cmpexch_failure_order(__m)); }
410 #if __cpp_lib_atomic_wait // C++ >= 20 412 wait(_Tp __old,
memory_order __m = memory_order_seq_cst)
const noexcept
415 [__m,
this] {
return this->load(__m); });
421 notify_one() noexcept
425 notify_all() noexcept
427 #endif // __cpp_lib_atomic_wait 431 template<
typename _Tp>
434 using value_type = _Tp*;
435 using difference_type = ptrdiff_t;
437 typedef _Tp* __pointer_type;
438 typedef __atomic_base<_Tp*> __base_type;
441 atomic() noexcept =
default;
442 ~
atomic() noexcept =
default;
447 constexpr
atomic(__pointer_type __p) noexcept : _M_b(__p) { }
449 operator __pointer_type()
const noexcept
450 {
return __pointer_type(_M_b); }
452 operator __pointer_type()
const volatile noexcept
453 {
return __pointer_type(_M_b); }
456 operator=(__pointer_type __p) noexcept
457 {
return _M_b.operator=(__p); }
460 operator=(__pointer_type __p)
volatile noexcept
461 {
return _M_b.operator=(__p); }
464 operator++(
int) noexcept
466 #if __cplusplus >= 201703L 467 static_assert( is_object_v<_Tp>,
"pointer to object type" );
473 operator++(
int)
volatile noexcept
475 #if __cplusplus >= 201703L 476 static_assert( is_object_v<_Tp>,
"pointer to object type" );
482 operator--(
int) noexcept
484 #if __cplusplus >= 201703L 485 static_assert( is_object_v<_Tp>,
"pointer to object type" );
491 operator--(
int)
volatile noexcept
493 #if __cplusplus >= 201703L 494 static_assert( is_object_v<_Tp>,
"pointer to object type" );
500 operator++() noexcept
502 #if __cplusplus >= 201703L 503 static_assert( is_object_v<_Tp>,
"pointer to object type" );
509 operator++()
volatile noexcept
511 #if __cplusplus >= 201703L 512 static_assert( is_object_v<_Tp>,
"pointer to object type" );
518 operator--() noexcept
520 #if __cplusplus >= 201703L 521 static_assert( is_object_v<_Tp>,
"pointer to object type" );
527 operator--()
volatile noexcept
529 #if __cplusplus >= 201703L 530 static_assert( is_object_v<_Tp>,
"pointer to object type" );
536 operator+=(ptrdiff_t __d) noexcept
538 #if __cplusplus >= 201703L 539 static_assert( is_object_v<_Tp>,
"pointer to object type" );
541 return _M_b.operator+=(__d);
545 operator+=(ptrdiff_t __d)
volatile noexcept
547 #if __cplusplus >= 201703L 548 static_assert( is_object_v<_Tp>,
"pointer to object type" );
550 return _M_b.operator+=(__d);
554 operator-=(ptrdiff_t __d) noexcept
556 #if __cplusplus >= 201703L 557 static_assert( is_object_v<_Tp>,
"pointer to object type" );
559 return _M_b.operator-=(__d);
563 operator-=(ptrdiff_t __d)
volatile noexcept
565 #if __cplusplus >= 201703L 566 static_assert( is_object_v<_Tp>,
"pointer to object type" );
568 return _M_b.operator-=(__d);
572 is_lock_free()
const noexcept
573 {
return _M_b.is_lock_free(); }
576 is_lock_free()
const volatile noexcept
577 {
return _M_b.is_lock_free(); }
579 #ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17 580 static constexpr
bool is_always_lock_free
581 = ATOMIC_POINTER_LOCK_FREE == 2;
585 store(__pointer_type __p,
587 {
return _M_b.store(__p, __m); }
590 store(__pointer_type __p,
591 memory_order __m = memory_order_seq_cst)
volatile noexcept
592 {
return _M_b.store(__p, __m); }
595 load(
memory_order __m = memory_order_seq_cst)
const noexcept
596 {
return _M_b.load(__m); }
599 load(
memory_order __m = memory_order_seq_cst)
const volatile noexcept
600 {
return _M_b.load(__m); }
603 exchange(__pointer_type __p,
605 {
return _M_b.exchange(__p, __m); }
608 exchange(__pointer_type __p,
609 memory_order __m = memory_order_seq_cst)
volatile noexcept
610 {
return _M_b.exchange(__p, __m); }
613 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
615 {
return _M_b.compare_exchange_weak(__p1, __p2, __m1, __m2); }
618 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
621 {
return _M_b.compare_exchange_weak(__p1, __p2, __m1, __m2); }
624 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
627 return compare_exchange_weak(__p1, __p2, __m,
628 __cmpexch_failure_order(__m));
632 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
633 memory_order __m = memory_order_seq_cst)
volatile noexcept
635 return compare_exchange_weak(__p1, __p2, __m,
636 __cmpexch_failure_order(__m));
640 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
642 {
return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
645 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
648 {
return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
651 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
654 return _M_b.compare_exchange_strong(__p1, __p2, __m,
655 __cmpexch_failure_order(__m));
659 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
660 memory_order __m = memory_order_seq_cst)
volatile noexcept
662 return _M_b.compare_exchange_strong(__p1, __p2, __m,
663 __cmpexch_failure_order(__m));
666 #if __cpp_lib_atomic_wait 668 wait(__pointer_type __old,
670 { _M_b.wait(__old, __m); }
675 notify_one() noexcept
676 { _M_b.notify_one(); }
679 notify_all() noexcept
680 { _M_b.notify_all(); }
681 #endif // __cpp_lib_atomic_wait 684 fetch_add(ptrdiff_t __d,
687 #if __cplusplus >= 201703L 688 static_assert( is_object_v<_Tp>,
"pointer to object type" );
690 return _M_b.fetch_add(__d, __m);
694 fetch_add(ptrdiff_t __d,
695 memory_order __m = memory_order_seq_cst)
volatile noexcept
697 #if __cplusplus >= 201703L 698 static_assert( is_object_v<_Tp>,
"pointer to object type" );
700 return _M_b.fetch_add(__d, __m);
704 fetch_sub(ptrdiff_t __d,
707 #if __cplusplus >= 201703L 708 static_assert( is_object_v<_Tp>,
"pointer to object type" );
710 return _M_b.fetch_sub(__d, __m);
714 fetch_sub(ptrdiff_t __d,
715 memory_order __m = memory_order_seq_cst)
volatile noexcept
717 #if __cplusplus >= 201703L 718 static_assert( is_object_v<_Tp>,
"pointer to object type" );
720 return _M_b.fetch_sub(__d, __m);
723 #if __glibcxx_atomic_min_max 725 fetch_min(__pointer_type __p,
727 {
return _M_b.fetch_min(__p, __m); }
730 fetch_min(__pointer_type __p,
731 memory_order __m = memory_order_seq_cst)
volatile noexcept
732 {
return _M_b.fetch_min(__p, __m); }
735 fetch_max(__pointer_type __p,
737 {
return _M_b.fetch_max(__p, __m); }
740 fetch_max(__pointer_type __p,
741 memory_order __m = memory_order_seq_cst)
volatile noexcept
742 {
return _M_b.fetch_max(__p, __m); }
749 struct atomic<char> : __atomic_base<char>
751 typedef char __integral_type;
752 typedef __atomic_base<char> __base_type;
754 atomic() noexcept =
default;
755 ~
atomic() noexcept =
default;
760 constexpr
atomic(__integral_type __i) noexcept : __base_type(__i) { }
762 using __base_type::operator __integral_type;
763 using __base_type::operator=;
765 #ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17 766 static constexpr
bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
772 struct atomic<signed char> : __atomic_base<signed char>
774 typedef signed char __integral_type;
775 typedef __atomic_base<signed char> __base_type;
777 atomic() noexcept=
default;
778 ~
atomic() noexcept =
default;
783 constexpr
atomic(__integral_type __i) noexcept : __base_type(__i) { }
785 using __base_type::operator __integral_type;
786 using __base_type::operator=;
788 #ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17 789 static constexpr
bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
795 struct atomic<unsigned char> : __atomic_base<unsigned char>
797 typedef unsigned char __integral_type;
798 typedef __atomic_base<unsigned char> __base_type;
800 atomic() noexcept=
default;
801 ~
atomic() noexcept =
default;
806 constexpr
atomic(__integral_type __i) noexcept : __base_type(__i) { }
808 using __base_type::operator __integral_type;
809 using __base_type::operator=;
811 #ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17 812 static constexpr
bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
818 struct atomic<short> : __atomic_base<short>
820 typedef short __integral_type;
821 typedef __atomic_base<short> __base_type;
823 atomic() noexcept =
default;
824 ~
atomic() noexcept =
default;
829 constexpr
atomic(__integral_type __i) noexcept : __base_type(__i) { }
831 using __base_type::operator __integral_type;
832 using __base_type::operator=;
834 #ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17 835 static constexpr
bool is_always_lock_free = ATOMIC_SHORT_LOCK_FREE == 2;
841 struct atomic<unsigned short> : __atomic_base<unsigned short>
843 typedef unsigned short __integral_type;
844 typedef __atomic_base<unsigned short> __base_type;
846 atomic() noexcept =
default;
847 ~
atomic() noexcept =
default;
852 constexpr
atomic(__integral_type __i) noexcept : __base_type(__i) { }
854 using __base_type::operator __integral_type;
855 using __base_type::operator=;
857 #ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17 858 static constexpr
bool is_always_lock_free = ATOMIC_SHORT_LOCK_FREE == 2;
866 typedef int __integral_type;
867 typedef __atomic_base<int> __base_type;
869 atomic() noexcept =
default;
870 ~
atomic() noexcept =
default;
875 constexpr
atomic(__integral_type __i) noexcept : __base_type(__i) { }
877 using __base_type::operator __integral_type;
878 using __base_type::operator=;
880 #ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17 881 static constexpr
bool is_always_lock_free = ATOMIC_INT_LOCK_FREE == 2;
887 struct atomic<unsigned int> : __atomic_base<unsigned int>
889 typedef unsigned int __integral_type;
890 typedef __atomic_base<unsigned int> __base_type;
892 atomic() noexcept =
default;
893 ~
atomic() noexcept =
default;
898 constexpr
atomic(__integral_type __i) noexcept : __base_type(__i) { }
900 using __base_type::operator __integral_type;
901 using __base_type::operator=;
903 #ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17 904 static constexpr
bool is_always_lock_free = ATOMIC_INT_LOCK_FREE == 2;
910 struct atomic<long> : __atomic_base<long>
912 typedef long __integral_type;
913 typedef __atomic_base<long> __base_type;
915 atomic() noexcept =
default;
916 ~
atomic() noexcept =
default;
921 constexpr
atomic(__integral_type __i) noexcept : __base_type(__i) { }
923 using __base_type::operator __integral_type;
924 using __base_type::operator=;
926 #ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17 927 static constexpr
bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2;
933 struct atomic<unsigned long> : __atomic_base<unsigned long>
935 typedef unsigned long __integral_type;
936 typedef __atomic_base<unsigned long> __base_type;
938 atomic() noexcept =
default;
939 ~
atomic() noexcept =
default;
944 constexpr
atomic(__integral_type __i) noexcept : __base_type(__i) { }
946 using __base_type::operator __integral_type;
947 using __base_type::operator=;
949 #ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17 950 static constexpr
bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2;
956 struct atomic<long long> : __atomic_base<long long>
958 typedef long long __integral_type;
959 typedef __atomic_base<long long> __base_type;
961 atomic() noexcept =
default;
962 ~
atomic() noexcept =
default;
967 constexpr
atomic(__integral_type __i) noexcept : __base_type(__i) { }
969 using __base_type::operator __integral_type;
970 using __base_type::operator=;
972 #ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17 973 static constexpr
bool is_always_lock_free = ATOMIC_LLONG_LOCK_FREE == 2;
979 struct atomic<unsigned long long> : __atomic_base<unsigned long long>
981 typedef unsigned long long __integral_type;
982 typedef __atomic_base<unsigned long long> __base_type;
984 atomic() noexcept =
default;
985 ~
atomic() noexcept =
default;
990 constexpr
atomic(__integral_type __i) noexcept : __base_type(__i) { }
992 using __base_type::operator __integral_type;
993 using __base_type::operator=;
995 #ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17 996 static constexpr
bool is_always_lock_free = ATOMIC_LLONG_LOCK_FREE == 2;
1002 struct atomic<wchar_t> : __atomic_base<wchar_t>
1004 typedef wchar_t __integral_type;
1005 typedef __atomic_base<wchar_t> __base_type;
1007 atomic() noexcept =
default;
1008 ~
atomic() noexcept =
default;
1013 constexpr
atomic(__integral_type __i) noexcept : __base_type(__i) { }
1015 using __base_type::operator __integral_type;
1016 using __base_type::operator=;
1018 #ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17 1019 static constexpr
bool is_always_lock_free = ATOMIC_WCHAR_T_LOCK_FREE == 2;
1023 #ifdef _GLIBCXX_USE_CHAR8_T 1026 struct atomic<char8_t> : __atomic_base<char8_t>
1028 typedef char8_t __integral_type;
1029 typedef __atomic_base<char8_t> __base_type;
1031 atomic() noexcept =
default;
1032 ~
atomic() noexcept =
default;
1037 constexpr
atomic(__integral_type __i) noexcept : __base_type(__i) { }
1039 using __base_type::operator __integral_type;
1040 using __base_type::operator=;
1042 #ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17 1043 static constexpr
bool is_always_lock_free
1044 = ATOMIC_CHAR8_T_LOCK_FREE == 2;
1051 struct atomic<char16_t> : __atomic_base<char16_t>
1053 typedef char16_t __integral_type;
1054 typedef __atomic_base<char16_t> __base_type;
1056 atomic() noexcept =
default;
1057 ~
atomic() noexcept =
default;
1062 constexpr
atomic(__integral_type __i) noexcept : __base_type(__i) { }
1064 using __base_type::operator __integral_type;
1065 using __base_type::operator=;
1067 #ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17 1068 static constexpr
bool is_always_lock_free
1069 = ATOMIC_CHAR16_T_LOCK_FREE == 2;
1075 struct atomic<char32_t> : __atomic_base<char32_t>
1077 typedef char32_t __integral_type;
1078 typedef __atomic_base<char32_t> __base_type;
1080 atomic() noexcept =
default;
1081 ~
atomic() noexcept =
default;
1086 constexpr
atomic(__integral_type __i) noexcept : __base_type(__i) { }
1088 using __base_type::operator __integral_type;
1089 using __base_type::operator=;
1091 #ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17 1092 static constexpr
bool is_always_lock_free
1093 = ATOMIC_CHAR32_T_LOCK_FREE == 2;
1137 #ifdef _GLIBCXX_USE_CHAR8_T 1148 #ifdef _GLIBCXX_USE_C99_STDINT 1247 atomic_flag_test_and_set_explicit(
atomic_flag* __a,
1249 {
return __a->test_and_set(__m); }
1252 atomic_flag_test_and_set_explicit(
volatile atomic_flag* __a,
1254 {
return __a->test_and_set(__m); }
1256 #if __cpp_lib_atomic_flag_test 1259 {
return __a->test(); }
1262 atomic_flag_test(
const volatile atomic_flag* __a) noexcept
1263 {
return __a->test(); }
1268 {
return __a->test(__m); }
1271 atomic_flag_test_explicit(
const volatile atomic_flag* __a,
1273 {
return __a->test(__m); }
1278 { __a->clear(__m); }
1281 atomic_flag_clear_explicit(
volatile atomic_flag* __a,
1283 { __a->clear(__m); }
1286 atomic_flag_test_and_set(
atomic_flag* __a) noexcept
1287 {
return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
1290 atomic_flag_test_and_set(
volatile atomic_flag* __a) noexcept
1291 {
return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
1295 { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
1298 atomic_flag_clear(
volatile atomic_flag* __a) noexcept
1299 { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
1301 #if __cpp_lib_atomic_wait 1303 atomic_flag_wait(
atomic_flag* __a,
bool __old) noexcept
1304 { __a->wait(__old); }
1307 atomic_flag_wait_explicit(
atomic_flag* __a,
bool __old,
1309 { __a->wait(__old, __m); }
1313 { __a->notify_one(); }
1317 { __a->notify_all(); }
1318 #endif // __cpp_lib_atomic_wait 1323 template<
typename _Tp>
1324 using __atomic_val_t = __type_identity_t<_Tp>;
1325 template<
typename _Tp>
1331 template<
typename _ITp>
1334 {
return __a->is_lock_free(); }
1336 template<
typename _ITp>
1338 atomic_is_lock_free(
const volatile atomic<_ITp>* __a) noexcept
1339 {
return __a->is_lock_free(); }
1341 template<
typename _ITp>
1343 atomic_init(
atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1344 { __a->store(__i, memory_order_relaxed); }
1346 template<
typename _ITp>
1348 atomic_init(
volatile atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1349 { __a->store(__i, memory_order_relaxed); }
1351 template<
typename _ITp>
1353 atomic_store_explicit(
atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1355 { __a->store(__i, __m); }
1357 template<
typename _ITp>
1359 atomic_store_explicit(
volatile atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1361 { __a->store(__i, __m); }
1363 template<
typename _ITp>
1366 {
return __a->load(__m); }
1368 template<
typename _ITp>
1372 {
return __a->load(__m); }
1374 template<
typename _ITp>
1376 atomic_exchange_explicit(
atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1378 {
return __a->exchange(__i, __m); }
1380 template<
typename _ITp>
1383 __atomic_val_t<_ITp> __i,
1385 {
return __a->exchange(__i, __m); }
1387 template<
typename _ITp>
1389 atomic_compare_exchange_weak_explicit(
atomic<_ITp>* __a,
1390 __atomic_val_t<_ITp>* __i1,
1391 __atomic_val_t<_ITp> __i2,
1394 {
return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
1396 template<
typename _ITp>
1398 atomic_compare_exchange_weak_explicit(
volatile atomic<_ITp>* __a,
1399 __atomic_val_t<_ITp>* __i1,
1400 __atomic_val_t<_ITp> __i2,
1403 {
return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
1405 template<
typename _ITp>
1407 atomic_compare_exchange_strong_explicit(
atomic<_ITp>* __a,
1408 __atomic_val_t<_ITp>* __i1,
1409 __atomic_val_t<_ITp> __i2,
1412 {
return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
1414 template<
typename _ITp>
1416 atomic_compare_exchange_strong_explicit(
volatile atomic<_ITp>* __a,
1417 __atomic_val_t<_ITp>* __i1,
1418 __atomic_val_t<_ITp> __i2,
1421 {
return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
1424 template<
typename _ITp>
1426 atomic_store(
atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1427 { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
1429 template<
typename _ITp>
1431 atomic_store(
volatile atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1432 { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
1434 template<
typename _ITp>
1437 {
return atomic_load_explicit(__a, memory_order_seq_cst); }
1439 template<
typename _ITp>
1442 {
return atomic_load_explicit(__a, memory_order_seq_cst); }
1444 template<
typename _ITp>
1446 atomic_exchange(
atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1447 {
return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
1449 template<
typename _ITp>
1452 __atomic_val_t<_ITp> __i) noexcept
1453 {
return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
1455 template<
typename _ITp>
1458 __atomic_val_t<_ITp>* __i1,
1459 __atomic_val_t<_ITp> __i2) noexcept
1461 return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
1462 memory_order_seq_cst,
1463 memory_order_seq_cst);
1466 template<
typename _ITp>
1468 atomic_compare_exchange_weak(
volatile atomic<_ITp>* __a,
1469 __atomic_val_t<_ITp>* __i1,
1470 __atomic_val_t<_ITp> __i2) noexcept
1472 return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
1473 memory_order_seq_cst,
1474 memory_order_seq_cst);
1477 template<
typename _ITp>
1480 __atomic_val_t<_ITp>* __i1,
1481 __atomic_val_t<_ITp> __i2) noexcept
1483 return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
1484 memory_order_seq_cst,
1485 memory_order_seq_cst);
1488 template<
typename _ITp>
1490 atomic_compare_exchange_strong(
volatile atomic<_ITp>* __a,
1491 __atomic_val_t<_ITp>* __i1,
1492 __atomic_val_t<_ITp> __i2) noexcept
1494 return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
1495 memory_order_seq_cst,
1496 memory_order_seq_cst);
1500 #if __cpp_lib_atomic_wait 1501 template<
typename _Tp>
1504 typename std::atomic<_Tp>::value_type __old) noexcept
1505 { __a->wait(__old); }
1507 template<
typename _Tp>
1510 typename std::atomic<_Tp>::value_type __old,
1512 { __a->wait(__old, __m); }
1514 template<
typename _Tp>
1517 { __a->notify_one(); }
1519 template<
typename _Tp>
1522 { __a->notify_all(); }
1523 #endif // __cpp_lib_atomic_wait 1529 template<
typename _ITp>
1532 __atomic_diff_t<_ITp> __i,
1534 {
return __a->fetch_add(__i, __m); }
1536 template<
typename _ITp>
1539 __atomic_diff_t<_ITp> __i,
1541 {
return __a->fetch_add(__i, __m); }
1543 template<
typename _ITp>
1546 __atomic_diff_t<_ITp> __i,
1548 {
return __a->fetch_sub(__i, __m); }
1550 template<
typename _ITp>
1553 __atomic_diff_t<_ITp> __i,
1555 {
return __a->fetch_sub(__i, __m); }
1557 template<
typename _ITp>
1559 atomic_fetch_and_explicit(__atomic_base<_ITp>* __a,
1560 __atomic_val_t<_ITp> __i,
1562 {
return __a->fetch_and(__i, __m); }
1564 template<
typename _ITp>
1566 atomic_fetch_and_explicit(
volatile __atomic_base<_ITp>* __a,
1567 __atomic_val_t<_ITp> __i,
1569 {
return __a->fetch_and(__i, __m); }
1571 template<
typename _ITp>
1573 atomic_fetch_or_explicit(__atomic_base<_ITp>* __a,
1574 __atomic_val_t<_ITp> __i,
1576 {
return __a->fetch_or(__i, __m); }
1578 template<
typename _ITp>
1580 atomic_fetch_or_explicit(
volatile __atomic_base<_ITp>* __a,
1581 __atomic_val_t<_ITp> __i,
1583 {
return __a->fetch_or(__i, __m); }
1585 template<
typename _ITp>
1587 atomic_fetch_xor_explicit(__atomic_base<_ITp>* __a,
1588 __atomic_val_t<_ITp> __i,
1590 {
return __a->fetch_xor(__i, __m); }
1592 template<
typename _ITp>
1594 atomic_fetch_xor_explicit(
volatile __atomic_base<_ITp>* __a,
1595 __atomic_val_t<_ITp> __i,
1597 {
return __a->fetch_xor(__i, __m); }
1599 #ifdef __cpp_lib_atomic_min_max 1600 template<
typename _Tp>
1603 __atomic_val_t<_Tp> __i,
1605 {
return __a->fetch_min(__i, __m); }
1607 template<
typename _Tp>
1609 atomic_fetch_min_explicit(
volatile atomic<_Tp>* __a,
1610 __atomic_val_t<_Tp> __i,
1612 {
return __a->fetch_min(__i, __m); }
1614 template<
typename _Tp>
1617 __atomic_val_t<_Tp> __i,
1619 {
return __a->fetch_max(__i, __m); }
1621 template<
typename _Tp>
1623 atomic_fetch_max_explicit(
volatile atomic<_Tp>* __a,
1624 __atomic_val_t<_Tp> __i,
1626 {
return __a->fetch_max(__i, __m); }
1629 template<
typename _ITp>
1632 __atomic_diff_t<_ITp> __i) noexcept
1633 {
return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
1635 template<
typename _ITp>
1638 __atomic_diff_t<_ITp> __i) noexcept
1639 {
return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
1641 template<
typename _ITp>
1644 __atomic_diff_t<_ITp> __i) noexcept
1645 {
return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
1647 template<
typename _ITp>
1650 __atomic_diff_t<_ITp> __i) noexcept
1651 {
return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
1653 template<
typename _ITp>
1655 atomic_fetch_and(__atomic_base<_ITp>* __a,
1656 __atomic_val_t<_ITp> __i) noexcept
1657 {
return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
1659 template<
typename _ITp>
1661 atomic_fetch_and(
volatile __atomic_base<_ITp>* __a,
1662 __atomic_val_t<_ITp> __i) noexcept
1663 {
return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
1665 template<
typename _ITp>
1667 atomic_fetch_or(__atomic_base<_ITp>* __a,
1668 __atomic_val_t<_ITp> __i) noexcept
1669 {
return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
1671 template<
typename _ITp>
1673 atomic_fetch_or(
volatile __atomic_base<_ITp>* __a,
1674 __atomic_val_t<_ITp> __i) noexcept
1675 {
return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
1677 template<
typename _ITp>
1679 atomic_fetch_xor(__atomic_base<_ITp>* __a,
1680 __atomic_val_t<_ITp> __i) noexcept
1681 {
return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
1683 template<
typename _ITp>
1685 atomic_fetch_xor(
volatile __atomic_base<_ITp>* __a,
1686 __atomic_val_t<_ITp> __i) noexcept
1687 {
return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
1689 #ifdef __cpp_lib_atomic_min_max 1690 template<
typename _Tp>
1693 __atomic_val_t<_Tp> __i) noexcept
1694 {
return atomic_fetch_min_explicit(__a, __i, memory_order_seq_cst); }
1696 template<
typename _Tp>
1699 __atomic_val_t<_Tp> __i) noexcept
1700 {
return atomic_fetch_min_explicit(__a, __i, memory_order_seq_cst); }
1702 template<
typename _Tp>
1705 __atomic_val_t<_Tp> __i) noexcept
1706 {
return atomic_fetch_max_explicit(__a, __i, memory_order_seq_cst); }
1708 template<
typename _Tp>
1711 __atomic_val_t<_Tp> __i) noexcept
1712 {
return atomic_fetch_max_explicit(__a, __i, memory_order_seq_cst); }
1715 #ifdef __cpp_lib_atomic_float 1717 struct atomic<float> : __atomic_float<float>
1719 atomic() noexcept =
default;
1722 atomic(
float __fp) noexcept : __atomic_float<float>(__fp)
1728 using __atomic_float<float>::operator=;
1732 struct atomic<double> : __atomic_float<double>
1734 atomic() noexcept =
default;
1737 atomic(
double __fp) noexcept : __atomic_float<double>(__fp)
1743 using __atomic_float<double>::operator=;
1747 struct atomic<long double> : __atomic_float<long double>
1749 atomic() noexcept =
default;
1752 atomic(
long double __fp) noexcept : __atomic_float<long double>(__fp)
1758 using __atomic_float<long double>::operator=;
1761 #ifdef __STDCPP_FLOAT16_T__ 1763 struct atomic<_Float16> : __atomic_float<_Float16>
1765 atomic() noexcept =
default;
1768 atomic(_Float16 __fp) noexcept : __atomic_float<_Float16>(__fp)
1774 using __atomic_float<_Float16>::operator=;
1778 #ifdef __STDCPP_FLOAT32_T__ 1780 struct atomic<_Float32> : __atomic_float<_Float32>
1782 atomic() noexcept =
default;
1785 atomic(_Float32 __fp) noexcept : __atomic_float<_Float32>(__fp)
1791 using __atomic_float<_Float32>::operator=;
1795 #ifdef __STDCPP_FLOAT64_T__ 1797 struct atomic<_Float64> : __atomic_float<_Float64>
1799 atomic() noexcept =
default;
1802 atomic(_Float64 __fp) noexcept : __atomic_float<_Float64>(__fp)
1808 using __atomic_float<_Float64>::operator=;
1812 #ifdef __STDCPP_FLOAT128_T__ 1814 struct atomic<_Float128> : __atomic_float<_Float128>
1816 atomic() noexcept =
default;
1819 atomic(_Float128 __fp) noexcept : __atomic_float<_Float128>(__fp)
1825 using __atomic_float<_Float128>::operator=;
1829 #ifdef __STDCPP_BFLOAT16_T__ 1831 struct atomic<__gnu_cxx::__bfloat16_t> : __atomic_float<__gnu_cxx::__bfloat16_t>
1833 atomic() noexcept =
default;
1836 atomic(__gnu_cxx::__bfloat16_t __fp) noexcept : __atomic_float<__gnu_cxx::__bfloat16_t>(__fp)
1842 using __atomic_float<__gnu_cxx::__bfloat16_t>::operator=;
1845 #endif // __cpp_lib_atomic_float 1847 #ifdef __cpp_lib_atomic_ref 1849 template<
typename _Tp>
1850 struct atomic_ref : __atomic_ref<_Tp>
1853 atomic_ref(_Tp& __t) noexcept
1856 __glibcxx_assert(((__UINTPTR_TYPE__)this->_M_ptr % this->required_alignment) == 0);
1862 atomic_ref(_Tp&&) =
delete;
1864 template<
typename _Up>
1865 requires is_convertible_v<_Up(*)[1], _Tp(*)[1]>
1866 atomic_ref(atomic_ref<_Up> __other) noexcept
1867 : __atomic_ref<_Tp>(__other._M_ptr)
1870 atomic_ref& operator=(
const atomic_ref&) =
delete;
1872 atomic_ref(
const atomic_ref&) =
default;
1874 using __atomic_ref<_Tp>::operator=;
1877 friend struct atomic_ref;
1879 #endif // __cpp_lib_atomic_ref 1881 #ifdef __cpp_lib_atomic_lock_free_type_aliases 1882 # ifdef _GLIBCXX_HAVE_PLATFORM_WAIT 1883 using atomic_signed_lock_free
1885 using atomic_unsigned_lock_free
1887 # elif ATOMIC_INT_LOCK_FREE == 2 1890 # elif ATOMIC_LONG_LOCK_FREE == 2 1893 # elif ATOMIC_CHAR_LOCK_FREE == 2 1897 # error "libstdc++ bug: no lock-free atomics but they were emitted in <version>" 1903 _GLIBCXX_END_NAMESPACE_VERSION
1908 #endif // _GLIBCXX_ATOMIC atomic< uint_least32_t > atomic_uint_least32_t
atomic_uint_least32_t
Explicit specialization for wchar_t.
atomic< int_fast32_t > atomic_int_fast32_t
atomic_int_fast32_t
atomic< int_fast16_t > atomic_int_fast16_t
atomic_int_fast16_t
Generic atomic type, primary class template.
atomic< uint_fast8_t > atomic_uint_fast8_t
atomic_uint_fast8_t
atomic< signed char > atomic_schar
atomic_schar
atomic< int_least64_t > atomic_int_least64_t
atomic_int_least64_t
atomic< wchar_t > atomic_wchar_t
atomic_wchar_t
atomic< size_t > atomic_size_t
atomic_size_t
atomic< char16_t > atomic_char16_t
atomic_char16_t
#define ATOMIC_BOOL_LOCK_FREE
Explicit specialization for short.
atomic< int_least32_t > atomic_int_least32_t
atomic_int_least32_t
atomic< long long > atomic_llong
atomic_llong
atomic< short > atomic_short
atomic_short
atomic< intmax_t > atomic_intmax_t
atomic_intmax_t
atomic< uint_least64_t > atomic_uint_least64_t
atomic_uint_least64_t
atomic< unsigned long long > atomic_ullong
atomic_ullong
ISO C++ entities toplevel namespace is std.
atomic< ptrdiff_t > atomic_ptrdiff_t
atomic_ptrdiff_t
atomic< char > atomic_char
atomic_char
atomic< bool > atomic_bool
atomic_bool
atomic< uintptr_t > atomic_uintptr_t
atomic_uintptr_t
Explicit specialization for unsigned long.
atomic< unsigned int > atomic_uint
atomic_uint
atomic< intptr_t > atomic_intptr_t
atomic_intptr_t
atomic< int_fast8_t > atomic_int_fast8_t
atomic_int_fast8_t
Explicit specialization for char.
atomic< uint64_t > atomic_uint64_t
atomic_uint64_t
Explicit specialization for char32_t.
atomic< uint_least8_t > atomic_uint_least8_t
atomic_uint_least8_t
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
Explicit specialization for int.
atomic< int16_t > atomic_int16_t
atomic_int16_t
Explicit specialization for unsigned char.
atomic< uint16_t > atomic_uint16_t
atomic_uint16_t
atomic< unsigned short > atomic_ushort
atomic_ushort
atomic< uintmax_t > atomic_uintmax_t
atomic_uintmax_t
atomic< uint_fast64_t > atomic_uint_fast64_t
atomic_uint_fast64_t
atomic< int64_t > atomic_int64_t
atomic_int64_t
Explicit specialization for unsigned long long.
atomic< uint32_t > atomic_uint32_t
atomic_uint32_t
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...
Explicit specialization for long.
atomic< unsigned long > atomic_ulong
atomic_ulong
atomic< uint_fast16_t > atomic_uint_fast16_t
atomic_uint_fast16_t
atomic< uint8_t > atomic_uint8_t
atomic_uint8_t
Explicit specialization for unsigned short.
atomic< int32_t > atomic_int32_t
atomic_int32_t
atomic< uint_least16_t > atomic_uint_least16_t
atomic_uint_least16_t
Explicit specialization for signed char.
atomic< unsigned char > atomic_uchar
atomic_uchar
atomic< int > atomic_int
atomic_int
atomic< int8_t > atomic_int8_t
atomic_int8_t
Explicit specialization for char16_t.
atomic< uint_fast32_t > atomic_uint_fast32_t
atomic_uint_fast32_t
atomic< int_least8_t > atomic_int_least8_t
atomic_int_least8_t
Explicit specialization for long long.
Explicit specialization for unsigned int.
atomic< int_fast64_t > atomic_int_fast64_t
atomic_int_fast64_t
atomic< long > atomic_long
atomic_long
atomic< int_least16_t > atomic_int_least16_t
atomic_int_least16_t
atomic< char32_t > atomic_char32_t
atomic_char32_t
memory_order
Enumeration for memory_order.