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 // _GLIBCXX_RESOLVE_LIB_DEFECTS
221 // 4069. std::atomic<volatile T> should be ill-formed
222 static_assert(is_same<_Tp, typename remove_cv<_Tp>::type>::value,
223 "template argument for std::atomic must not be const or volatile");
225#if __cplusplus > 201703L
226 static_assert(is_copy_constructible_v<_Tp>);
227 static_assert(is_move_constructible_v<_Tp>);
228 static_assert(is_copy_assignable_v<_Tp>);
229 static_assert(is_move_assignable_v<_Tp>);
233#if __cpp_lib_atomic_value_initialization
234 // _GLIBCXX_RESOLVE_LIB_DEFECTS
235 // 4169. std::atomic<T>'s default constructor should be constrained
236 constexpr atomic() noexcept(is_nothrow_default_constructible_v<_Tp>)
237 requires is_default_constructible_v<_Tp>
244 ~atomic() noexcept = default;
245 atomic(const atomic&) = delete;
246 atomic& operator=(const atomic&) = delete;
247 atomic& operator=(const atomic&) volatile = delete;
249 constexpr atomic(_Tp __i) noexcept : _M_i(__i)
251#if __cplusplus >= 201402L && __has_builtin(__builtin_clear_padding)
252 if _GLIBCXX17_CONSTEXPR (__atomic_impl::__maybe_has_padding<_Tp>())
253 __builtin_clear_padding(std::__addressof(_M_i));
257 operator _Tp() const noexcept
260 operator _Tp() const volatile noexcept
264 operator=(_Tp __i) noexcept
265 { store(__i); return __i; }
268 operator=(_Tp __i) volatile noexcept
269 { store(__i); return __i; }
272 is_lock_free() const noexcept
274 // Produce a fake, minimally aligned pointer.
275 return __atomic_is_lock_free(sizeof(_M_i),
276 reinterpret_cast<void *>(-_S_alignment));
280 is_lock_free() const volatile noexcept
282 // Produce a fake, minimally aligned pointer.
283 return __atomic_is_lock_free(sizeof(_M_i),
284 reinterpret_cast<void *>(-_S_alignment));
287#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
288 static constexpr bool is_always_lock_free
289 = __atomic_always_lock_free(sizeof(_M_i), 0);
293 store(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept
295 __atomic_store(std::__addressof(_M_i),
296 __atomic_impl::__clear_padding(__i),
301 store(_Tp __i, memory_order __m = memory_order_seq_cst) volatile noexcept
303 __atomic_store(std::__addressof(_M_i),
304 __atomic_impl::__clear_padding(__i),
309 load(memory_order __m = memory_order_seq_cst) const noexcept
311 alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
312 _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
313 __atomic_load(std::__addressof(_M_i), __ptr, int(__m));
318 load(memory_order __m = memory_order_seq_cst) const volatile noexcept
320 alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
321 _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
322 __atomic_load(std::__addressof(_M_i), __ptr, int(__m));
327 exchange(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept
329 alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
330 _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
331 __atomic_exchange(std::__addressof(_M_i),
332 __atomic_impl::__clear_padding(__i),
339 memory_order __m = memory_order_seq_cst) volatile noexcept
341 alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
342 _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
343 __atomic_exchange(std::__addressof(_M_i),
344 __atomic_impl::__clear_padding(__i),
350 compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s,
351 memory_order __f) noexcept
353 return __atomic_impl::__compare_exchange(_M_i, __e, __i, true,
358 compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s,
359 memory_order __f) volatile noexcept
361 return __atomic_impl::__compare_exchange(_M_i, __e, __i, true,
366 compare_exchange_weak(_Tp& __e, _Tp __i,
367 memory_order __m = memory_order_seq_cst) noexcept
368 { return compare_exchange_weak(__e, __i, __m,
369 __cmpexch_failure_order(__m)); }
372 compare_exchange_weak(_Tp& __e, _Tp __i,
373 memory_order __m = memory_order_seq_cst) volatile noexcept
374 { return compare_exchange_weak(__e, __i, __m,
375 __cmpexch_failure_order(__m)); }
378 compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s,
379 memory_order __f) noexcept
381 return __atomic_impl::__compare_exchange(_M_i, __e, __i, false,
386 compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s,
387 memory_order __f) volatile noexcept
389 return __atomic_impl::__compare_exchange(_M_i, __e, __i, false,
394 compare_exchange_strong(_Tp& __e, _Tp __i,
395 memory_order __m = memory_order_seq_cst) noexcept
396 { return compare_exchange_strong(__e, __i, __m,
397 __cmpexch_failure_order(__m)); }
400 compare_exchange_strong(_Tp& __e, _Tp __i,
401 memory_order __m = memory_order_seq_cst) volatile noexcept
402 { return compare_exchange_strong(__e, __i, __m,
403 __cmpexch_failure_order(__m)); }
405#if __cpp_lib_atomic_wait // C++ >= 20
407 wait(_Tp __old, memory_order __m = memory_order_seq_cst) const noexcept
409 std::__atomic_wait_address_v(&_M_i, __old,
410 [__m, this] { return this->load(__m); });
413 // TODO add const volatile overload
416 notify_one() noexcept
417 { std::__atomic_notify_address(&_M_i, false); }
420 notify_all() noexcept
421 { std::__atomic_notify_address(&_M_i, true); }
422#endif // __cpp_lib_atomic_wait
426 /// Partial specialization for pointer types.
427 template<typename _Tp>
430 using value_type = _Tp*;
431 using difference_type = ptrdiff_t;
433 typedef _Tp* __pointer_type;
434 typedef __atomic_base<_Tp*> __base_type;
437 atomic() noexcept = default;
438 ~atomic() noexcept = default;
439 atomic(const atomic&) = delete;
440 atomic& operator=(const atomic&) = delete;
441 atomic& operator=(const atomic&) volatile = delete;
443 constexpr atomic(__pointer_type __p) noexcept : _M_b(__p) { }
445 operator __pointer_type() const noexcept
446 { return __pointer_type(_M_b); }
448 operator __pointer_type() const volatile noexcept
449 { return __pointer_type(_M_b); }
452 operator=(__pointer_type __p) noexcept
453 { return _M_b.operator=(__p); }
456 operator=(__pointer_type __p) volatile noexcept
457 { return _M_b.operator=(__p); }
460 operator++(int) noexcept
462#if __cplusplus >= 201703L
463 static_assert( is_object_v<_Tp>, "pointer to object type" );
469 operator++(int) volatile noexcept
471#if __cplusplus >= 201703L
472 static_assert( is_object_v<_Tp>, "pointer to object type" );
478 operator--(int) noexcept
480#if __cplusplus >= 201703L
481 static_assert( is_object_v<_Tp>, "pointer to object type" );
487 operator--(int) volatile noexcept
489#if __cplusplus >= 201703L
490 static_assert( is_object_v<_Tp>, "pointer to object type" );
496 operator++() noexcept
498#if __cplusplus >= 201703L
499 static_assert( is_object_v<_Tp>, "pointer to object type" );
505 operator++() volatile noexcept
507#if __cplusplus >= 201703L
508 static_assert( is_object_v<_Tp>, "pointer to object type" );
514 operator--() noexcept
516#if __cplusplus >= 201703L
517 static_assert( is_object_v<_Tp>, "pointer to object type" );
523 operator--() volatile noexcept
525#if __cplusplus >= 201703L
526 static_assert( is_object_v<_Tp>, "pointer to object type" );
532 operator+=(ptrdiff_t __d) noexcept
534#if __cplusplus >= 201703L
535 static_assert( is_object_v<_Tp>, "pointer to object type" );
537 return _M_b.operator+=(__d);
541 operator+=(ptrdiff_t __d) volatile noexcept
543#if __cplusplus >= 201703L
544 static_assert( is_object_v<_Tp>, "pointer to object type" );
546 return _M_b.operator+=(__d);
550 operator-=(ptrdiff_t __d) noexcept
552#if __cplusplus >= 201703L
553 static_assert( is_object_v<_Tp>, "pointer to object type" );
555 return _M_b.operator-=(__d);
559 operator-=(ptrdiff_t __d) volatile noexcept
561#if __cplusplus >= 201703L
562 static_assert( is_object_v<_Tp>, "pointer to object type" );
564 return _M_b.operator-=(__d);
568 is_lock_free() const noexcept
569 { return _M_b.is_lock_free(); }
572 is_lock_free() const volatile noexcept
573 { return _M_b.is_lock_free(); }
575#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
576 static constexpr bool is_always_lock_free
577 = ATOMIC_POINTER_LOCK_FREE == 2;
581 store(__pointer_type __p,
582 memory_order __m = memory_order_seq_cst) noexcept
583 { return _M_b.store(__p, __m); }
586 store(__pointer_type __p,
587 memory_order __m = memory_order_seq_cst) volatile noexcept
588 { return _M_b.store(__p, __m); }
591 load(memory_order __m = memory_order_seq_cst) const noexcept
592 { return _M_b.load(__m); }
595 load(memory_order __m = memory_order_seq_cst) const volatile noexcept
596 { return _M_b.load(__m); }
599 exchange(__pointer_type __p,
600 memory_order __m = memory_order_seq_cst) noexcept
601 { return _M_b.exchange(__p, __m); }
604 exchange(__pointer_type __p,
605 memory_order __m = memory_order_seq_cst) volatile noexcept
606 { return _M_b.exchange(__p, __m); }
609 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
610 memory_order __m1, memory_order __m2) noexcept
611 { return _M_b.compare_exchange_weak(__p1, __p2, __m1, __m2); }
614 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
616 memory_order __m2) volatile noexcept
617 { return _M_b.compare_exchange_weak(__p1, __p2, __m1, __m2); }
620 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
621 memory_order __m = memory_order_seq_cst) noexcept
623 return compare_exchange_weak(__p1, __p2, __m,
624 __cmpexch_failure_order(__m));
628 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
629 memory_order __m = memory_order_seq_cst) volatile noexcept
631 return compare_exchange_weak(__p1, __p2, __m,
632 __cmpexch_failure_order(__m));
636 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
637 memory_order __m1, memory_order __m2) noexcept
638 { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
641 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
643 memory_order __m2) volatile noexcept
644 { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
647 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
648 memory_order __m = memory_order_seq_cst) noexcept
650 return _M_b.compare_exchange_strong(__p1, __p2, __m,
651 __cmpexch_failure_order(__m));
655 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
656 memory_order __m = memory_order_seq_cst) volatile noexcept
658 return _M_b.compare_exchange_strong(__p1, __p2, __m,
659 __cmpexch_failure_order(__m));
662#if __cpp_lib_atomic_wait
664 wait(__pointer_type __old, memory_order __m = memory_order_seq_cst) const noexcept
665 { _M_b.wait(__old, __m); }
667 // TODO add const volatile overload
670 notify_one() noexcept
671 { _M_b.notify_one(); }
674 notify_all() noexcept
675 { _M_b.notify_all(); }
676#endif // __cpp_lib_atomic_wait
679 fetch_add(ptrdiff_t __d,
680 memory_order __m = memory_order_seq_cst) noexcept
682#if __cplusplus >= 201703L
683 static_assert( is_object_v<_Tp>, "pointer to object type" );
685 return _M_b.fetch_add(__d, __m);
689 fetch_add(ptrdiff_t __d,
690 memory_order __m = memory_order_seq_cst) volatile noexcept
692#if __cplusplus >= 201703L
693 static_assert( is_object_v<_Tp>, "pointer to object type" );
695 return _M_b.fetch_add(__d, __m);
699 fetch_sub(ptrdiff_t __d,
700 memory_order __m = memory_order_seq_cst) noexcept
702#if __cplusplus >= 201703L
703 static_assert( is_object_v<_Tp>, "pointer to object type" );
705 return _M_b.fetch_sub(__d, __m);
709 fetch_sub(ptrdiff_t __d,
710 memory_order __m = memory_order_seq_cst) volatile noexcept
712#if __cplusplus >= 201703L
713 static_assert( is_object_v<_Tp>, "pointer to object type" );
715 return _M_b.fetch_sub(__d, __m);
720 /// Explicit specialization for char.
722 struct atomic<char> : __atomic_base<char>
724 typedef char __integral_type;
725 typedef __atomic_base<char> __base_type;
727 atomic() noexcept = default;
728 ~atomic() noexcept = default;
729 atomic(const atomic&) = delete;
730 atomic& operator=(const atomic&) = delete;
731 atomic& operator=(const atomic&) volatile = delete;
733 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
735 using __base_type::operator __integral_type;
736 using __base_type::operator=;
738#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
739 static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
743 /// Explicit specialization for signed char.
745 struct atomic<signed char> : __atomic_base<signed char>
747 typedef signed char __integral_type;
748 typedef __atomic_base<signed char> __base_type;
750 atomic() noexcept= default;
751 ~atomic() noexcept = default;
752 atomic(const atomic&) = delete;
753 atomic& operator=(const atomic&) = delete;
754 atomic& operator=(const atomic&) volatile = delete;
756 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
758 using __base_type::operator __integral_type;
759 using __base_type::operator=;
761#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
762 static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
766 /// Explicit specialization for unsigned char.
768 struct atomic<unsigned char> : __atomic_base<unsigned char>
770 typedef unsigned char __integral_type;
771 typedef __atomic_base<unsigned char> __base_type;
773 atomic() noexcept= default;
774 ~atomic() noexcept = default;
775 atomic(const atomic&) = delete;
776 atomic& operator=(const atomic&) = delete;
777 atomic& operator=(const atomic&) volatile = delete;
779 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
781 using __base_type::operator __integral_type;
782 using __base_type::operator=;
784#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
785 static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
789 /// Explicit specialization for short.
791 struct atomic<short> : __atomic_base<short>
793 typedef short __integral_type;
794 typedef __atomic_base<short> __base_type;
796 atomic() noexcept = default;
797 ~atomic() noexcept = default;
798 atomic(const atomic&) = delete;
799 atomic& operator=(const atomic&) = delete;
800 atomic& operator=(const atomic&) volatile = delete;
802 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
804 using __base_type::operator __integral_type;
805 using __base_type::operator=;
807#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
808 static constexpr bool is_always_lock_free = ATOMIC_SHORT_LOCK_FREE == 2;
812 /// Explicit specialization for unsigned short.
814 struct atomic<unsigned short> : __atomic_base<unsigned short>
816 typedef unsigned short __integral_type;
817 typedef __atomic_base<unsigned short> __base_type;
819 atomic() noexcept = default;
820 ~atomic() noexcept = default;
821 atomic(const atomic&) = delete;
822 atomic& operator=(const atomic&) = delete;
823 atomic& operator=(const atomic&) volatile = delete;
825 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
827 using __base_type::operator __integral_type;
828 using __base_type::operator=;
830#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
831 static constexpr bool is_always_lock_free = ATOMIC_SHORT_LOCK_FREE == 2;
835 /// Explicit specialization for int.
837 struct atomic<int> : __atomic_base<int>
839 typedef int __integral_type;
840 typedef __atomic_base<int> __base_type;
842 atomic() noexcept = default;
843 ~atomic() noexcept = default;
844 atomic(const atomic&) = delete;
845 atomic& operator=(const atomic&) = delete;
846 atomic& operator=(const atomic&) volatile = delete;
848 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
850 using __base_type::operator __integral_type;
851 using __base_type::operator=;
853#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
854 static constexpr bool is_always_lock_free = ATOMIC_INT_LOCK_FREE == 2;
858 /// Explicit specialization for unsigned int.
860 struct atomic<unsigned int> : __atomic_base<unsigned int>
862 typedef unsigned int __integral_type;
863 typedef __atomic_base<unsigned int> __base_type;
865 atomic() noexcept = default;
866 ~atomic() noexcept = default;
867 atomic(const atomic&) = delete;
868 atomic& operator=(const atomic&) = delete;
869 atomic& operator=(const atomic&) volatile = delete;
871 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
873 using __base_type::operator __integral_type;
874 using __base_type::operator=;
876#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
877 static constexpr bool is_always_lock_free = ATOMIC_INT_LOCK_FREE == 2;
881 /// Explicit specialization for long.
883 struct atomic<long> : __atomic_base<long>
885 typedef long __integral_type;
886 typedef __atomic_base<long> __base_type;
888 atomic() noexcept = default;
889 ~atomic() noexcept = default;
890 atomic(const atomic&) = delete;
891 atomic& operator=(const atomic&) = delete;
892 atomic& operator=(const atomic&) volatile = delete;
894 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
896 using __base_type::operator __integral_type;
897 using __base_type::operator=;
899#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
900 static constexpr bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2;
904 /// Explicit specialization for unsigned long.
906 struct atomic<unsigned long> : __atomic_base<unsigned long>
908 typedef unsigned long __integral_type;
909 typedef __atomic_base<unsigned long> __base_type;
911 atomic() noexcept = default;
912 ~atomic() noexcept = default;
913 atomic(const atomic&) = delete;
914 atomic& operator=(const atomic&) = delete;
915 atomic& operator=(const atomic&) volatile = delete;
917 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
919 using __base_type::operator __integral_type;
920 using __base_type::operator=;
922#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
923 static constexpr bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2;
927 /// Explicit specialization for long long.
929 struct atomic<long long> : __atomic_base<long long>
931 typedef long long __integral_type;
932 typedef __atomic_base<long long> __base_type;
934 atomic() noexcept = default;
935 ~atomic() noexcept = default;
936 atomic(const atomic&) = delete;
937 atomic& operator=(const atomic&) = delete;
938 atomic& operator=(const atomic&) volatile = delete;
940 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
942 using __base_type::operator __integral_type;
943 using __base_type::operator=;
945#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
946 static constexpr bool is_always_lock_free = ATOMIC_LLONG_LOCK_FREE == 2;
950 /// Explicit specialization for unsigned long long.
952 struct atomic<unsigned long long> : __atomic_base<unsigned long long>
954 typedef unsigned long long __integral_type;
955 typedef __atomic_base<unsigned long long> __base_type;
957 atomic() noexcept = default;
958 ~atomic() noexcept = default;
959 atomic(const atomic&) = delete;
960 atomic& operator=(const atomic&) = delete;
961 atomic& operator=(const atomic&) volatile = delete;
963 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
965 using __base_type::operator __integral_type;
966 using __base_type::operator=;
968#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
969 static constexpr bool is_always_lock_free = ATOMIC_LLONG_LOCK_FREE == 2;
973 /// Explicit specialization for wchar_t.
975 struct atomic<wchar_t> : __atomic_base<wchar_t>
977 typedef wchar_t __integral_type;
978 typedef __atomic_base<wchar_t> __base_type;
980 atomic() noexcept = default;
981 ~atomic() noexcept = default;
982 atomic(const atomic&) = delete;
983 atomic& operator=(const atomic&) = delete;
984 atomic& operator=(const atomic&) volatile = delete;
986 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
988 using __base_type::operator __integral_type;
989 using __base_type::operator=;
991#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
992 static constexpr bool is_always_lock_free = ATOMIC_WCHAR_T_LOCK_FREE == 2;
996#ifdef _GLIBCXX_USE_CHAR8_T
997 /// Explicit specialization for char8_t.
999 struct atomic<char8_t> : __atomic_base<char8_t>
1001 typedef char8_t __integral_type;
1002 typedef __atomic_base<char8_t> __base_type;
1004 atomic() noexcept = default;
1005 ~atomic() noexcept = default;
1006 atomic(const atomic&) = delete;
1007 atomic& operator=(const atomic&) = delete;
1008 atomic& operator=(const atomic&) volatile = delete;
1010 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
1012 using __base_type::operator __integral_type;
1013 using __base_type::operator=;
1015#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
1016 static constexpr bool is_always_lock_free
1017 = ATOMIC_CHAR8_T_LOCK_FREE == 2;
1022 /// Explicit specialization for char16_t.
1024 struct atomic<char16_t> : __atomic_base<char16_t>
1026 typedef char16_t __integral_type;
1027 typedef __atomic_base<char16_t> __base_type;
1029 atomic() noexcept = default;
1030 ~atomic() noexcept = default;
1031 atomic(const atomic&) = delete;
1032 atomic& operator=(const atomic&) = delete;
1033 atomic& operator=(const atomic&) volatile = delete;
1035 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
1037 using __base_type::operator __integral_type;
1038 using __base_type::operator=;
1040#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
1041 static constexpr bool is_always_lock_free
1042 = ATOMIC_CHAR16_T_LOCK_FREE == 2;
1046 /// Explicit specialization for char32_t.
1048 struct atomic<char32_t> : __atomic_base<char32_t>
1050 typedef char32_t __integral_type;
1051 typedef __atomic_base<char32_t> __base_type;
1053 atomic() noexcept = default;
1054 ~atomic() noexcept = default;
1055 atomic(const atomic&) = delete;
1056 atomic& operator=(const atomic&) = delete;
1057 atomic& operator=(const atomic&) volatile = delete;
1059 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
1061 using __base_type::operator __integral_type;
1062 using __base_type::operator=;
1064#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
1065 static constexpr bool is_always_lock_free
1066 = ATOMIC_CHAR32_T_LOCK_FREE == 2;
1072 typedef atomic<bool> atomic_bool;
1075 typedef atomic<char> atomic_char;
1078 typedef atomic<signed char> atomic_schar;
1081 typedef atomic<unsigned char> atomic_uchar;
1084 typedef atomic<short> atomic_short;
1087 typedef atomic<unsigned short> atomic_ushort;
1090 typedef atomic<int> atomic_int;
1093 typedef atomic<unsigned int> atomic_uint;
1096 typedef atomic<long> atomic_long;
1099 typedef atomic<unsigned long> atomic_ulong;
1102 typedef atomic<long long> atomic_llong;
1105 typedef atomic<unsigned long long> atomic_ullong;
1108 typedef atomic<wchar_t> atomic_wchar_t;
1110#ifdef _GLIBCXX_USE_CHAR8_T
1112 typedef atomic<char8_t> atomic_char8_t;
1116 typedef atomic<char16_t> atomic_char16_t;
1119 typedef atomic<char32_t> atomic_char32_t;
1121#ifdef _GLIBCXX_USE_C99_STDINT
1122 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1123 // 2441. Exact-width atomic typedefs should be provided
1126 typedef atomic<int8_t> atomic_int8_t;
1129 typedef atomic<uint8_t> atomic_uint8_t;
1132 typedef atomic<int16_t> atomic_int16_t;
1135 typedef atomic<uint16_t> atomic_uint16_t;
1138 typedef atomic<int32_t> atomic_int32_t;
1141 typedef atomic<uint32_t> atomic_uint32_t;
1144 typedef atomic<int64_t> atomic_int64_t;
1147 typedef atomic<uint64_t> atomic_uint64_t;
1150 /// atomic_int_least8_t
1151 typedef atomic<int_least8_t> atomic_int_least8_t;
1153 /// atomic_uint_least8_t
1154 typedef atomic<uint_least8_t> atomic_uint_least8_t;
1156 /// atomic_int_least16_t
1157 typedef atomic<int_least16_t> atomic_int_least16_t;
1159 /// atomic_uint_least16_t
1160 typedef atomic<uint_least16_t> atomic_uint_least16_t;
1162 /// atomic_int_least32_t
1163 typedef atomic<int_least32_t> atomic_int_least32_t;
1165 /// atomic_uint_least32_t
1166 typedef atomic<uint_least32_t> atomic_uint_least32_t;
1168 /// atomic_int_least64_t
1169 typedef atomic<int_least64_t> atomic_int_least64_t;
1171 /// atomic_uint_least64_t
1172 typedef atomic<uint_least64_t> atomic_uint_least64_t;
1175 /// atomic_int_fast8_t
1176 typedef atomic<int_fast8_t> atomic_int_fast8_t;
1178 /// atomic_uint_fast8_t
1179 typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
1181 /// atomic_int_fast16_t
1182 typedef atomic<int_fast16_t> atomic_int_fast16_t;
1184 /// atomic_uint_fast16_t
1185 typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
1187 /// atomic_int_fast32_t
1188 typedef atomic<int_fast32_t> atomic_int_fast32_t;
1190 /// atomic_uint_fast32_t
1191 typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
1193 /// atomic_int_fast64_t
1194 typedef atomic<int_fast64_t> atomic_int_fast64_t;
1196 /// atomic_uint_fast64_t
1197 typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
1201 typedef atomic<intptr_t> atomic_intptr_t;
1203 /// atomic_uintptr_t
1204 typedef atomic<uintptr_t> atomic_uintptr_t;
1207 typedef atomic<size_t> atomic_size_t;
1209 /// atomic_ptrdiff_t
1210 typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
1213 typedef atomic<intmax_t> atomic_intmax_t;
1215 /// atomic_uintmax_t
1216 typedef atomic<uintmax_t> atomic_uintmax_t;
1218 // Function definitions, atomic_flag operations.
1220 atomic_flag_test_and_set_explicit(atomic_flag* __a,
1221 memory_order __m) noexcept
1222 { return __a->test_and_set(__m); }
1225 atomic_flag_test_and_set_explicit(volatile atomic_flag* __a,
1226 memory_order __m) noexcept
1227 { return __a->test_and_set(__m); }
1229#if __cpp_lib_atomic_flag_test
1231 atomic_flag_test(const atomic_flag* __a) noexcept
1232 { return __a->test(); }
1235 atomic_flag_test(const volatile atomic_flag* __a) noexcept
1236 { return __a->test(); }
1239 atomic_flag_test_explicit(const atomic_flag* __a,
1240 memory_order __m) noexcept
1241 { return __a->test(__m); }
1244 atomic_flag_test_explicit(const volatile atomic_flag* __a,
1245 memory_order __m) noexcept
1246 { return __a->test(__m); }
1250 atomic_flag_clear_explicit(atomic_flag* __a, memory_order __m) noexcept
1251 { __a->clear(__m); }
1254 atomic_flag_clear_explicit(volatile atomic_flag* __a,
1255 memory_order __m) noexcept
1256 { __a->clear(__m); }
1259 atomic_flag_test_and_set(atomic_flag* __a) noexcept
1260 { return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
1263 atomic_flag_test_and_set(volatile atomic_flag* __a) noexcept
1264 { return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
1267 atomic_flag_clear(atomic_flag* __a) noexcept
1268 { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
1271 atomic_flag_clear(volatile atomic_flag* __a) noexcept
1272 { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
1274#if __cpp_lib_atomic_wait
1276 atomic_flag_wait(atomic_flag* __a, bool __old) noexcept
1277 { __a->wait(__old); }
1280 atomic_flag_wait_explicit(atomic_flag* __a, bool __old,
1281 memory_order __m) noexcept
1282 { __a->wait(__old, __m); }
1285 atomic_flag_notify_one(atomic_flag* __a) noexcept
1286 { __a->notify_one(); }
1289 atomic_flag_notify_all(atomic_flag* __a) noexcept
1290 { __a->notify_all(); }
1291#endif // __cpp_lib_atomic_wait
1293 /// @cond undocumented
1294 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1295 // 3220. P0558 broke conforming C++14 uses of atomic shared_ptr
1296 template<typename _Tp>
1297 using __atomic_val_t = __type_identity_t<_Tp>;
1298 template<typename _Tp>
1299 using __atomic_diff_t = typename atomic<_Tp>::difference_type;
1302 // [atomics.nonmembers] Non-member functions.
1303 // Function templates generally applicable to atomic types.
1304 template<typename _ITp>
1306 atomic_is_lock_free(const atomic<_ITp>* __a) noexcept
1307 { return __a->is_lock_free(); }
1309 template<typename _ITp>
1311 atomic_is_lock_free(const volatile atomic<_ITp>* __a) noexcept
1312 { return __a->is_lock_free(); }
1314 template<typename _ITp>
1316 atomic_init(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1317 { __a->store(__i, memory_order_relaxed); }
1319 template<typename _ITp>
1321 atomic_init(volatile atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1322 { __a->store(__i, memory_order_relaxed); }
1324 template<typename _ITp>
1326 atomic_store_explicit(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1327 memory_order __m) noexcept
1328 { __a->store(__i, __m); }
1330 template<typename _ITp>
1332 atomic_store_explicit(volatile atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1333 memory_order __m) noexcept
1334 { __a->store(__i, __m); }
1336 template<typename _ITp>
1338 atomic_load_explicit(const atomic<_ITp>* __a, memory_order __m) noexcept
1339 { return __a->load(__m); }
1341 template<typename _ITp>
1343 atomic_load_explicit(const volatile atomic<_ITp>* __a,
1344 memory_order __m) noexcept
1345 { return __a->load(__m); }
1347 template<typename _ITp>
1349 atomic_exchange_explicit(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1350 memory_order __m) noexcept
1351 { return __a->exchange(__i, __m); }
1353 template<typename _ITp>
1355 atomic_exchange_explicit(volatile atomic<_ITp>* __a,
1356 __atomic_val_t<_ITp> __i,
1357 memory_order __m) noexcept
1358 { return __a->exchange(__i, __m); }
1360 template<typename _ITp>
1362 atomic_compare_exchange_weak_explicit(atomic<_ITp>* __a,
1363 __atomic_val_t<_ITp>* __i1,
1364 __atomic_val_t<_ITp> __i2,
1366 memory_order __m2) noexcept
1367 { return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
1369 template<typename _ITp>
1371 atomic_compare_exchange_weak_explicit(volatile atomic<_ITp>* __a,
1372 __atomic_val_t<_ITp>* __i1,
1373 __atomic_val_t<_ITp> __i2,
1375 memory_order __m2) noexcept
1376 { return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
1378 template<typename _ITp>
1380 atomic_compare_exchange_strong_explicit(atomic<_ITp>* __a,
1381 __atomic_val_t<_ITp>* __i1,
1382 __atomic_val_t<_ITp> __i2,
1384 memory_order __m2) noexcept
1385 { return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
1387 template<typename _ITp>
1389 atomic_compare_exchange_strong_explicit(volatile 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_strong(*__i1, __i2, __m1, __m2); }
1397 template<typename _ITp>
1399 atomic_store(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1400 { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
1402 template<typename _ITp>
1404 atomic_store(volatile atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1405 { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
1407 template<typename _ITp>
1409 atomic_load(const atomic<_ITp>* __a) noexcept
1410 { return atomic_load_explicit(__a, memory_order_seq_cst); }
1412 template<typename _ITp>
1414 atomic_load(const volatile atomic<_ITp>* __a) noexcept
1415 { return atomic_load_explicit(__a, memory_order_seq_cst); }
1417 template<typename _ITp>
1419 atomic_exchange(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1420 { return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
1422 template<typename _ITp>
1424 atomic_exchange(volatile atomic<_ITp>* __a,
1425 __atomic_val_t<_ITp> __i) noexcept
1426 { return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
1428 template<typename _ITp>
1430 atomic_compare_exchange_weak(atomic<_ITp>* __a,
1431 __atomic_val_t<_ITp>* __i1,
1432 __atomic_val_t<_ITp> __i2) noexcept
1434 return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
1435 memory_order_seq_cst,
1436 memory_order_seq_cst);
1439 template<typename _ITp>
1441 atomic_compare_exchange_weak(volatile atomic<_ITp>* __a,
1442 __atomic_val_t<_ITp>* __i1,
1443 __atomic_val_t<_ITp> __i2) noexcept
1445 return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
1446 memory_order_seq_cst,
1447 memory_order_seq_cst);
1450 template<typename _ITp>
1452 atomic_compare_exchange_strong(atomic<_ITp>* __a,
1453 __atomic_val_t<_ITp>* __i1,
1454 __atomic_val_t<_ITp> __i2) noexcept
1456 return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
1457 memory_order_seq_cst,
1458 memory_order_seq_cst);
1461 template<typename _ITp>
1463 atomic_compare_exchange_strong(volatile atomic<_ITp>* __a,
1464 __atomic_val_t<_ITp>* __i1,
1465 __atomic_val_t<_ITp> __i2) noexcept
1467 return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
1468 memory_order_seq_cst,
1469 memory_order_seq_cst);
1473#if __cpp_lib_atomic_wait
1474 template<typename _Tp>
1476 atomic_wait(const atomic<_Tp>* __a,
1477 typename std::atomic<_Tp>::value_type __old) noexcept
1478 { __a->wait(__old); }
1480 template<typename _Tp>
1482 atomic_wait_explicit(const atomic<_Tp>* __a,
1483 typename std::atomic<_Tp>::value_type __old,
1484 std::memory_order __m) noexcept
1485 { __a->wait(__old, __m); }
1487 template<typename _Tp>
1489 atomic_notify_one(atomic<_Tp>* __a) noexcept
1490 { __a->notify_one(); }
1492 template<typename _Tp>
1494 atomic_notify_all(atomic<_Tp>* __a) noexcept
1495 { __a->notify_all(); }
1496#endif // __cpp_lib_atomic_wait
1498 // Function templates for atomic_integral and atomic_pointer operations only.
1499 // Some operations (and, or, xor) are only available for atomic integrals,
1500 // which is implemented by taking a parameter of type __atomic_base<_ITp>*.
1502 template<typename _ITp>
1504 atomic_fetch_add_explicit(atomic<_ITp>* __a,
1505 __atomic_diff_t<_ITp> __i,
1506 memory_order __m) noexcept
1507 { return __a->fetch_add(__i, __m); }
1509 template<typename _ITp>
1511 atomic_fetch_add_explicit(volatile atomic<_ITp>* __a,
1512 __atomic_diff_t<_ITp> __i,
1513 memory_order __m) noexcept
1514 { return __a->fetch_add(__i, __m); }
1516 template<typename _ITp>
1518 atomic_fetch_sub_explicit(atomic<_ITp>* __a,
1519 __atomic_diff_t<_ITp> __i,
1520 memory_order __m) noexcept
1521 { return __a->fetch_sub(__i, __m); }
1523 template<typename _ITp>
1525 atomic_fetch_sub_explicit(volatile atomic<_ITp>* __a,
1526 __atomic_diff_t<_ITp> __i,
1527 memory_order __m) noexcept
1528 { return __a->fetch_sub(__i, __m); }
1530 template<typename _ITp>
1532 atomic_fetch_and_explicit(__atomic_base<_ITp>* __a,
1533 __atomic_val_t<_ITp> __i,
1534 memory_order __m) noexcept
1535 { return __a->fetch_and(__i, __m); }
1537 template<typename _ITp>
1539 atomic_fetch_and_explicit(volatile __atomic_base<_ITp>* __a,
1540 __atomic_val_t<_ITp> __i,
1541 memory_order __m) noexcept
1542 { return __a->fetch_and(__i, __m); }
1544 template<typename _ITp>
1546 atomic_fetch_or_explicit(__atomic_base<_ITp>* __a,
1547 __atomic_val_t<_ITp> __i,
1548 memory_order __m) noexcept
1549 { return __a->fetch_or(__i, __m); }
1551 template<typename _ITp>
1553 atomic_fetch_or_explicit(volatile __atomic_base<_ITp>* __a,
1554 __atomic_val_t<_ITp> __i,
1555 memory_order __m) noexcept
1556 { return __a->fetch_or(__i, __m); }
1558 template<typename _ITp>
1560 atomic_fetch_xor_explicit(__atomic_base<_ITp>* __a,
1561 __atomic_val_t<_ITp> __i,
1562 memory_order __m) noexcept
1563 { return __a->fetch_xor(__i, __m); }
1565 template<typename _ITp>
1567 atomic_fetch_xor_explicit(volatile __atomic_base<_ITp>* __a,
1568 __atomic_val_t<_ITp> __i,
1569 memory_order __m) noexcept
1570 { return __a->fetch_xor(__i, __m); }
1572 template<typename _ITp>
1574 atomic_fetch_add(atomic<_ITp>* __a,
1575 __atomic_diff_t<_ITp> __i) noexcept
1576 { return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
1578 template<typename _ITp>
1580 atomic_fetch_add(volatile atomic<_ITp>* __a,
1581 __atomic_diff_t<_ITp> __i) noexcept
1582 { return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
1584 template<typename _ITp>
1586 atomic_fetch_sub(atomic<_ITp>* __a,
1587 __atomic_diff_t<_ITp> __i) noexcept
1588 { return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
1590 template<typename _ITp>
1592 atomic_fetch_sub(volatile atomic<_ITp>* __a,
1593 __atomic_diff_t<_ITp> __i) noexcept
1594 { return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
1596 template<typename _ITp>
1598 atomic_fetch_and(__atomic_base<_ITp>* __a,
1599 __atomic_val_t<_ITp> __i) noexcept
1600 { return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
1602 template<typename _ITp>
1604 atomic_fetch_and(volatile __atomic_base<_ITp>* __a,
1605 __atomic_val_t<_ITp> __i) noexcept
1606 { return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
1608 template<typename _ITp>
1610 atomic_fetch_or(__atomic_base<_ITp>* __a,
1611 __atomic_val_t<_ITp> __i) noexcept
1612 { return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
1614 template<typename _ITp>
1616 atomic_fetch_or(volatile __atomic_base<_ITp>* __a,
1617 __atomic_val_t<_ITp> __i) noexcept
1618 { return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
1620 template<typename _ITp>
1622 atomic_fetch_xor(__atomic_base<_ITp>* __a,
1623 __atomic_val_t<_ITp> __i) noexcept
1624 { return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
1626 template<typename _ITp>
1628 atomic_fetch_xor(volatile __atomic_base<_ITp>* __a,
1629 __atomic_val_t<_ITp> __i) noexcept
1630 { return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
1632#ifdef __cpp_lib_atomic_float
1634 struct atomic<float> : __atomic_float<float>
1636 atomic() noexcept = default;
1639 atomic(float __fp) noexcept : __atomic_float<float>(__fp)
1642 atomic& operator=(const atomic&) volatile = delete;
1643 atomic& operator=(const atomic&) = delete;
1645 using __atomic_float<float>::operator=;
1649 struct atomic<double> : __atomic_float<double>
1651 atomic() noexcept = default;
1654 atomic(double __fp) noexcept : __atomic_float<double>(__fp)
1657 atomic& operator=(const atomic&) volatile = delete;
1658 atomic& operator=(const atomic&) = delete;
1660 using __atomic_float<double>::operator=;
1664 struct atomic<long double> : __atomic_float<long double>
1666 atomic() noexcept = default;
1669 atomic(long double __fp) noexcept : __atomic_float<long double>(__fp)
1672 atomic& operator=(const atomic&) volatile = delete;
1673 atomic& operator=(const atomic&) = delete;
1675 using __atomic_float<long double>::operator=;
1678#ifdef __STDCPP_FLOAT16_T__
1680 struct atomic<_Float16> : __atomic_float<_Float16>
1682 atomic() noexcept = default;
1685 atomic(_Float16 __fp) noexcept : __atomic_float<_Float16>(__fp)
1688 atomic& operator=(const atomic&) volatile = delete;
1689 atomic& operator=(const atomic&) = delete;
1691 using __atomic_float<_Float16>::operator=;
1695#ifdef __STDCPP_FLOAT32_T__
1697 struct atomic<_Float32> : __atomic_float<_Float32>
1699 atomic() noexcept = default;
1702 atomic(_Float32 __fp) noexcept : __atomic_float<_Float32>(__fp)
1705 atomic& operator=(const atomic&) volatile = delete;
1706 atomic& operator=(const atomic&) = delete;
1708 using __atomic_float<_Float32>::operator=;
1712#ifdef __STDCPP_FLOAT64_T__
1714 struct atomic<_Float64> : __atomic_float<_Float64>
1716 atomic() noexcept = default;
1719 atomic(_Float64 __fp) noexcept : __atomic_float<_Float64>(__fp)
1722 atomic& operator=(const atomic&) volatile = delete;
1723 atomic& operator=(const atomic&) = delete;
1725 using __atomic_float<_Float64>::operator=;
1729#ifdef __STDCPP_FLOAT128_T__
1731 struct atomic<_Float128> : __atomic_float<_Float128>
1733 atomic() noexcept = default;
1736 atomic(_Float128 __fp) noexcept : __atomic_float<_Float128>(__fp)
1739 atomic& operator=(const atomic&) volatile = delete;
1740 atomic& operator=(const atomic&) = delete;
1742 using __atomic_float<_Float128>::operator=;
1746#ifdef __STDCPP_BFLOAT16_T__
1748 struct atomic<__gnu_cxx::__bfloat16_t> : __atomic_float<__gnu_cxx::__bfloat16_t>
1750 atomic() noexcept = default;
1753 atomic(__gnu_cxx::__bfloat16_t __fp) noexcept : __atomic_float<__gnu_cxx::__bfloat16_t>(__fp)
1756 atomic& operator=(const atomic&) volatile = delete;
1757 atomic& operator=(const atomic&) = delete;
1759 using __atomic_float<__gnu_cxx::__bfloat16_t>::operator=;
1762#endif // __cpp_lib_atomic_float
1764#ifdef __cpp_lib_atomic_ref
1765 /// Class template to provide atomic operations on a non-atomic variable.
1766 template<typename _Tp>
1767 struct atomic_ref : __atomic_ref<_Tp>
1770 atomic_ref(_Tp& __t) noexcept : __atomic_ref<_Tp>(__t)
1773 atomic_ref& operator=(const atomic_ref&) = delete;
1775 atomic_ref(const atomic_ref&) = default;
1777 using __atomic_ref<_Tp>::operator=;
1779#endif // __cpp_lib_atomic_ref
1781#ifdef __cpp_lib_atomic_lock_free_type_aliases
1782# ifdef _GLIBCXX_HAVE_PLATFORM_WAIT
1783 using atomic_signed_lock_free
1784 = atomic<make_signed_t<__detail::__platform_wait_t>>;
1785 using atomic_unsigned_lock_free
1786 = atomic<make_unsigned_t<__detail::__platform_wait_t>>;
1787# elif ATOMIC_INT_LOCK_FREE == 2
1788 using atomic_signed_lock_free = atomic<signed int>;
1789 using atomic_unsigned_lock_free = atomic<unsigned int>;
1790# elif ATOMIC_LONG_LOCK_FREE == 2
1791 using atomic_signed_lock_free = atomic<signed long>;
1792 using atomic_unsigned_lock_free = atomic<unsigned long>;
1793# elif ATOMIC_CHAR_LOCK_FREE == 2
1794 using atomic_signed_lock_free = atomic<signed char>;
1795 using atomic_unsigned_lock_free = atomic<unsigned char>;
1797# error "libstdc++ bug: no lock-free atomics but they were emitted in <version>"
1801 /// @} group atomics
1803_GLIBCXX_END_NAMESPACE_VERSION
1808#endif // _GLIBCXX_ATOMIC