3// Copyright (C) 2008-2025 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
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_ref
47#define __glibcxx_want_atomic_lock_free_type_aliases
48#define __glibcxx_want_atomic_value_initialization
49#define __glibcxx_want_atomic_wait
50#include <bits/version.h>
52#include <bits/atomic_base.h>
56namespace std _GLIBCXX_VISIBILITY(default)
58_GLIBCXX_BEGIN_NAMESPACE_VERSION
65 template<typename _Tp>
69 // NB: No operators or fetch-operations for this type.
73 using value_type = bool;
76 __atomic_base<bool> _M_base;
79 atomic() noexcept = default;
80 ~atomic() noexcept = default;
81 atomic(const atomic&) = delete;
82 atomic& operator=(const atomic&) = delete;
83 atomic& operator=(const atomic&) volatile = delete;
85 constexpr atomic(bool __i) noexcept : _M_base(__i) { }
88 operator=(bool __i) noexcept
89 { return _M_base.operator=(__i); }
92 operator=(bool __i) volatile noexcept
93 { return _M_base.operator=(__i); }
95 operator bool() const noexcept
96 { return _M_base.load(); }
98 operator bool() const volatile noexcept
99 { return _M_base.load(); }
102 is_lock_free() const noexcept { return _M_base.is_lock_free(); }
105 is_lock_free() const volatile noexcept { return _M_base.is_lock_free(); }
107#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
108 static constexpr bool is_always_lock_free = ATOMIC_BOOL_LOCK_FREE == 2;
112 store(bool __i, memory_order __m = memory_order_seq_cst) noexcept
113 { _M_base.store(__i, __m); }
116 store(bool __i, memory_order __m = memory_order_seq_cst) volatile noexcept
117 { _M_base.store(__i, __m); }
120 load(memory_order __m = memory_order_seq_cst) const noexcept
121 { return _M_base.load(__m); }
124 load(memory_order __m = memory_order_seq_cst) const volatile noexcept
125 { return _M_base.load(__m); }
128 exchange(bool __i, memory_order __m = memory_order_seq_cst) noexcept
129 { return _M_base.exchange(__i, __m); }
133 memory_order __m = memory_order_seq_cst) volatile noexcept
134 { return _M_base.exchange(__i, __m); }
137 compare_exchange_weak(bool& __i1, bool __i2, memory_order __m1,
138 memory_order __m2) noexcept
139 { return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); }
142 compare_exchange_weak(bool& __i1, bool __i2, memory_order __m1,
143 memory_order __m2) volatile noexcept
144 { return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); }
147 compare_exchange_weak(bool& __i1, bool __i2,
148 memory_order __m = memory_order_seq_cst) noexcept
149 { return _M_base.compare_exchange_weak(__i1, __i2, __m); }
152 compare_exchange_weak(bool& __i1, bool __i2,
153 memory_order __m = memory_order_seq_cst) volatile noexcept
154 { return _M_base.compare_exchange_weak(__i1, __i2, __m); }
157 compare_exchange_strong(bool& __i1, bool __i2, memory_order __m1,
158 memory_order __m2) noexcept
159 { return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); }
162 compare_exchange_strong(bool& __i1, bool __i2, memory_order __m1,
163 memory_order __m2) volatile noexcept
164 { return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); }
167 compare_exchange_strong(bool& __i1, bool __i2,
168 memory_order __m = memory_order_seq_cst) noexcept
169 { return _M_base.compare_exchange_strong(__i1, __i2, __m); }
172 compare_exchange_strong(bool& __i1, bool __i2,
173 memory_order __m = memory_order_seq_cst) volatile noexcept
174 { return _M_base.compare_exchange_strong(__i1, __i2, __m); }
176#if __cpp_lib_atomic_wait
178 wait(bool __old, memory_order __m = memory_order_seq_cst) const noexcept
179 { _M_base.wait(__old, __m); }
181 // TODO add const volatile overload
184 notify_one() noexcept
185 { _M_base.notify_one(); }
188 notify_all() noexcept
189 { _M_base.notify_all(); }
190#endif // __cpp_lib_atomic_wait
194 * @brief Generic atomic type, primary class template.
196 * @tparam _Tp Type to be made atomic, must be trivially copyable.
198 template<typename _Tp>
201 using value_type = _Tp;
204 // Align 1/2/4/8/16-byte types to at least their size.
205 static constexpr int _S_min_alignment
206 = (sizeof(_Tp) & (sizeof(_Tp) - 1)) || sizeof(_Tp) > 16
209 static constexpr int _S_alignment
210 = _S_min_alignment > alignof(_Tp) ? _S_min_alignment : alignof(_Tp);
212 alignas(_S_alignment) _Tp _M_i;
214 static_assert(__is_trivially_copyable(_Tp),
215 "std::atomic requires a trivially copyable type");
217 static_assert(sizeof(_Tp) > 0,
218 "Incomplete or zero-sized types are not supported");
220#if __cplusplus > 201703L
221 static_assert(is_copy_constructible_v<_Tp>);
222 static_assert(is_move_constructible_v<_Tp>);
223 static_assert(is_copy_assignable_v<_Tp>);
224 static_assert(is_move_assignable_v<_Tp>);
228#if __cpp_lib_atomic_value_initialization
229 // _GLIBCXX_RESOLVE_LIB_DEFECTS
230 // 4169. std::atomic<T>'s default constructor should be constrained
231 constexpr atomic() noexcept(is_nothrow_default_constructible_v<_Tp>)
232 requires is_default_constructible_v<_Tp>
239 ~atomic() noexcept = default;
240 atomic(const atomic&) = delete;
241 atomic& operator=(const atomic&) = delete;
242 atomic& operator=(const atomic&) volatile = delete;
244#pragma GCC diagnostic push
245#pragma GCC diagnostic ignored "-Wc++14-extensions" // constexpr ctor body
246 constexpr atomic(_Tp __i) noexcept : _M_i(__i)
248#if __has_builtin(__builtin_clear_padding)
249 if _GLIBCXX17_CONSTEXPR (__atomic_impl::__maybe_has_padding<_Tp>())
250 if (!std::__is_constant_evaluated())
251 __builtin_clear_padding(std::__addressof(_M_i));
254#pragma GCC diagnostic pop
256 operator _Tp() const noexcept
259 operator _Tp() const volatile noexcept
263 operator=(_Tp __i) noexcept
264 { store(__i); return __i; }
267 operator=(_Tp __i) volatile noexcept
268 { store(__i); return __i; }
271 is_lock_free() const noexcept
273 // Produce a fake, minimally aligned pointer.
274 return __atomic_is_lock_free(sizeof(_M_i),
275 reinterpret_cast<void *>(-_S_alignment));
279 is_lock_free() const volatile noexcept
281 // Produce a fake, minimally aligned pointer.
282 return __atomic_is_lock_free(sizeof(_M_i),
283 reinterpret_cast<void *>(-_S_alignment));
286#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
287 static constexpr bool is_always_lock_free
288 = __atomic_always_lock_free(sizeof(_M_i), 0);
292 store(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept
294 __atomic_store(std::__addressof(_M_i),
295 __atomic_impl::__clear_padding(__i),
300 store(_Tp __i, memory_order __m = memory_order_seq_cst) volatile noexcept
302 __atomic_store(std::__addressof(_M_i),
303 __atomic_impl::__clear_padding(__i),
308 load(memory_order __m = memory_order_seq_cst) const noexcept
310 alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
311 _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
312 __atomic_load(std::__addressof(_M_i), __ptr, int(__m));
317 load(memory_order __m = memory_order_seq_cst) const volatile noexcept
319 alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
320 _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
321 __atomic_load(std::__addressof(_M_i), __ptr, int(__m));
326 exchange(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept
328 alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
329 _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
330 __atomic_exchange(std::__addressof(_M_i),
331 __atomic_impl::__clear_padding(__i),
338 memory_order __m = memory_order_seq_cst) volatile noexcept
340 alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
341 _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
342 __atomic_exchange(std::__addressof(_M_i),
343 __atomic_impl::__clear_padding(__i),
349 compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s,
350 memory_order __f) noexcept
352 return __atomic_impl::__compare_exchange(_M_i, __e, __i, true,
357 compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s,
358 memory_order __f) volatile noexcept
360 return __atomic_impl::__compare_exchange(_M_i, __e, __i, true,
365 compare_exchange_weak(_Tp& __e, _Tp __i,
366 memory_order __m = memory_order_seq_cst) noexcept
367 { return compare_exchange_weak(__e, __i, __m,
368 __cmpexch_failure_order(__m)); }
371 compare_exchange_weak(_Tp& __e, _Tp __i,
372 memory_order __m = memory_order_seq_cst) volatile noexcept
373 { return compare_exchange_weak(__e, __i, __m,
374 __cmpexch_failure_order(__m)); }
377 compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s,
378 memory_order __f) noexcept
380 return __atomic_impl::__compare_exchange(_M_i, __e, __i, false,
385 compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s,
386 memory_order __f) volatile noexcept
388 return __atomic_impl::__compare_exchange(_M_i, __e, __i, false,
393 compare_exchange_strong(_Tp& __e, _Tp __i,
394 memory_order __m = memory_order_seq_cst) noexcept
395 { return compare_exchange_strong(__e, __i, __m,
396 __cmpexch_failure_order(__m)); }
399 compare_exchange_strong(_Tp& __e, _Tp __i,
400 memory_order __m = memory_order_seq_cst) volatile noexcept
401 { return compare_exchange_strong(__e, __i, __m,
402 __cmpexch_failure_order(__m)); }
404#if __cpp_lib_atomic_wait // C++ >= 20
406 wait(_Tp __old, memory_order __m = memory_order_seq_cst) const noexcept
408 std::__atomic_wait_address_v(std::addressof(_M_i), __old,
409 [__m, this] { return this->load(__m); });
412 // TODO add const volatile overload
415 notify_one() noexcept
416 { std::__atomic_notify_address(std::addressof(_M_i), false); }
419 notify_all() noexcept
420 { std::__atomic_notify_address(std::addressof(_M_i), true); }
421#endif // __cpp_lib_atomic_wait
424 /// Partial specialization for pointer types.
425 template<typename _Tp>
428 using value_type = _Tp*;
429 using difference_type = ptrdiff_t;
431 typedef _Tp* __pointer_type;
432 typedef __atomic_base<_Tp*> __base_type;
435 atomic() noexcept = default;
436 ~atomic() noexcept = default;
437 atomic(const atomic&) = delete;
438 atomic& operator=(const atomic&) = delete;
439 atomic& operator=(const atomic&) volatile = delete;
441 constexpr atomic(__pointer_type __p) noexcept : _M_b(__p) { }
443 operator __pointer_type() const noexcept
444 { return __pointer_type(_M_b); }
446 operator __pointer_type() const volatile noexcept
447 { return __pointer_type(_M_b); }
450 operator=(__pointer_type __p) noexcept
451 { return _M_b.operator=(__p); }
454 operator=(__pointer_type __p) volatile noexcept
455 { return _M_b.operator=(__p); }
458 operator++(int) noexcept
460#if __cplusplus >= 201703L
461 static_assert( is_object_v<_Tp>, "pointer to object type" );
467 operator++(int) volatile noexcept
469#if __cplusplus >= 201703L
470 static_assert( is_object_v<_Tp>, "pointer to object type" );
476 operator--(int) noexcept
478#if __cplusplus >= 201703L
479 static_assert( is_object_v<_Tp>, "pointer to object type" );
485 operator--(int) volatile noexcept
487#if __cplusplus >= 201703L
488 static_assert( is_object_v<_Tp>, "pointer to object type" );
494 operator++() noexcept
496#if __cplusplus >= 201703L
497 static_assert( is_object_v<_Tp>, "pointer to object type" );
503 operator++() volatile noexcept
505#if __cplusplus >= 201703L
506 static_assert( is_object_v<_Tp>, "pointer to object type" );
512 operator--() noexcept
514#if __cplusplus >= 201703L
515 static_assert( is_object_v<_Tp>, "pointer to object type" );
521 operator--() volatile noexcept
523#if __cplusplus >= 201703L
524 static_assert( is_object_v<_Tp>, "pointer to object type" );
530 operator+=(ptrdiff_t __d) noexcept
532#if __cplusplus >= 201703L
533 static_assert( is_object_v<_Tp>, "pointer to object type" );
535 return _M_b.operator+=(__d);
539 operator+=(ptrdiff_t __d) volatile noexcept
541#if __cplusplus >= 201703L
542 static_assert( is_object_v<_Tp>, "pointer to object type" );
544 return _M_b.operator+=(__d);
548 operator-=(ptrdiff_t __d) noexcept
550#if __cplusplus >= 201703L
551 static_assert( is_object_v<_Tp>, "pointer to object type" );
553 return _M_b.operator-=(__d);
557 operator-=(ptrdiff_t __d) volatile noexcept
559#if __cplusplus >= 201703L
560 static_assert( is_object_v<_Tp>, "pointer to object type" );
562 return _M_b.operator-=(__d);
566 is_lock_free() const noexcept
567 { return _M_b.is_lock_free(); }
570 is_lock_free() const volatile noexcept
571 { return _M_b.is_lock_free(); }
573#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
574 static constexpr bool is_always_lock_free
575 = ATOMIC_POINTER_LOCK_FREE == 2;
579 store(__pointer_type __p,
580 memory_order __m = memory_order_seq_cst) noexcept
581 { return _M_b.store(__p, __m); }
584 store(__pointer_type __p,
585 memory_order __m = memory_order_seq_cst) volatile noexcept
586 { return _M_b.store(__p, __m); }
589 load(memory_order __m = memory_order_seq_cst) const noexcept
590 { return _M_b.load(__m); }
593 load(memory_order __m = memory_order_seq_cst) const volatile noexcept
594 { return _M_b.load(__m); }
597 exchange(__pointer_type __p,
598 memory_order __m = memory_order_seq_cst) noexcept
599 { return _M_b.exchange(__p, __m); }
602 exchange(__pointer_type __p,
603 memory_order __m = memory_order_seq_cst) volatile noexcept
604 { return _M_b.exchange(__p, __m); }
607 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
608 memory_order __m1, memory_order __m2) noexcept
609 { return _M_b.compare_exchange_weak(__p1, __p2, __m1, __m2); }
612 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
614 memory_order __m2) volatile noexcept
615 { return _M_b.compare_exchange_weak(__p1, __p2, __m1, __m2); }
618 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
619 memory_order __m = memory_order_seq_cst) noexcept
621 return compare_exchange_weak(__p1, __p2, __m,
622 __cmpexch_failure_order(__m));
626 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
627 memory_order __m = memory_order_seq_cst) volatile noexcept
629 return compare_exchange_weak(__p1, __p2, __m,
630 __cmpexch_failure_order(__m));
634 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
635 memory_order __m1, memory_order __m2) noexcept
636 { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
639 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
641 memory_order __m2) volatile noexcept
642 { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
645 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
646 memory_order __m = memory_order_seq_cst) noexcept
648 return _M_b.compare_exchange_strong(__p1, __p2, __m,
649 __cmpexch_failure_order(__m));
653 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
654 memory_order __m = memory_order_seq_cst) volatile noexcept
656 return _M_b.compare_exchange_strong(__p1, __p2, __m,
657 __cmpexch_failure_order(__m));
660#if __cpp_lib_atomic_wait
662 wait(__pointer_type __old, memory_order __m = memory_order_seq_cst) const noexcept
663 { _M_b.wait(__old, __m); }
665 // TODO add const volatile overload
668 notify_one() noexcept
669 { _M_b.notify_one(); }
672 notify_all() noexcept
673 { _M_b.notify_all(); }
674#endif // __cpp_lib_atomic_wait
677 fetch_add(ptrdiff_t __d,
678 memory_order __m = memory_order_seq_cst) noexcept
680#if __cplusplus >= 201703L
681 static_assert( is_object_v<_Tp>, "pointer to object type" );
683 return _M_b.fetch_add(__d, __m);
687 fetch_add(ptrdiff_t __d,
688 memory_order __m = memory_order_seq_cst) volatile noexcept
690#if __cplusplus >= 201703L
691 static_assert( is_object_v<_Tp>, "pointer to object type" );
693 return _M_b.fetch_add(__d, __m);
697 fetch_sub(ptrdiff_t __d,
698 memory_order __m = memory_order_seq_cst) noexcept
700#if __cplusplus >= 201703L
701 static_assert( is_object_v<_Tp>, "pointer to object type" );
703 return _M_b.fetch_sub(__d, __m);
707 fetch_sub(ptrdiff_t __d,
708 memory_order __m = memory_order_seq_cst) volatile noexcept
710#if __cplusplus >= 201703L
711 static_assert( is_object_v<_Tp>, "pointer to object type" );
713 return _M_b.fetch_sub(__d, __m);
718 /// Explicit specialization for char.
720 struct atomic<char> : __atomic_base<char>
722 typedef char __integral_type;
723 typedef __atomic_base<char> __base_type;
725 atomic() noexcept = default;
726 ~atomic() noexcept = default;
727 atomic(const atomic&) = delete;
728 atomic& operator=(const atomic&) = delete;
729 atomic& operator=(const atomic&) volatile = delete;
731 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
733 using __base_type::operator __integral_type;
734 using __base_type::operator=;
736#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
737 static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
741 /// Explicit specialization for signed char.
743 struct atomic<signed char> : __atomic_base<signed char>
745 typedef signed char __integral_type;
746 typedef __atomic_base<signed char> __base_type;
748 atomic() noexcept= default;
749 ~atomic() noexcept = default;
750 atomic(const atomic&) = delete;
751 atomic& operator=(const atomic&) = delete;
752 atomic& operator=(const atomic&) volatile = delete;
754 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
756 using __base_type::operator __integral_type;
757 using __base_type::operator=;
759#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
760 static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
764 /// Explicit specialization for unsigned char.
766 struct atomic<unsigned char> : __atomic_base<unsigned char>
768 typedef unsigned char __integral_type;
769 typedef __atomic_base<unsigned char> __base_type;
771 atomic() noexcept= default;
772 ~atomic() noexcept = default;
773 atomic(const atomic&) = delete;
774 atomic& operator=(const atomic&) = delete;
775 atomic& operator=(const atomic&) volatile = delete;
777 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
779 using __base_type::operator __integral_type;
780 using __base_type::operator=;
782#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
783 static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
787 /// Explicit specialization for short.
789 struct atomic<short> : __atomic_base<short>
791 typedef short __integral_type;
792 typedef __atomic_base<short> __base_type;
794 atomic() noexcept = default;
795 ~atomic() noexcept = default;
796 atomic(const atomic&) = delete;
797 atomic& operator=(const atomic&) = delete;
798 atomic& operator=(const atomic&) volatile = delete;
800 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
802 using __base_type::operator __integral_type;
803 using __base_type::operator=;
805#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
806 static constexpr bool is_always_lock_free = ATOMIC_SHORT_LOCK_FREE == 2;
810 /// Explicit specialization for unsigned short.
812 struct atomic<unsigned short> : __atomic_base<unsigned short>
814 typedef unsigned short __integral_type;
815 typedef __atomic_base<unsigned short> __base_type;
817 atomic() noexcept = default;
818 ~atomic() noexcept = default;
819 atomic(const atomic&) = delete;
820 atomic& operator=(const atomic&) = delete;
821 atomic& operator=(const atomic&) volatile = delete;
823 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
825 using __base_type::operator __integral_type;
826 using __base_type::operator=;
828#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
829 static constexpr bool is_always_lock_free = ATOMIC_SHORT_LOCK_FREE == 2;
833 /// Explicit specialization for int.
835 struct atomic<int> : __atomic_base<int>
837 typedef int __integral_type;
838 typedef __atomic_base<int> __base_type;
840 atomic() noexcept = default;
841 ~atomic() noexcept = default;
842 atomic(const atomic&) = delete;
843 atomic& operator=(const atomic&) = delete;
844 atomic& operator=(const atomic&) volatile = delete;
846 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
848 using __base_type::operator __integral_type;
849 using __base_type::operator=;
851#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
852 static constexpr bool is_always_lock_free = ATOMIC_INT_LOCK_FREE == 2;
856 /// Explicit specialization for unsigned int.
858 struct atomic<unsigned int> : __atomic_base<unsigned int>
860 typedef unsigned int __integral_type;
861 typedef __atomic_base<unsigned int> __base_type;
863 atomic() noexcept = default;
864 ~atomic() noexcept = default;
865 atomic(const atomic&) = delete;
866 atomic& operator=(const atomic&) = delete;
867 atomic& operator=(const atomic&) volatile = delete;
869 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
871 using __base_type::operator __integral_type;
872 using __base_type::operator=;
874#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
875 static constexpr bool is_always_lock_free = ATOMIC_INT_LOCK_FREE == 2;
879 /// Explicit specialization for long.
881 struct atomic<long> : __atomic_base<long>
883 typedef long __integral_type;
884 typedef __atomic_base<long> __base_type;
886 atomic() noexcept = default;
887 ~atomic() noexcept = default;
888 atomic(const atomic&) = delete;
889 atomic& operator=(const atomic&) = delete;
890 atomic& operator=(const atomic&) volatile = delete;
892 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
894 using __base_type::operator __integral_type;
895 using __base_type::operator=;
897#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
898 static constexpr bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2;
902 /// Explicit specialization for unsigned long.
904 struct atomic<unsigned long> : __atomic_base<unsigned long>
906 typedef unsigned long __integral_type;
907 typedef __atomic_base<unsigned long> __base_type;
909 atomic() noexcept = default;
910 ~atomic() noexcept = default;
911 atomic(const atomic&) = delete;
912 atomic& operator=(const atomic&) = delete;
913 atomic& operator=(const atomic&) volatile = delete;
915 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
917 using __base_type::operator __integral_type;
918 using __base_type::operator=;
920#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
921 static constexpr bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2;
925 /// Explicit specialization for long long.
927 struct atomic<long long> : __atomic_base<long long>
929 typedef long long __integral_type;
930 typedef __atomic_base<long long> __base_type;
932 atomic() noexcept = default;
933 ~atomic() noexcept = default;
934 atomic(const atomic&) = delete;
935 atomic& operator=(const atomic&) = delete;
936 atomic& operator=(const atomic&) volatile = delete;
938 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
940 using __base_type::operator __integral_type;
941 using __base_type::operator=;
943#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
944 static constexpr bool is_always_lock_free = ATOMIC_LLONG_LOCK_FREE == 2;
948 /// Explicit specialization for unsigned long long.
950 struct atomic<unsigned long long> : __atomic_base<unsigned long long>
952 typedef unsigned long long __integral_type;
953 typedef __atomic_base<unsigned long long> __base_type;
955 atomic() noexcept = default;
956 ~atomic() noexcept = default;
957 atomic(const atomic&) = delete;
958 atomic& operator=(const atomic&) = delete;
959 atomic& operator=(const atomic&) volatile = delete;
961 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
963 using __base_type::operator __integral_type;
964 using __base_type::operator=;
966#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
967 static constexpr bool is_always_lock_free = ATOMIC_LLONG_LOCK_FREE == 2;
971 /// Explicit specialization for wchar_t.
973 struct atomic<wchar_t> : __atomic_base<wchar_t>
975 typedef wchar_t __integral_type;
976 typedef __atomic_base<wchar_t> __base_type;
978 atomic() noexcept = default;
979 ~atomic() noexcept = default;
980 atomic(const atomic&) = delete;
981 atomic& operator=(const atomic&) = delete;
982 atomic& operator=(const atomic&) volatile = delete;
984 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
986 using __base_type::operator __integral_type;
987 using __base_type::operator=;
989#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
990 static constexpr bool is_always_lock_free = ATOMIC_WCHAR_T_LOCK_FREE == 2;
994#ifdef _GLIBCXX_USE_CHAR8_T
995 /// Explicit specialization for char8_t.
997 struct atomic<char8_t> : __atomic_base<char8_t>
999 typedef char8_t __integral_type;
1000 typedef __atomic_base<char8_t> __base_type;
1002 atomic() noexcept = default;
1003 ~atomic() noexcept = default;
1004 atomic(const atomic&) = delete;
1005 atomic& operator=(const atomic&) = delete;
1006 atomic& operator=(const atomic&) volatile = delete;
1008 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
1010 using __base_type::operator __integral_type;
1011 using __base_type::operator=;
1013#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
1014 static constexpr bool is_always_lock_free
1015 = ATOMIC_CHAR8_T_LOCK_FREE == 2;
1020 /// Explicit specialization for char16_t.
1022 struct atomic<char16_t> : __atomic_base<char16_t>
1024 typedef char16_t __integral_type;
1025 typedef __atomic_base<char16_t> __base_type;
1027 atomic() noexcept = default;
1028 ~atomic() noexcept = default;
1029 atomic(const atomic&) = delete;
1030 atomic& operator=(const atomic&) = delete;
1031 atomic& operator=(const atomic&) volatile = delete;
1033 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
1035 using __base_type::operator __integral_type;
1036 using __base_type::operator=;
1038#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
1039 static constexpr bool is_always_lock_free
1040 = ATOMIC_CHAR16_T_LOCK_FREE == 2;
1044 /// Explicit specialization for char32_t.
1046 struct atomic<char32_t> : __atomic_base<char32_t>
1048 typedef char32_t __integral_type;
1049 typedef __atomic_base<char32_t> __base_type;
1051 atomic() noexcept = default;
1052 ~atomic() noexcept = default;
1053 atomic(const atomic&) = delete;
1054 atomic& operator=(const atomic&) = delete;
1055 atomic& operator=(const atomic&) volatile = delete;
1057 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
1059 using __base_type::operator __integral_type;
1060 using __base_type::operator=;
1062#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
1063 static constexpr bool is_always_lock_free
1064 = ATOMIC_CHAR32_T_LOCK_FREE == 2;
1070 typedef atomic<bool> atomic_bool;
1073 typedef atomic<char> atomic_char;
1076 typedef atomic<signed char> atomic_schar;
1079 typedef atomic<unsigned char> atomic_uchar;
1082 typedef atomic<short> atomic_short;
1085 typedef atomic<unsigned short> atomic_ushort;
1088 typedef atomic<int> atomic_int;
1091 typedef atomic<unsigned int> atomic_uint;
1094 typedef atomic<long> atomic_long;
1097 typedef atomic<unsigned long> atomic_ulong;
1100 typedef atomic<long long> atomic_llong;
1103 typedef atomic<unsigned long long> atomic_ullong;
1106 typedef atomic<wchar_t> atomic_wchar_t;
1108#ifdef _GLIBCXX_USE_CHAR8_T
1110 typedef atomic<char8_t> atomic_char8_t;
1114 typedef atomic<char16_t> atomic_char16_t;
1117 typedef atomic<char32_t> atomic_char32_t;
1119#ifdef _GLIBCXX_USE_C99_STDINT
1120 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1121 // 2441. Exact-width atomic typedefs should be provided
1124 typedef atomic<int8_t> atomic_int8_t;
1127 typedef atomic<uint8_t> atomic_uint8_t;
1130 typedef atomic<int16_t> atomic_int16_t;
1133 typedef atomic<uint16_t> atomic_uint16_t;
1136 typedef atomic<int32_t> atomic_int32_t;
1139 typedef atomic<uint32_t> atomic_uint32_t;
1142 typedef atomic<int64_t> atomic_int64_t;
1145 typedef atomic<uint64_t> atomic_uint64_t;
1148 /// atomic_int_least8_t
1149 typedef atomic<int_least8_t> atomic_int_least8_t;
1151 /// atomic_uint_least8_t
1152 typedef atomic<uint_least8_t> atomic_uint_least8_t;
1154 /// atomic_int_least16_t
1155 typedef atomic<int_least16_t> atomic_int_least16_t;
1157 /// atomic_uint_least16_t
1158 typedef atomic<uint_least16_t> atomic_uint_least16_t;
1160 /// atomic_int_least32_t
1161 typedef atomic<int_least32_t> atomic_int_least32_t;
1163 /// atomic_uint_least32_t
1164 typedef atomic<uint_least32_t> atomic_uint_least32_t;
1166 /// atomic_int_least64_t
1167 typedef atomic<int_least64_t> atomic_int_least64_t;
1169 /// atomic_uint_least64_t
1170 typedef atomic<uint_least64_t> atomic_uint_least64_t;
1173 /// atomic_int_fast8_t
1174 typedef atomic<int_fast8_t> atomic_int_fast8_t;
1176 /// atomic_uint_fast8_t
1177 typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
1179 /// atomic_int_fast16_t
1180 typedef atomic<int_fast16_t> atomic_int_fast16_t;
1182 /// atomic_uint_fast16_t
1183 typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
1185 /// atomic_int_fast32_t
1186 typedef atomic<int_fast32_t> atomic_int_fast32_t;
1188 /// atomic_uint_fast32_t
1189 typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
1191 /// atomic_int_fast64_t
1192 typedef atomic<int_fast64_t> atomic_int_fast64_t;
1194 /// atomic_uint_fast64_t
1195 typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
1199 typedef atomic<intptr_t> atomic_intptr_t;
1201 /// atomic_uintptr_t
1202 typedef atomic<uintptr_t> atomic_uintptr_t;
1205 typedef atomic<size_t> atomic_size_t;
1207 /// atomic_ptrdiff_t
1208 typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
1211 typedef atomic<intmax_t> atomic_intmax_t;
1213 /// atomic_uintmax_t
1214 typedef atomic<uintmax_t> atomic_uintmax_t;
1216 // Function definitions, atomic_flag operations.
1218 atomic_flag_test_and_set_explicit(atomic_flag* __a,
1219 memory_order __m) noexcept
1220 { return __a->test_and_set(__m); }
1223 atomic_flag_test_and_set_explicit(volatile atomic_flag* __a,
1224 memory_order __m) noexcept
1225 { return __a->test_and_set(__m); }
1227#if __cpp_lib_atomic_flag_test
1229 atomic_flag_test(const atomic_flag* __a) noexcept
1230 { return __a->test(); }
1233 atomic_flag_test(const volatile atomic_flag* __a) noexcept
1234 { return __a->test(); }
1237 atomic_flag_test_explicit(const atomic_flag* __a,
1238 memory_order __m) noexcept
1239 { return __a->test(__m); }
1242 atomic_flag_test_explicit(const volatile atomic_flag* __a,
1243 memory_order __m) noexcept
1244 { return __a->test(__m); }
1248 atomic_flag_clear_explicit(atomic_flag* __a, memory_order __m) noexcept
1249 { __a->clear(__m); }
1252 atomic_flag_clear_explicit(volatile atomic_flag* __a,
1253 memory_order __m) noexcept
1254 { __a->clear(__m); }
1257 atomic_flag_test_and_set(atomic_flag* __a) noexcept
1258 { return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
1261 atomic_flag_test_and_set(volatile atomic_flag* __a) noexcept
1262 { return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
1265 atomic_flag_clear(atomic_flag* __a) noexcept
1266 { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
1269 atomic_flag_clear(volatile atomic_flag* __a) noexcept
1270 { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
1272#if __cpp_lib_atomic_wait
1274 atomic_flag_wait(atomic_flag* __a, bool __old) noexcept
1275 { __a->wait(__old); }
1278 atomic_flag_wait_explicit(atomic_flag* __a, bool __old,
1279 memory_order __m) noexcept
1280 { __a->wait(__old, __m); }
1283 atomic_flag_notify_one(atomic_flag* __a) noexcept
1284 { __a->notify_one(); }
1287 atomic_flag_notify_all(atomic_flag* __a) noexcept
1288 { __a->notify_all(); }
1289#endif // __cpp_lib_atomic_wait
1291 /// @cond undocumented
1292 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1293 // 3220. P0558 broke conforming C++14 uses of atomic shared_ptr
1294 template<typename _Tp>
1295 using __atomic_val_t = __type_identity_t<_Tp>;
1296 template<typename _Tp>
1297 using __atomic_diff_t = typename atomic<_Tp>::difference_type;
1300 // [atomics.nonmembers] Non-member functions.
1301 // Function templates generally applicable to atomic types.
1302 template<typename _ITp>
1304 atomic_is_lock_free(const atomic<_ITp>* __a) noexcept
1305 { return __a->is_lock_free(); }
1307 template<typename _ITp>
1309 atomic_is_lock_free(const volatile atomic<_ITp>* __a) noexcept
1310 { return __a->is_lock_free(); }
1312 template<typename _ITp>
1314 atomic_init(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1315 { __a->store(__i, memory_order_relaxed); }
1317 template<typename _ITp>
1319 atomic_init(volatile atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1320 { __a->store(__i, memory_order_relaxed); }
1322 template<typename _ITp>
1324 atomic_store_explicit(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1325 memory_order __m) noexcept
1326 { __a->store(__i, __m); }
1328 template<typename _ITp>
1330 atomic_store_explicit(volatile atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1331 memory_order __m) noexcept
1332 { __a->store(__i, __m); }
1334 template<typename _ITp>
1336 atomic_load_explicit(const atomic<_ITp>* __a, memory_order __m) noexcept
1337 { return __a->load(__m); }
1339 template<typename _ITp>
1341 atomic_load_explicit(const volatile atomic<_ITp>* __a,
1342 memory_order __m) noexcept
1343 { return __a->load(__m); }
1345 template<typename _ITp>
1347 atomic_exchange_explicit(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1348 memory_order __m) noexcept
1349 { return __a->exchange(__i, __m); }
1351 template<typename _ITp>
1353 atomic_exchange_explicit(volatile atomic<_ITp>* __a,
1354 __atomic_val_t<_ITp> __i,
1355 memory_order __m) noexcept
1356 { return __a->exchange(__i, __m); }
1358 template<typename _ITp>
1360 atomic_compare_exchange_weak_explicit(atomic<_ITp>* __a,
1361 __atomic_val_t<_ITp>* __i1,
1362 __atomic_val_t<_ITp> __i2,
1364 memory_order __m2) noexcept
1365 { return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
1367 template<typename _ITp>
1369 atomic_compare_exchange_weak_explicit(volatile atomic<_ITp>* __a,
1370 __atomic_val_t<_ITp>* __i1,
1371 __atomic_val_t<_ITp> __i2,
1373 memory_order __m2) noexcept
1374 { return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
1376 template<typename _ITp>
1378 atomic_compare_exchange_strong_explicit(atomic<_ITp>* __a,
1379 __atomic_val_t<_ITp>* __i1,
1380 __atomic_val_t<_ITp> __i2,
1382 memory_order __m2) noexcept
1383 { return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
1385 template<typename _ITp>
1387 atomic_compare_exchange_strong_explicit(volatile atomic<_ITp>* __a,
1388 __atomic_val_t<_ITp>* __i1,
1389 __atomic_val_t<_ITp> __i2,
1391 memory_order __m2) noexcept
1392 { return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
1395 template<typename _ITp>
1397 atomic_store(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1398 { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
1400 template<typename _ITp>
1402 atomic_store(volatile atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1403 { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
1405 template<typename _ITp>
1407 atomic_load(const atomic<_ITp>* __a) noexcept
1408 { return atomic_load_explicit(__a, memory_order_seq_cst); }
1410 template<typename _ITp>
1412 atomic_load(const volatile atomic<_ITp>* __a) noexcept
1413 { return atomic_load_explicit(__a, memory_order_seq_cst); }
1415 template<typename _ITp>
1417 atomic_exchange(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1418 { return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
1420 template<typename _ITp>
1422 atomic_exchange(volatile atomic<_ITp>* __a,
1423 __atomic_val_t<_ITp> __i) noexcept
1424 { return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
1426 template<typename _ITp>
1428 atomic_compare_exchange_weak(atomic<_ITp>* __a,
1429 __atomic_val_t<_ITp>* __i1,
1430 __atomic_val_t<_ITp> __i2) noexcept
1432 return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
1433 memory_order_seq_cst,
1434 memory_order_seq_cst);
1437 template<typename _ITp>
1439 atomic_compare_exchange_weak(volatile atomic<_ITp>* __a,
1440 __atomic_val_t<_ITp>* __i1,
1441 __atomic_val_t<_ITp> __i2) noexcept
1443 return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
1444 memory_order_seq_cst,
1445 memory_order_seq_cst);
1448 template<typename _ITp>
1450 atomic_compare_exchange_strong(atomic<_ITp>* __a,
1451 __atomic_val_t<_ITp>* __i1,
1452 __atomic_val_t<_ITp> __i2) noexcept
1454 return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
1455 memory_order_seq_cst,
1456 memory_order_seq_cst);
1459 template<typename _ITp>
1461 atomic_compare_exchange_strong(volatile atomic<_ITp>* __a,
1462 __atomic_val_t<_ITp>* __i1,
1463 __atomic_val_t<_ITp> __i2) noexcept
1465 return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
1466 memory_order_seq_cst,
1467 memory_order_seq_cst);
1471#if __cpp_lib_atomic_wait
1472 template<typename _Tp>
1474 atomic_wait(const atomic<_Tp>* __a,
1475 typename std::atomic<_Tp>::value_type __old) noexcept
1476 { __a->wait(__old); }
1478 template<typename _Tp>
1480 atomic_wait_explicit(const atomic<_Tp>* __a,
1481 typename std::atomic<_Tp>::value_type __old,
1482 std::memory_order __m) noexcept
1483 { __a->wait(__old, __m); }
1485 template<typename _Tp>
1487 atomic_notify_one(atomic<_Tp>* __a) noexcept
1488 { __a->notify_one(); }
1490 template<typename _Tp>
1492 atomic_notify_all(atomic<_Tp>* __a) noexcept
1493 { __a->notify_all(); }
1494#endif // __cpp_lib_atomic_wait
1496 // Function templates for atomic_integral and atomic_pointer operations only.
1497 // Some operations (and, or, xor) are only available for atomic integrals,
1498 // which is implemented by taking a parameter of type __atomic_base<_ITp>*.
1500 template<typename _ITp>
1502 atomic_fetch_add_explicit(atomic<_ITp>* __a,
1503 __atomic_diff_t<_ITp> __i,
1504 memory_order __m) noexcept
1505 { return __a->fetch_add(__i, __m); }
1507 template<typename _ITp>
1509 atomic_fetch_add_explicit(volatile atomic<_ITp>* __a,
1510 __atomic_diff_t<_ITp> __i,
1511 memory_order __m) noexcept
1512 { return __a->fetch_add(__i, __m); }
1514 template<typename _ITp>
1516 atomic_fetch_sub_explicit(atomic<_ITp>* __a,
1517 __atomic_diff_t<_ITp> __i,
1518 memory_order __m) noexcept
1519 { return __a->fetch_sub(__i, __m); }
1521 template<typename _ITp>
1523 atomic_fetch_sub_explicit(volatile atomic<_ITp>* __a,
1524 __atomic_diff_t<_ITp> __i,
1525 memory_order __m) noexcept
1526 { return __a->fetch_sub(__i, __m); }
1528 template<typename _ITp>
1530 atomic_fetch_and_explicit(__atomic_base<_ITp>* __a,
1531 __atomic_val_t<_ITp> __i,
1532 memory_order __m) noexcept
1533 { return __a->fetch_and(__i, __m); }
1535 template<typename _ITp>
1537 atomic_fetch_and_explicit(volatile __atomic_base<_ITp>* __a,
1538 __atomic_val_t<_ITp> __i,
1539 memory_order __m) noexcept
1540 { return __a->fetch_and(__i, __m); }
1542 template<typename _ITp>
1544 atomic_fetch_or_explicit(__atomic_base<_ITp>* __a,
1545 __atomic_val_t<_ITp> __i,
1546 memory_order __m) noexcept
1547 { return __a->fetch_or(__i, __m); }
1549 template<typename _ITp>
1551 atomic_fetch_or_explicit(volatile __atomic_base<_ITp>* __a,
1552 __atomic_val_t<_ITp> __i,
1553 memory_order __m) noexcept
1554 { return __a->fetch_or(__i, __m); }
1556 template<typename _ITp>
1558 atomic_fetch_xor_explicit(__atomic_base<_ITp>* __a,
1559 __atomic_val_t<_ITp> __i,
1560 memory_order __m) noexcept
1561 { return __a->fetch_xor(__i, __m); }
1563 template<typename _ITp>
1565 atomic_fetch_xor_explicit(volatile __atomic_base<_ITp>* __a,
1566 __atomic_val_t<_ITp> __i,
1567 memory_order __m) noexcept
1568 { return __a->fetch_xor(__i, __m); }
1570 template<typename _ITp>
1572 atomic_fetch_add(atomic<_ITp>* __a,
1573 __atomic_diff_t<_ITp> __i) noexcept
1574 { return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
1576 template<typename _ITp>
1578 atomic_fetch_add(volatile atomic<_ITp>* __a,
1579 __atomic_diff_t<_ITp> __i) noexcept
1580 { return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
1582 template<typename _ITp>
1584 atomic_fetch_sub(atomic<_ITp>* __a,
1585 __atomic_diff_t<_ITp> __i) noexcept
1586 { return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
1588 template<typename _ITp>
1590 atomic_fetch_sub(volatile atomic<_ITp>* __a,
1591 __atomic_diff_t<_ITp> __i) noexcept
1592 { return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
1594 template<typename _ITp>
1596 atomic_fetch_and(__atomic_base<_ITp>* __a,
1597 __atomic_val_t<_ITp> __i) noexcept
1598 { return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
1600 template<typename _ITp>
1602 atomic_fetch_and(volatile __atomic_base<_ITp>* __a,
1603 __atomic_val_t<_ITp> __i) noexcept
1604 { return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
1606 template<typename _ITp>
1608 atomic_fetch_or(__atomic_base<_ITp>* __a,
1609 __atomic_val_t<_ITp> __i) noexcept
1610 { return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
1612 template<typename _ITp>
1614 atomic_fetch_or(volatile __atomic_base<_ITp>* __a,
1615 __atomic_val_t<_ITp> __i) noexcept
1616 { return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
1618 template<typename _ITp>
1620 atomic_fetch_xor(__atomic_base<_ITp>* __a,
1621 __atomic_val_t<_ITp> __i) noexcept
1622 { return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
1624 template<typename _ITp>
1626 atomic_fetch_xor(volatile __atomic_base<_ITp>* __a,
1627 __atomic_val_t<_ITp> __i) noexcept
1628 { return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
1630#ifdef __cpp_lib_atomic_float
1632 struct atomic<float> : __atomic_float<float>
1634 atomic() noexcept = default;
1637 atomic(float __fp) noexcept : __atomic_float<float>(__fp)
1640 atomic& operator=(const atomic&) volatile = delete;
1641 atomic& operator=(const atomic&) = delete;
1643 using __atomic_float<float>::operator=;
1647 struct atomic<double> : __atomic_float<double>
1649 atomic() noexcept = default;
1652 atomic(double __fp) noexcept : __atomic_float<double>(__fp)
1655 atomic& operator=(const atomic&) volatile = delete;
1656 atomic& operator=(const atomic&) = delete;
1658 using __atomic_float<double>::operator=;
1662 struct atomic<long double> : __atomic_float<long double>
1664 atomic() noexcept = default;
1667 atomic(long double __fp) noexcept : __atomic_float<long double>(__fp)
1670 atomic& operator=(const atomic&) volatile = delete;
1671 atomic& operator=(const atomic&) = delete;
1673 using __atomic_float<long double>::operator=;
1676#ifdef __STDCPP_FLOAT16_T__
1678 struct atomic<_Float16> : __atomic_float<_Float16>
1680 atomic() noexcept = default;
1683 atomic(_Float16 __fp) noexcept : __atomic_float<_Float16>(__fp)
1686 atomic& operator=(const atomic&) volatile = delete;
1687 atomic& operator=(const atomic&) = delete;
1689 using __atomic_float<_Float16>::operator=;
1693#ifdef __STDCPP_FLOAT32_T__
1695 struct atomic<_Float32> : __atomic_float<_Float32>
1697 atomic() noexcept = default;
1700 atomic(_Float32 __fp) noexcept : __atomic_float<_Float32>(__fp)
1703 atomic& operator=(const atomic&) volatile = delete;
1704 atomic& operator=(const atomic&) = delete;
1706 using __atomic_float<_Float32>::operator=;
1710#ifdef __STDCPP_FLOAT64_T__
1712 struct atomic<_Float64> : __atomic_float<_Float64>
1714 atomic() noexcept = default;
1717 atomic(_Float64 __fp) noexcept : __atomic_float<_Float64>(__fp)
1720 atomic& operator=(const atomic&) volatile = delete;
1721 atomic& operator=(const atomic&) = delete;
1723 using __atomic_float<_Float64>::operator=;
1727#ifdef __STDCPP_FLOAT128_T__
1729 struct atomic<_Float128> : __atomic_float<_Float128>
1731 atomic() noexcept = default;
1734 atomic(_Float128 __fp) noexcept : __atomic_float<_Float128>(__fp)
1737 atomic& operator=(const atomic&) volatile = delete;
1738 atomic& operator=(const atomic&) = delete;
1740 using __atomic_float<_Float128>::operator=;
1744#ifdef __STDCPP_BFLOAT16_T__
1746 struct atomic<__gnu_cxx::__bfloat16_t> : __atomic_float<__gnu_cxx::__bfloat16_t>
1748 atomic() noexcept = default;
1751 atomic(__gnu_cxx::__bfloat16_t __fp) noexcept : __atomic_float<__gnu_cxx::__bfloat16_t>(__fp)
1754 atomic& operator=(const atomic&) volatile = delete;
1755 atomic& operator=(const atomic&) = delete;
1757 using __atomic_float<__gnu_cxx::__bfloat16_t>::operator=;
1760#endif // __cpp_lib_atomic_float
1762#ifdef __cpp_lib_atomic_ref
1763 /// Class template to provide atomic operations on a non-atomic variable.
1764 template<typename _Tp>
1765 struct atomic_ref : __atomic_ref<_Tp>
1768 atomic_ref(_Tp& __t) noexcept : __atomic_ref<_Tp>(__t)
1771 atomic_ref& operator=(const atomic_ref&) = delete;
1773 atomic_ref(const atomic_ref&) = default;
1775 using __atomic_ref<_Tp>::operator=;
1777#endif // __cpp_lib_atomic_ref
1779#ifdef __cpp_lib_atomic_lock_free_type_aliases
1780# ifdef _GLIBCXX_HAVE_PLATFORM_WAIT
1781 using atomic_signed_lock_free
1782 = atomic<make_signed_t<__detail::__platform_wait_t>>;
1783 using atomic_unsigned_lock_free
1784 = atomic<make_unsigned_t<__detail::__platform_wait_t>>;
1785# elif ATOMIC_INT_LOCK_FREE == 2
1786 using atomic_signed_lock_free = atomic<signed int>;
1787 using atomic_unsigned_lock_free = atomic<unsigned int>;
1788# elif ATOMIC_LONG_LOCK_FREE == 2
1789 using atomic_signed_lock_free = atomic<signed long>;
1790 using atomic_unsigned_lock_free = atomic<unsigned long>;
1791# elif ATOMIC_CHAR_LOCK_FREE == 2
1792 using atomic_signed_lock_free = atomic<signed char>;
1793 using atomic_unsigned_lock_free = atomic<unsigned char>;
1795# error "libstdc++ bug: no lock-free atomics but they were emitted in <version>"
1799 /// @} group atomics
1801_GLIBCXX_END_NAMESPACE_VERSION
1806#endif // _GLIBCXX_ATOMIC