3 // Copyright (C) 2008-2026 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file include/atomic
26 * This is a Standard C++ Library header.
29 // Based on "C++ Atomic Types and Operations" by Hans Boehm and Lawrence Crowl.
30 // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2427.html
32 #ifndef _GLIBCXX_ATOMIC
33 #define _GLIBCXX_ATOMIC 1
35 #ifdef _GLIBCXX_SYSHDR
36 #pragma GCC system_header
39 #if __cplusplus < 201103L
40 # include <bits/c++0x_warning.h>
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
51 #include <bits/version.h>
53 #include <bits/atomic_base.h>
55 #include <type_traits>
57 namespace std _GLIBCXX_VISIBILITY(default)
59 _GLIBCXX_BEGIN_NAMESPACE_VERSION
66 template<typename _Tp>
70 // NB: No operators or fetch-operations for this type.
74 using value_type = bool;
77 __atomic_base<bool> _M_base;
80 atomic() noexcept = default;
81 ~atomic() noexcept = default;
82 atomic(const atomic&) = delete;
83 atomic& operator=(const atomic&) = delete;
84 atomic& operator=(const atomic&) volatile = delete;
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
109 static constexpr bool is_always_lock_free = ATOMIC_BOOL_LOCK_FREE == 2;
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,
139 memory_order __m2) noexcept
140 { return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); }
143 compare_exchange_weak(bool& __i1, bool __i2, memory_order __m1,
144 memory_order __m2) volatile noexcept
145 { return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); }
148 compare_exchange_weak(bool& __i1, bool __i2,
149 memory_order __m = memory_order_seq_cst) noexcept
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,
159 memory_order __m2) noexcept
160 { return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); }
163 compare_exchange_strong(bool& __i1, bool __i2, memory_order __m1,
164 memory_order __m2) volatile noexcept
165 { return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); }
168 compare_exchange_strong(bool& __i1, bool __i2,
169 memory_order __m = memory_order_seq_cst) noexcept
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); }
182 // TODO add const volatile overload
185 notify_one() noexcept
186 { _M_base.notify_one(); }
189 notify_all() noexcept
190 { _M_base.notify_all(); }
191 #endif // __cpp_lib_atomic_wait
195 * @brief Generic atomic type, primary class template.
197 * @tparam _Tp Type to be made atomic, must be trivially copyable.
199 template<typename _Tp>
202 using value_type = _Tp;
205 // Align 1/2/4/8/16-byte types to at least their size.
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");
221 // _GLIBCXX_RESOLVE_LIB_DEFECTS
222 // 4069. std::atomic<volatile T> should be ill-formed
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
235 // _GLIBCXX_RESOLVE_LIB_DEFECTS
236 // 4169. std::atomic<T>'s default constructor should be constrained
237 constexpr atomic() noexcept(is_nothrow_default_constructible_v<_Tp>)
238 requires is_default_constructible_v<_Tp>
245 ~atomic() noexcept = default;
246 atomic(const atomic&) = delete;
247 atomic& operator=(const atomic&) = delete;
248 atomic& operator=(const atomic&) volatile = delete;
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())
257 __builtin_clear_padding(std::__addressof(_M_i));
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
279 // Produce a fake, minimally aligned pointer.
280 return __atomic_is_lock_free(sizeof(_M_i),
281 reinterpret_cast<void *>(-_S_alignment));
285 is_lock_free() const volatile noexcept
287 // Produce a fake, minimally aligned pointer.
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
300 __atomic_store(std::__addressof(_M_i),
301 __atomic_impl::__clear_padding(__i),
306 store(_Tp __i, memory_order __m = memory_order_seq_cst) volatile noexcept
308 __atomic_store(std::__addressof(_M_i),
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);
318 __atomic_load(std::__addressof(_M_i), __ptr, int(__m));
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);
327 __atomic_load(std::__addressof(_M_i), __ptr, int(__m));
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);
336 __atomic_exchange(std::__addressof(_M_i),
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);
348 __atomic_exchange(std::__addressof(_M_i),
349 __atomic_impl::__clear_padding(__i),
355 compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s,
356 memory_order __f) noexcept
358 return __atomic_impl::__compare_exchange(_M_i, __e, __i, true,
363 compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s,
364 memory_order __f) volatile noexcept
366 return __atomic_impl::__compare_exchange(_M_i, __e, __i, true,
371 compare_exchange_weak(_Tp& __e, _Tp __i,
372 memory_order __m = memory_order_seq_cst) noexcept
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,
384 memory_order __f) noexcept
386 return __atomic_impl::__compare_exchange(_M_i, __e, __i, false,
391 compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s,
392 memory_order __f) volatile noexcept
394 return __atomic_impl::__compare_exchange(_M_i, __e, __i, false,
399 compare_exchange_strong(_Tp& __e, _Tp __i,
400 memory_order __m = memory_order_seq_cst) noexcept
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
414 std::__atomic_wait_address_v(std::addressof(_M_i), __old,
415 [__m, this] { return this->load(__m); });
418 // TODO add const volatile overload
421 notify_one() noexcept
422 { std::__atomic_notify_address(std::addressof(_M_i), false); }
425 notify_all() noexcept
426 { std::__atomic_notify_address(std::addressof(_M_i), true); }
427 #endif // __cpp_lib_atomic_wait
430 /// Partial specialization for pointer types.
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;
443 atomic(const atomic&) = delete;
444 atomic& operator=(const atomic&) = delete;
445 atomic& operator=(const atomic&) volatile = delete;
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,
586 memory_order __m = memory_order_seq_cst) noexcept
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,
604 memory_order __m = memory_order_seq_cst) noexcept
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,
614 memory_order __m1, memory_order __m2) noexcept
615 { return _M_b.compare_exchange_weak(__p1, __p2, __m1, __m2); }
618 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
620 memory_order __m2) volatile noexcept
621 { return _M_b.compare_exchange_weak(__p1, __p2, __m1, __m2); }
624 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
625 memory_order __m = memory_order_seq_cst) noexcept
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,
641 memory_order __m1, memory_order __m2) noexcept
642 { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
645 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
647 memory_order __m2) volatile noexcept
648 { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
651 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
652 memory_order __m = memory_order_seq_cst) noexcept
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,
669 memory_order __m = memory_order_seq_cst) const noexcept
670 { _M_b.wait(__old, __m); }
672 // TODO add const volatile overload
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,
685 memory_order __m = memory_order_seq_cst) noexcept
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,
705 memory_order __m = memory_order_seq_cst) noexcept
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,
726 memory_order __m = memory_order_seq_cst) noexcept
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,
736 memory_order __m = memory_order_seq_cst) noexcept
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); }
747 /// Explicit specialization for char.
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;
756 atomic(const atomic&) = delete;
757 atomic& operator=(const atomic&) = delete;
758 atomic& operator=(const atomic&) volatile = delete;
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;
770 /// Explicit specialization for signed char.
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;
779 atomic(const atomic&) = delete;
780 atomic& operator=(const atomic&) = delete;
781 atomic& operator=(const atomic&) volatile = delete;
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;
793 /// Explicit specialization for unsigned char.
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;
802 atomic(const atomic&) = delete;
803 atomic& operator=(const atomic&) = delete;
804 atomic& operator=(const atomic&) volatile = delete;
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;
816 /// Explicit specialization for short.
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;
825 atomic(const atomic&) = delete;
826 atomic& operator=(const atomic&) = delete;
827 atomic& operator=(const atomic&) volatile = delete;
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;
839 /// Explicit specialization for unsigned short.
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;
848 atomic(const atomic&) = delete;
849 atomic& operator=(const atomic&) = delete;
850 atomic& operator=(const atomic&) volatile = delete;
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;
862 /// Explicit specialization for int.
864 struct atomic<int> : __atomic_base<int>
866 typedef int __integral_type;
867 typedef __atomic_base<int> __base_type;
869 atomic() noexcept = default;
870 ~atomic() noexcept = default;
871 atomic(const atomic&) = delete;
872 atomic& operator=(const atomic&) = delete;
873 atomic& operator=(const atomic&) volatile = delete;
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;
885 /// Explicit specialization for unsigned int.
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;
894 atomic(const atomic&) = delete;
895 atomic& operator=(const atomic&) = delete;
896 atomic& operator=(const atomic&) volatile = delete;
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;
908 /// Explicit specialization for long.
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;
917 atomic(const atomic&) = delete;
918 atomic& operator=(const atomic&) = delete;
919 atomic& operator=(const atomic&) volatile = delete;
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;
931 /// Explicit specialization for unsigned long.
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;
940 atomic(const atomic&) = delete;
941 atomic& operator=(const atomic&) = delete;
942 atomic& operator=(const atomic&) volatile = delete;
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;
954 /// Explicit specialization for long long.
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;
963 atomic(const atomic&) = delete;
964 atomic& operator=(const atomic&) = delete;
965 atomic& operator=(const atomic&) volatile = delete;
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;
977 /// Explicit specialization for unsigned long long.
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;
986 atomic(const atomic&) = delete;
987 atomic& operator=(const atomic&) = delete;
988 atomic& operator=(const atomic&) volatile = delete;
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;
1000 /// Explicit specialization for wchar_t.
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;
1009 atomic(const atomic&) = delete;
1010 atomic& operator=(const atomic&) = delete;
1011 atomic& operator=(const atomic&) volatile = delete;
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
1024 /// Explicit specialization for 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;
1033 atomic(const atomic&) = delete;
1034 atomic& operator=(const atomic&) = delete;
1035 atomic& operator=(const atomic&) volatile = delete;
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;
1049 /// Explicit specialization for char16_t.
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;
1058 atomic(const atomic&) = delete;
1059 atomic& operator=(const atomic&) = delete;
1060 atomic& operator=(const atomic&) volatile = delete;
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;
1073 /// Explicit specialization for char32_t.
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;
1082 atomic(const atomic&) = delete;
1083 atomic& operator=(const atomic&) = delete;
1084 atomic& operator=(const atomic&) volatile = delete;
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;
1099 typedef atomic<bool> atomic_bool;
1102 typedef atomic<char> atomic_char;
1105 typedef atomic<signed char> atomic_schar;
1108 typedef atomic<unsigned char> atomic_uchar;
1111 typedef atomic<short> atomic_short;
1114 typedef atomic<unsigned short> atomic_ushort;
1117 typedef atomic<int> atomic_int;
1120 typedef atomic<unsigned int> atomic_uint;
1123 typedef atomic<long> atomic_long;
1126 typedef atomic<unsigned long> atomic_ulong;
1129 typedef atomic<long long> atomic_llong;
1132 typedef atomic<unsigned long long> atomic_ullong;
1135 typedef atomic<wchar_t> atomic_wchar_t;
1137 #ifdef _GLIBCXX_USE_CHAR8_T
1139 typedef atomic<char8_t> atomic_char8_t;
1143 typedef atomic<char16_t> atomic_char16_t;
1146 typedef atomic<char32_t> atomic_char32_t;
1148 #ifdef _GLIBCXX_USE_C99_STDINT
1149 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1150 // 2441. Exact-width atomic typedefs should be provided
1153 typedef atomic<int8_t> atomic_int8_t;
1156 typedef atomic<uint8_t> atomic_uint8_t;
1159 typedef atomic<int16_t> atomic_int16_t;
1162 typedef atomic<uint16_t> atomic_uint16_t;
1165 typedef atomic<int32_t> atomic_int32_t;
1168 typedef atomic<uint32_t> atomic_uint32_t;
1171 typedef atomic<int64_t> atomic_int64_t;
1174 typedef atomic<uint64_t> atomic_uint64_t;
1177 /// atomic_int_least8_t
1178 typedef atomic<int_least8_t> atomic_int_least8_t;
1180 /// atomic_uint_least8_t
1181 typedef atomic<uint_least8_t> atomic_uint_least8_t;
1183 /// atomic_int_least16_t
1184 typedef atomic<int_least16_t> atomic_int_least16_t;
1186 /// atomic_uint_least16_t
1187 typedef atomic<uint_least16_t> atomic_uint_least16_t;
1189 /// atomic_int_least32_t
1190 typedef atomic<int_least32_t> atomic_int_least32_t;
1192 /// atomic_uint_least32_t
1193 typedef atomic<uint_least32_t> atomic_uint_least32_t;
1195 /// atomic_int_least64_t
1196 typedef atomic<int_least64_t> atomic_int_least64_t;
1198 /// atomic_uint_least64_t
1199 typedef atomic<uint_least64_t> atomic_uint_least64_t;
1202 /// atomic_int_fast8_t
1203 typedef atomic<int_fast8_t> atomic_int_fast8_t;
1205 /// atomic_uint_fast8_t
1206 typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
1208 /// atomic_int_fast16_t
1209 typedef atomic<int_fast16_t> atomic_int_fast16_t;
1211 /// atomic_uint_fast16_t
1212 typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
1214 /// atomic_int_fast32_t
1215 typedef atomic<int_fast32_t> atomic_int_fast32_t;
1217 /// atomic_uint_fast32_t
1218 typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
1220 /// atomic_int_fast64_t
1221 typedef atomic<int_fast64_t> atomic_int_fast64_t;
1223 /// atomic_uint_fast64_t
1224 typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
1228 typedef atomic<intptr_t> atomic_intptr_t;
1230 /// atomic_uintptr_t
1231 typedef atomic<uintptr_t> atomic_uintptr_t;
1234 typedef atomic<size_t> atomic_size_t;
1236 /// atomic_ptrdiff_t
1237 typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
1240 typedef atomic<intmax_t> atomic_intmax_t;
1242 /// atomic_uintmax_t
1243 typedef atomic<uintmax_t> atomic_uintmax_t;
1245 // Function definitions, atomic_flag operations.
1247 atomic_flag_test_and_set_explicit(atomic_flag* __a,
1248 memory_order __m) noexcept
1249 { return __a->test_and_set(__m); }
1252 atomic_flag_test_and_set_explicit(volatile atomic_flag* __a,
1253 memory_order __m) noexcept
1254 { return __a->test_and_set(__m); }
1256 #if __cpp_lib_atomic_flag_test
1258 atomic_flag_test(const atomic_flag* __a) noexcept
1259 { return __a->test(); }
1262 atomic_flag_test(const volatile atomic_flag* __a) noexcept
1263 { return __a->test(); }
1266 atomic_flag_test_explicit(const atomic_flag* __a,
1267 memory_order __m) noexcept
1268 { return __a->test(__m); }
1271 atomic_flag_test_explicit(const volatile atomic_flag* __a,
1272 memory_order __m) noexcept
1273 { return __a->test(__m); }
1277 atomic_flag_clear_explicit(atomic_flag* __a, memory_order __m) noexcept
1278 { __a->clear(__m); }
1281 atomic_flag_clear_explicit(volatile atomic_flag* __a,
1282 memory_order __m) noexcept
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); }
1294 atomic_flag_clear(atomic_flag* __a) noexcept
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,
1308 memory_order __m) noexcept
1309 { __a->wait(__old, __m); }
1312 atomic_flag_notify_one(atomic_flag* __a) noexcept
1313 { __a->notify_one(); }
1316 atomic_flag_notify_all(atomic_flag* __a) noexcept
1317 { __a->notify_all(); }
1318 #endif // __cpp_lib_atomic_wait
1320 /// @cond undocumented
1321 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1322 // 3220. P0558 broke conforming C++14 uses of atomic shared_ptr
1323 template<typename _Tp>
1324 using __atomic_val_t = __type_identity_t<_Tp>;
1325 template<typename _Tp>
1326 using __atomic_diff_t = typename atomic<_Tp>::difference_type;
1329 // [atomics.nonmembers] Non-member functions.
1330 // Function templates generally applicable to atomic types.
1331 template<typename _ITp>
1333 atomic_is_lock_free(const atomic<_ITp>* __a) noexcept
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,
1354 memory_order __m) noexcept
1355 { __a->store(__i, __m); }
1357 template<typename _ITp>
1359 atomic_store_explicit(volatile atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1360 memory_order __m) noexcept
1361 { __a->store(__i, __m); }
1363 template<typename _ITp>
1365 atomic_load_explicit(const atomic<_ITp>* __a, memory_order __m) noexcept
1366 { return __a->load(__m); }
1368 template<typename _ITp>
1370 atomic_load_explicit(const volatile atomic<_ITp>* __a,
1371 memory_order __m) noexcept
1372 { return __a->load(__m); }
1374 template<typename _ITp>
1376 atomic_exchange_explicit(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1377 memory_order __m) noexcept
1378 { return __a->exchange(__i, __m); }
1380 template<typename _ITp>
1382 atomic_exchange_explicit(volatile atomic<_ITp>* __a,
1383 __atomic_val_t<_ITp> __i,
1384 memory_order __m) noexcept
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,
1393 memory_order __m2) noexcept
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,
1402 memory_order __m2) noexcept
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,
1411 memory_order __m2) noexcept
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,
1420 memory_order __m2) noexcept
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>
1436 atomic_load(const atomic<_ITp>* __a) noexcept
1437 { return atomic_load_explicit(__a, memory_order_seq_cst); }
1439 template<typename _ITp>
1441 atomic_load(const volatile atomic<_ITp>* __a) noexcept
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>
1451 atomic_exchange(volatile atomic<_ITp>* __a,
1452 __atomic_val_t<_ITp> __i) noexcept
1453 { return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
1455 template<typename _ITp>
1457 atomic_compare_exchange_weak(atomic<_ITp>* __a,
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>
1479 atomic_compare_exchange_strong(atomic<_ITp>* __a,
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>
1503 atomic_wait(const atomic<_Tp>* __a,
1504 typename std::atomic<_Tp>::value_type __old) noexcept
1505 { __a->wait(__old); }
1507 template<typename _Tp>
1509 atomic_wait_explicit(const atomic<_Tp>* __a,
1510 typename std::atomic<_Tp>::value_type __old,
1511 std::memory_order __m) noexcept
1512 { __a->wait(__old, __m); }
1514 template<typename _Tp>
1516 atomic_notify_one(atomic<_Tp>* __a) noexcept
1517 { __a->notify_one(); }
1519 template<typename _Tp>
1521 atomic_notify_all(atomic<_Tp>* __a) noexcept
1522 { __a->notify_all(); }
1523 #endif // __cpp_lib_atomic_wait
1525 // Function templates for atomic_integral and atomic_pointer operations only.
1526 // Some operations (and, or, xor) are only available for atomic integrals,
1527 // which is implemented by taking a parameter of type __atomic_base<_ITp>*.
1529 template<typename _ITp>
1531 atomic_fetch_add_explicit(atomic<_ITp>* __a,
1532 __atomic_diff_t<_ITp> __i,
1533 memory_order __m) noexcept
1534 { return __a->fetch_add(__i, __m); }
1536 template<typename _ITp>
1538 atomic_fetch_add_explicit(volatile atomic<_ITp>* __a,
1539 __atomic_diff_t<_ITp> __i,
1540 memory_order __m) noexcept
1541 { return __a->fetch_add(__i, __m); }
1543 template<typename _ITp>
1545 atomic_fetch_sub_explicit(atomic<_ITp>* __a,
1546 __atomic_diff_t<_ITp> __i,
1547 memory_order __m) noexcept
1548 { return __a->fetch_sub(__i, __m); }
1550 template<typename _ITp>
1552 atomic_fetch_sub_explicit(volatile atomic<_ITp>* __a,
1553 __atomic_diff_t<_ITp> __i,
1554 memory_order __m) noexcept
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,
1561 memory_order __m) noexcept
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,
1568 memory_order __m) noexcept
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,
1575 memory_order __m) noexcept
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,
1582 memory_order __m) noexcept
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,
1589 memory_order __m) noexcept
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,
1596 memory_order __m) noexcept
1597 { return __a->fetch_xor(__i, __m); }
1599 #ifdef __cpp_lib_atomic_min_max
1600 template<typename _Tp>
1602 atomic_fetch_min_explicit(atomic<_Tp>* __a,
1603 __atomic_val_t<_Tp> __i,
1604 memory_order __m) noexcept
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,
1611 memory_order __m) noexcept
1612 { return __a->fetch_min(__i, __m); }
1614 template<typename _Tp>
1616 atomic_fetch_max_explicit(atomic<_Tp>* __a,
1617 __atomic_val_t<_Tp> __i,
1618 memory_order __m) noexcept
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,
1625 memory_order __m) noexcept
1626 { return __a->fetch_max(__i, __m); }
1629 template<typename _ITp>
1631 atomic_fetch_add(atomic<_ITp>* __a,
1632 __atomic_diff_t<_ITp> __i) noexcept
1633 { return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
1635 template<typename _ITp>
1637 atomic_fetch_add(volatile atomic<_ITp>* __a,
1638 __atomic_diff_t<_ITp> __i) noexcept
1639 { return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
1641 template<typename _ITp>
1643 atomic_fetch_sub(atomic<_ITp>* __a,
1644 __atomic_diff_t<_ITp> __i) noexcept
1645 { return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
1647 template<typename _ITp>
1649 atomic_fetch_sub(volatile atomic<_ITp>* __a,
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>
1692 atomic_fetch_min(atomic<_Tp>* __a,
1693 __atomic_val_t<_Tp> __i) noexcept
1694 { return atomic_fetch_min_explicit(__a, __i, memory_order_seq_cst); }
1696 template<typename _Tp>
1698 atomic_fetch_min(volatile atomic<_Tp>* __a,
1699 __atomic_val_t<_Tp> __i) noexcept
1700 { return atomic_fetch_min_explicit(__a, __i, memory_order_seq_cst); }
1702 template<typename _Tp>
1704 atomic_fetch_max(atomic<_Tp>* __a,
1705 __atomic_val_t<_Tp> __i) noexcept
1706 { return atomic_fetch_max_explicit(__a, __i, memory_order_seq_cst); }
1708 template<typename _Tp>
1710 atomic_fetch_max(volatile atomic<_Tp>* __a,
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)
1725 atomic& operator=(const atomic&) volatile = delete;
1726 atomic& operator=(const atomic&) = delete;
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)
1740 atomic& operator=(const atomic&) volatile = delete;
1741 atomic& operator=(const atomic&) = delete;
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)
1755 atomic& operator=(const atomic&) volatile = delete;
1756 atomic& operator=(const atomic&) = delete;
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)
1771 atomic& operator=(const atomic&) volatile = delete;
1772 atomic& operator=(const atomic&) = delete;
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)
1788 atomic& operator=(const atomic&) volatile = delete;
1789 atomic& operator=(const atomic&) = delete;
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)
1805 atomic& operator=(const atomic&) volatile = delete;
1806 atomic& operator=(const atomic&) = delete;
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)
1822 atomic& operator=(const atomic&) volatile = delete;
1823 atomic& operator=(const atomic&) = delete;
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)
1839 atomic& operator=(const atomic&) volatile = delete;
1840 atomic& operator=(const atomic&) = delete;
1842 using __atomic_float<__gnu_cxx::__bfloat16_t>::operator=;
1845 #endif // __cpp_lib_atomic_float
1847 #ifdef __cpp_lib_atomic_ref
1848 /// Class template to provide atomic operations on a non-atomic variable.
1849 template<typename _Tp>
1850 struct atomic_ref : __atomic_ref<_Tp>
1853 atomic_ref(_Tp& __t) noexcept
1854 : __atomic_ref<_Tp>(std::addressof(__t))
1856 __glibcxx_assert(((__UINTPTR_TYPE__)this->_M_ptr % this->required_alignment) == 0);
1859 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1860 // 4472. std::atomic_ref<const T> can be constructed from temporaries
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
1884 = atomic<make_signed_t<__detail::__platform_wait_t>>;
1885 using atomic_unsigned_lock_free
1886 = atomic<make_unsigned_t<__detail::__platform_wait_t>>;
1887 # elif ATOMIC_INT_LOCK_FREE == 2
1888 using atomic_signed_lock_free = atomic<signed int>;
1889 using atomic_unsigned_lock_free = atomic<unsigned int>;
1890 # elif ATOMIC_LONG_LOCK_FREE == 2
1891 using atomic_signed_lock_free = atomic<signed long>;
1892 using atomic_unsigned_lock_free = atomic<unsigned long>;
1893 # elif ATOMIC_CHAR_LOCK_FREE == 2
1894 using atomic_signed_lock_free = atomic<signed char>;
1895 using atomic_unsigned_lock_free = atomic<unsigned char>;
1897 # error "libstdc++ bug: no lock-free atomics but they were emitted in <version>"
1901 /// @} group atomics
1903 _GLIBCXX_END_NAMESPACE_VERSION
1908 #endif // _GLIBCXX_ATOMIC