3// Copyright (C) 2008-2024 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>
55namespace std _GLIBCXX_VISIBILITY(default)
57_GLIBCXX_BEGIN_NAMESPACE_VERSION
64 template<typename _Tp>
68 // NB: No operators or fetch-operations for this type.
72 using value_type = bool;
75 __atomic_base<bool> _M_base;
78 atomic() noexcept = default;
79 ~atomic() noexcept = default;
80 atomic(const atomic&) = delete;
81 atomic& operator=(const atomic&) = delete;
82 atomic& operator=(const atomic&) volatile = delete;
84 constexpr atomic(bool __i) noexcept : _M_base(__i) { }
87 operator=(bool __i) noexcept
88 { return _M_base.operator=(__i); }
91 operator=(bool __i) volatile noexcept
92 { return _M_base.operator=(__i); }
94 operator bool() const noexcept
95 { return _M_base.load(); }
97 operator bool() const volatile noexcept
98 { return _M_base.load(); }
101 is_lock_free() const noexcept { return _M_base.is_lock_free(); }
104 is_lock_free() const volatile noexcept { return _M_base.is_lock_free(); }
106#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
107 static constexpr bool is_always_lock_free = ATOMIC_BOOL_LOCK_FREE == 2;
111 store(bool __i, memory_order __m = memory_order_seq_cst) noexcept
112 { _M_base.store(__i, __m); }
115 store(bool __i, memory_order __m = memory_order_seq_cst) volatile noexcept
116 { _M_base.store(__i, __m); }
119 load(memory_order __m = memory_order_seq_cst) const noexcept
120 { return _M_base.load(__m); }
123 load(memory_order __m = memory_order_seq_cst) const volatile noexcept
124 { return _M_base.load(__m); }
127 exchange(bool __i, memory_order __m = memory_order_seq_cst) noexcept
128 { return _M_base.exchange(__i, __m); }
132 memory_order __m = memory_order_seq_cst) volatile noexcept
133 { return _M_base.exchange(__i, __m); }
136 compare_exchange_weak(bool& __i1, bool __i2, memory_order __m1,
137 memory_order __m2) noexcept
138 { return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); }
141 compare_exchange_weak(bool& __i1, bool __i2, memory_order __m1,
142 memory_order __m2) volatile noexcept
143 { return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); }
146 compare_exchange_weak(bool& __i1, bool __i2,
147 memory_order __m = memory_order_seq_cst) noexcept
148 { return _M_base.compare_exchange_weak(__i1, __i2, __m); }
151 compare_exchange_weak(bool& __i1, bool __i2,
152 memory_order __m = memory_order_seq_cst) volatile noexcept
153 { return _M_base.compare_exchange_weak(__i1, __i2, __m); }
156 compare_exchange_strong(bool& __i1, bool __i2, memory_order __m1,
157 memory_order __m2) noexcept
158 { return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); }
161 compare_exchange_strong(bool& __i1, bool __i2, memory_order __m1,
162 memory_order __m2) volatile noexcept
163 { return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); }
166 compare_exchange_strong(bool& __i1, bool __i2,
167 memory_order __m = memory_order_seq_cst) noexcept
168 { return _M_base.compare_exchange_strong(__i1, __i2, __m); }
171 compare_exchange_strong(bool& __i1, bool __i2,
172 memory_order __m = memory_order_seq_cst) volatile noexcept
173 { return _M_base.compare_exchange_strong(__i1, __i2, __m); }
175#if __cpp_lib_atomic_wait
177 wait(bool __old, memory_order __m = memory_order_seq_cst) const noexcept
178 { _M_base.wait(__old, __m); }
180 // TODO add const volatile overload
183 notify_one() noexcept
184 { _M_base.notify_one(); }
187 notify_all() noexcept
188 { _M_base.notify_all(); }
189#endif // __cpp_lib_atomic_wait
192/// @cond undocumented
193#if __cpp_lib_atomic_value_initialization
194# define _GLIBCXX20_INIT(I) = I
196# define _GLIBCXX20_INIT(I)
201 * @brief Generic atomic type, primary class template.
203 * @tparam _Tp Type to be made atomic, must be trivially copyable.
205 template<typename _Tp>
208 using value_type = _Tp;
211 // Align 1/2/4/8/16-byte types to at least their size.
212 static constexpr int _S_min_alignment
213 = (sizeof(_Tp) & (sizeof(_Tp) - 1)) || sizeof(_Tp) > 16
216 static constexpr int _S_alignment
217 = _S_min_alignment > alignof(_Tp) ? _S_min_alignment : alignof(_Tp);
219 alignas(_S_alignment) _Tp _M_i _GLIBCXX20_INIT(_Tp());
221 static_assert(__is_trivially_copyable(_Tp),
222 "std::atomic requires a trivially copyable type");
224 static_assert(sizeof(_Tp) > 0,
225 "Incomplete or zero-sized types are not supported");
227#if __cplusplus > 201703L
228 static_assert(is_copy_constructible_v<_Tp>);
229 static_assert(is_move_constructible_v<_Tp>);
230 static_assert(is_copy_assignable_v<_Tp>);
231 static_assert(is_move_assignable_v<_Tp>);
236 ~atomic() noexcept = default;
237 atomic(const atomic&) = delete;
238 atomic& operator=(const atomic&) = delete;
239 atomic& operator=(const atomic&) volatile = delete;
241 constexpr atomic(_Tp __i) noexcept : _M_i(__i)
243#if __cplusplus >= 201402L && __has_builtin(__builtin_clear_padding)
244 if _GLIBCXX17_CONSTEXPR (__atomic_impl::__maybe_has_padding<_Tp>())
245 __builtin_clear_padding(std::__addressof(_M_i));
249 operator _Tp() const noexcept
252 operator _Tp() const volatile noexcept
256 operator=(_Tp __i) noexcept
257 { store(__i); return __i; }
260 operator=(_Tp __i) volatile noexcept
261 { store(__i); return __i; }
264 is_lock_free() const noexcept
266 // Produce a fake, minimally aligned pointer.
267 return __atomic_is_lock_free(sizeof(_M_i),
268 reinterpret_cast<void *>(-_S_alignment));
272 is_lock_free() const volatile noexcept
274 // Produce a fake, minimally aligned pointer.
275 return __atomic_is_lock_free(sizeof(_M_i),
276 reinterpret_cast<void *>(-_S_alignment));
279#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
280 static constexpr bool is_always_lock_free
281 = __atomic_always_lock_free(sizeof(_M_i), 0);
285 store(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept
287 __atomic_store(std::__addressof(_M_i),
288 __atomic_impl::__clear_padding(__i),
293 store(_Tp __i, memory_order __m = memory_order_seq_cst) volatile noexcept
295 __atomic_store(std::__addressof(_M_i),
296 __atomic_impl::__clear_padding(__i),
301 load(memory_order __m = memory_order_seq_cst) const noexcept
303 alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
304 _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
305 __atomic_load(std::__addressof(_M_i), __ptr, int(__m));
310 load(memory_order __m = memory_order_seq_cst) const volatile noexcept
312 alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
313 _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
314 __atomic_load(std::__addressof(_M_i), __ptr, int(__m));
319 exchange(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept
321 alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
322 _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
323 __atomic_exchange(std::__addressof(_M_i),
324 __atomic_impl::__clear_padding(__i),
331 memory_order __m = memory_order_seq_cst) volatile noexcept
333 alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
334 _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
335 __atomic_exchange(std::__addressof(_M_i),
336 __atomic_impl::__clear_padding(__i),
342 compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s,
343 memory_order __f) noexcept
345 return __atomic_impl::__compare_exchange(_M_i, __e, __i, true,
350 compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s,
351 memory_order __f) volatile noexcept
353 return __atomic_impl::__compare_exchange(_M_i, __e, __i, true,
358 compare_exchange_weak(_Tp& __e, _Tp __i,
359 memory_order __m = memory_order_seq_cst) noexcept
360 { return compare_exchange_weak(__e, __i, __m,
361 __cmpexch_failure_order(__m)); }
364 compare_exchange_weak(_Tp& __e, _Tp __i,
365 memory_order __m = memory_order_seq_cst) volatile noexcept
366 { return compare_exchange_weak(__e, __i, __m,
367 __cmpexch_failure_order(__m)); }
370 compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s,
371 memory_order __f) noexcept
373 return __atomic_impl::__compare_exchange(_M_i, __e, __i, false,
378 compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s,
379 memory_order __f) volatile noexcept
381 return __atomic_impl::__compare_exchange(_M_i, __e, __i, false,
386 compare_exchange_strong(_Tp& __e, _Tp __i,
387 memory_order __m = memory_order_seq_cst) noexcept
388 { return compare_exchange_strong(__e, __i, __m,
389 __cmpexch_failure_order(__m)); }
392 compare_exchange_strong(_Tp& __e, _Tp __i,
393 memory_order __m = memory_order_seq_cst) volatile noexcept
394 { return compare_exchange_strong(__e, __i, __m,
395 __cmpexch_failure_order(__m)); }
397#if __cpp_lib_atomic_wait // C++ >= 20
399 wait(_Tp __old, memory_order __m = memory_order_seq_cst) const noexcept
401 std::__atomic_wait_address_v(&_M_i, __old,
402 [__m, this] { return this->load(__m); });
405 // TODO add const volatile overload
408 notify_one() noexcept
409 { std::__atomic_notify_address(&_M_i, false); }
412 notify_all() noexcept
413 { std::__atomic_notify_address(&_M_i, true); }
414#endif // __cpp_lib_atomic_wait
417#undef _GLIBCXX20_INIT
419 /// Partial specialization for pointer types.
420 template<typename _Tp>
423 using value_type = _Tp*;
424 using difference_type = ptrdiff_t;
426 typedef _Tp* __pointer_type;
427 typedef __atomic_base<_Tp*> __base_type;
430 atomic() noexcept = default;
431 ~atomic() noexcept = default;
432 atomic(const atomic&) = delete;
433 atomic& operator=(const atomic&) = delete;
434 atomic& operator=(const atomic&) volatile = delete;
436 constexpr atomic(__pointer_type __p) noexcept : _M_b(__p) { }
438 operator __pointer_type() const noexcept
439 { return __pointer_type(_M_b); }
441 operator __pointer_type() const volatile noexcept
442 { return __pointer_type(_M_b); }
445 operator=(__pointer_type __p) noexcept
446 { return _M_b.operator=(__p); }
449 operator=(__pointer_type __p) volatile noexcept
450 { return _M_b.operator=(__p); }
453 operator++(int) noexcept
455#if __cplusplus >= 201703L
456 static_assert( is_object_v<_Tp>, "pointer to object type" );
462 operator++(int) volatile noexcept
464#if __cplusplus >= 201703L
465 static_assert( is_object_v<_Tp>, "pointer to object type" );
471 operator--(int) noexcept
473#if __cplusplus >= 201703L
474 static_assert( is_object_v<_Tp>, "pointer to object type" );
480 operator--(int) volatile noexcept
482#if __cplusplus >= 201703L
483 static_assert( is_object_v<_Tp>, "pointer to object type" );
489 operator++() noexcept
491#if __cplusplus >= 201703L
492 static_assert( is_object_v<_Tp>, "pointer to object type" );
498 operator++() volatile noexcept
500#if __cplusplus >= 201703L
501 static_assert( is_object_v<_Tp>, "pointer to object type" );
507 operator--() noexcept
509#if __cplusplus >= 201703L
510 static_assert( is_object_v<_Tp>, "pointer to object type" );
516 operator--() volatile noexcept
518#if __cplusplus >= 201703L
519 static_assert( is_object_v<_Tp>, "pointer to object type" );
525 operator+=(ptrdiff_t __d) noexcept
527#if __cplusplus >= 201703L
528 static_assert( is_object_v<_Tp>, "pointer to object type" );
530 return _M_b.operator+=(__d);
534 operator+=(ptrdiff_t __d) volatile noexcept
536#if __cplusplus >= 201703L
537 static_assert( is_object_v<_Tp>, "pointer to object type" );
539 return _M_b.operator+=(__d);
543 operator-=(ptrdiff_t __d) noexcept
545#if __cplusplus >= 201703L
546 static_assert( is_object_v<_Tp>, "pointer to object type" );
548 return _M_b.operator-=(__d);
552 operator-=(ptrdiff_t __d) volatile noexcept
554#if __cplusplus >= 201703L
555 static_assert( is_object_v<_Tp>, "pointer to object type" );
557 return _M_b.operator-=(__d);
561 is_lock_free() const noexcept
562 { return _M_b.is_lock_free(); }
565 is_lock_free() const volatile noexcept
566 { return _M_b.is_lock_free(); }
568#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
569 static constexpr bool is_always_lock_free
570 = ATOMIC_POINTER_LOCK_FREE == 2;
574 store(__pointer_type __p,
575 memory_order __m = memory_order_seq_cst) noexcept
576 { return _M_b.store(__p, __m); }
579 store(__pointer_type __p,
580 memory_order __m = memory_order_seq_cst) volatile noexcept
581 { return _M_b.store(__p, __m); }
584 load(memory_order __m = memory_order_seq_cst) const noexcept
585 { return _M_b.load(__m); }
588 load(memory_order __m = memory_order_seq_cst) const volatile noexcept
589 { return _M_b.load(__m); }
592 exchange(__pointer_type __p,
593 memory_order __m = memory_order_seq_cst) noexcept
594 { return _M_b.exchange(__p, __m); }
597 exchange(__pointer_type __p,
598 memory_order __m = memory_order_seq_cst) volatile noexcept
599 { return _M_b.exchange(__p, __m); }
602 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
603 memory_order __m1, memory_order __m2) noexcept
604 { return _M_b.compare_exchange_weak(__p1, __p2, __m1, __m2); }
607 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
609 memory_order __m2) volatile noexcept
610 { return _M_b.compare_exchange_weak(__p1, __p2, __m1, __m2); }
613 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
614 memory_order __m = memory_order_seq_cst) noexcept
616 return compare_exchange_weak(__p1, __p2, __m,
617 __cmpexch_failure_order(__m));
621 compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
622 memory_order __m = memory_order_seq_cst) volatile noexcept
624 return compare_exchange_weak(__p1, __p2, __m,
625 __cmpexch_failure_order(__m));
629 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
630 memory_order __m1, memory_order __m2) noexcept
631 { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
634 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
636 memory_order __m2) volatile noexcept
637 { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
640 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
641 memory_order __m = memory_order_seq_cst) noexcept
643 return _M_b.compare_exchange_strong(__p1, __p2, __m,
644 __cmpexch_failure_order(__m));
648 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
649 memory_order __m = memory_order_seq_cst) volatile noexcept
651 return _M_b.compare_exchange_strong(__p1, __p2, __m,
652 __cmpexch_failure_order(__m));
655#if __cpp_lib_atomic_wait
657 wait(__pointer_type __old, memory_order __m = memory_order_seq_cst) const noexcept
658 { _M_b.wait(__old, __m); }
660 // TODO add const volatile overload
663 notify_one() noexcept
664 { _M_b.notify_one(); }
667 notify_all() noexcept
668 { _M_b.notify_all(); }
669#endif // __cpp_lib_atomic_wait
672 fetch_add(ptrdiff_t __d,
673 memory_order __m = memory_order_seq_cst) noexcept
675#if __cplusplus >= 201703L
676 static_assert( is_object_v<_Tp>, "pointer to object type" );
678 return _M_b.fetch_add(__d, __m);
682 fetch_add(ptrdiff_t __d,
683 memory_order __m = memory_order_seq_cst) volatile noexcept
685#if __cplusplus >= 201703L
686 static_assert( is_object_v<_Tp>, "pointer to object type" );
688 return _M_b.fetch_add(__d, __m);
692 fetch_sub(ptrdiff_t __d,
693 memory_order __m = memory_order_seq_cst) noexcept
695#if __cplusplus >= 201703L
696 static_assert( is_object_v<_Tp>, "pointer to object type" );
698 return _M_b.fetch_sub(__d, __m);
702 fetch_sub(ptrdiff_t __d,
703 memory_order __m = memory_order_seq_cst) volatile noexcept
705#if __cplusplus >= 201703L
706 static_assert( is_object_v<_Tp>, "pointer to object type" );
708 return _M_b.fetch_sub(__d, __m);
713 /// Explicit specialization for char.
715 struct atomic<char> : __atomic_base<char>
717 typedef char __integral_type;
718 typedef __atomic_base<char> __base_type;
720 atomic() noexcept = default;
721 ~atomic() noexcept = default;
722 atomic(const atomic&) = delete;
723 atomic& operator=(const atomic&) = delete;
724 atomic& operator=(const atomic&) volatile = delete;
726 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
728 using __base_type::operator __integral_type;
729 using __base_type::operator=;
731#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
732 static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
736 /// Explicit specialization for signed char.
738 struct atomic<signed char> : __atomic_base<signed char>
740 typedef signed char __integral_type;
741 typedef __atomic_base<signed char> __base_type;
743 atomic() noexcept= default;
744 ~atomic() noexcept = default;
745 atomic(const atomic&) = delete;
746 atomic& operator=(const atomic&) = delete;
747 atomic& operator=(const atomic&) volatile = delete;
749 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
751 using __base_type::operator __integral_type;
752 using __base_type::operator=;
754#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
755 static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
759 /// Explicit specialization for unsigned char.
761 struct atomic<unsigned char> : __atomic_base<unsigned char>
763 typedef unsigned char __integral_type;
764 typedef __atomic_base<unsigned char> __base_type;
766 atomic() noexcept= default;
767 ~atomic() noexcept = default;
768 atomic(const atomic&) = delete;
769 atomic& operator=(const atomic&) = delete;
770 atomic& operator=(const atomic&) volatile = delete;
772 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
774 using __base_type::operator __integral_type;
775 using __base_type::operator=;
777#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
778 static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
782 /// Explicit specialization for short.
784 struct atomic<short> : __atomic_base<short>
786 typedef short __integral_type;
787 typedef __atomic_base<short> __base_type;
789 atomic() noexcept = default;
790 ~atomic() noexcept = default;
791 atomic(const atomic&) = delete;
792 atomic& operator=(const atomic&) = delete;
793 atomic& operator=(const atomic&) volatile = delete;
795 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
797 using __base_type::operator __integral_type;
798 using __base_type::operator=;
800#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
801 static constexpr bool is_always_lock_free = ATOMIC_SHORT_LOCK_FREE == 2;
805 /// Explicit specialization for unsigned short.
807 struct atomic<unsigned short> : __atomic_base<unsigned short>
809 typedef unsigned short __integral_type;
810 typedef __atomic_base<unsigned short> __base_type;
812 atomic() noexcept = default;
813 ~atomic() noexcept = default;
814 atomic(const atomic&) = delete;
815 atomic& operator=(const atomic&) = delete;
816 atomic& operator=(const atomic&) volatile = delete;
818 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
820 using __base_type::operator __integral_type;
821 using __base_type::operator=;
823#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
824 static constexpr bool is_always_lock_free = ATOMIC_SHORT_LOCK_FREE == 2;
828 /// Explicit specialization for int.
830 struct atomic<int> : __atomic_base<int>
832 typedef int __integral_type;
833 typedef __atomic_base<int> __base_type;
835 atomic() noexcept = default;
836 ~atomic() noexcept = default;
837 atomic(const atomic&) = delete;
838 atomic& operator=(const atomic&) = delete;
839 atomic& operator=(const atomic&) volatile = delete;
841 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
843 using __base_type::operator __integral_type;
844 using __base_type::operator=;
846#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
847 static constexpr bool is_always_lock_free = ATOMIC_INT_LOCK_FREE == 2;
851 /// Explicit specialization for unsigned int.
853 struct atomic<unsigned int> : __atomic_base<unsigned int>
855 typedef unsigned int __integral_type;
856 typedef __atomic_base<unsigned int> __base_type;
858 atomic() noexcept = default;
859 ~atomic() noexcept = default;
860 atomic(const atomic&) = delete;
861 atomic& operator=(const atomic&) = delete;
862 atomic& operator=(const atomic&) volatile = delete;
864 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
866 using __base_type::operator __integral_type;
867 using __base_type::operator=;
869#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
870 static constexpr bool is_always_lock_free = ATOMIC_INT_LOCK_FREE == 2;
874 /// Explicit specialization for long.
876 struct atomic<long> : __atomic_base<long>
878 typedef long __integral_type;
879 typedef __atomic_base<long> __base_type;
881 atomic() noexcept = default;
882 ~atomic() noexcept = default;
883 atomic(const atomic&) = delete;
884 atomic& operator=(const atomic&) = delete;
885 atomic& operator=(const atomic&) volatile = delete;
887 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
889 using __base_type::operator __integral_type;
890 using __base_type::operator=;
892#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
893 static constexpr bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2;
897 /// Explicit specialization for unsigned long.
899 struct atomic<unsigned long> : __atomic_base<unsigned long>
901 typedef unsigned long __integral_type;
902 typedef __atomic_base<unsigned long> __base_type;
904 atomic() noexcept = default;
905 ~atomic() noexcept = default;
906 atomic(const atomic&) = delete;
907 atomic& operator=(const atomic&) = delete;
908 atomic& operator=(const atomic&) volatile = delete;
910 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
912 using __base_type::operator __integral_type;
913 using __base_type::operator=;
915#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
916 static constexpr bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2;
920 /// Explicit specialization for long long.
922 struct atomic<long long> : __atomic_base<long long>
924 typedef long long __integral_type;
925 typedef __atomic_base<long long> __base_type;
927 atomic() noexcept = default;
928 ~atomic() noexcept = default;
929 atomic(const atomic&) = delete;
930 atomic& operator=(const atomic&) = delete;
931 atomic& operator=(const atomic&) volatile = delete;
933 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
935 using __base_type::operator __integral_type;
936 using __base_type::operator=;
938#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
939 static constexpr bool is_always_lock_free = ATOMIC_LLONG_LOCK_FREE == 2;
943 /// Explicit specialization for unsigned long long.
945 struct atomic<unsigned long long> : __atomic_base<unsigned long long>
947 typedef unsigned long long __integral_type;
948 typedef __atomic_base<unsigned long long> __base_type;
950 atomic() noexcept = default;
951 ~atomic() noexcept = default;
952 atomic(const atomic&) = delete;
953 atomic& operator=(const atomic&) = delete;
954 atomic& operator=(const atomic&) volatile = delete;
956 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
958 using __base_type::operator __integral_type;
959 using __base_type::operator=;
961#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
962 static constexpr bool is_always_lock_free = ATOMIC_LLONG_LOCK_FREE == 2;
966 /// Explicit specialization for wchar_t.
968 struct atomic<wchar_t> : __atomic_base<wchar_t>
970 typedef wchar_t __integral_type;
971 typedef __atomic_base<wchar_t> __base_type;
973 atomic() noexcept = default;
974 ~atomic() noexcept = default;
975 atomic(const atomic&) = delete;
976 atomic& operator=(const atomic&) = delete;
977 atomic& operator=(const atomic&) volatile = delete;
979 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
981 using __base_type::operator __integral_type;
982 using __base_type::operator=;
984#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
985 static constexpr bool is_always_lock_free = ATOMIC_WCHAR_T_LOCK_FREE == 2;
989#ifdef _GLIBCXX_USE_CHAR8_T
990 /// Explicit specialization for char8_t.
992 struct atomic<char8_t> : __atomic_base<char8_t>
994 typedef char8_t __integral_type;
995 typedef __atomic_base<char8_t> __base_type;
997 atomic() noexcept = default;
998 ~atomic() noexcept = default;
999 atomic(const atomic&) = delete;
1000 atomic& operator=(const atomic&) = delete;
1001 atomic& operator=(const atomic&) volatile = delete;
1003 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
1005 using __base_type::operator __integral_type;
1006 using __base_type::operator=;
1008#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
1009 static constexpr bool is_always_lock_free
1010 = ATOMIC_CHAR8_T_LOCK_FREE == 2;
1015 /// Explicit specialization for char16_t.
1017 struct atomic<char16_t> : __atomic_base<char16_t>
1019 typedef char16_t __integral_type;
1020 typedef __atomic_base<char16_t> __base_type;
1022 atomic() noexcept = default;
1023 ~atomic() noexcept = default;
1024 atomic(const atomic&) = delete;
1025 atomic& operator=(const atomic&) = delete;
1026 atomic& operator=(const atomic&) volatile = delete;
1028 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
1030 using __base_type::operator __integral_type;
1031 using __base_type::operator=;
1033#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
1034 static constexpr bool is_always_lock_free
1035 = ATOMIC_CHAR16_T_LOCK_FREE == 2;
1039 /// Explicit specialization for char32_t.
1041 struct atomic<char32_t> : __atomic_base<char32_t>
1043 typedef char32_t __integral_type;
1044 typedef __atomic_base<char32_t> __base_type;
1046 atomic() noexcept = default;
1047 ~atomic() noexcept = default;
1048 atomic(const atomic&) = delete;
1049 atomic& operator=(const atomic&) = delete;
1050 atomic& operator=(const atomic&) volatile = delete;
1052 constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
1054 using __base_type::operator __integral_type;
1055 using __base_type::operator=;
1057#ifdef __cpp_lib_atomic_is_always_lock_free // C++ >= 17
1058 static constexpr bool is_always_lock_free
1059 = ATOMIC_CHAR32_T_LOCK_FREE == 2;
1065 typedef atomic<bool> atomic_bool;
1068 typedef atomic<char> atomic_char;
1071 typedef atomic<signed char> atomic_schar;
1074 typedef atomic<unsigned char> atomic_uchar;
1077 typedef atomic<short> atomic_short;
1080 typedef atomic<unsigned short> atomic_ushort;
1083 typedef atomic<int> atomic_int;
1086 typedef atomic<unsigned int> atomic_uint;
1089 typedef atomic<long> atomic_long;
1092 typedef atomic<unsigned long> atomic_ulong;
1095 typedef atomic<long long> atomic_llong;
1098 typedef atomic<unsigned long long> atomic_ullong;
1101 typedef atomic<wchar_t> atomic_wchar_t;
1103#ifdef _GLIBCXX_USE_CHAR8_T
1105 typedef atomic<char8_t> atomic_char8_t;
1109 typedef atomic<char16_t> atomic_char16_t;
1112 typedef atomic<char32_t> atomic_char32_t;
1114#ifdef _GLIBCXX_USE_C99_STDINT
1115 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1116 // 2441. Exact-width atomic typedefs should be provided
1119 typedef atomic<int8_t> atomic_int8_t;
1122 typedef atomic<uint8_t> atomic_uint8_t;
1125 typedef atomic<int16_t> atomic_int16_t;
1128 typedef atomic<uint16_t> atomic_uint16_t;
1131 typedef atomic<int32_t> atomic_int32_t;
1134 typedef atomic<uint32_t> atomic_uint32_t;
1137 typedef atomic<int64_t> atomic_int64_t;
1140 typedef atomic<uint64_t> atomic_uint64_t;
1143 /// atomic_int_least8_t
1144 typedef atomic<int_least8_t> atomic_int_least8_t;
1146 /// atomic_uint_least8_t
1147 typedef atomic<uint_least8_t> atomic_uint_least8_t;
1149 /// atomic_int_least16_t
1150 typedef atomic<int_least16_t> atomic_int_least16_t;
1152 /// atomic_uint_least16_t
1153 typedef atomic<uint_least16_t> atomic_uint_least16_t;
1155 /// atomic_int_least32_t
1156 typedef atomic<int_least32_t> atomic_int_least32_t;
1158 /// atomic_uint_least32_t
1159 typedef atomic<uint_least32_t> atomic_uint_least32_t;
1161 /// atomic_int_least64_t
1162 typedef atomic<int_least64_t> atomic_int_least64_t;
1164 /// atomic_uint_least64_t
1165 typedef atomic<uint_least64_t> atomic_uint_least64_t;
1168 /// atomic_int_fast8_t
1169 typedef atomic<int_fast8_t> atomic_int_fast8_t;
1171 /// atomic_uint_fast8_t
1172 typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
1174 /// atomic_int_fast16_t
1175 typedef atomic<int_fast16_t> atomic_int_fast16_t;
1177 /// atomic_uint_fast16_t
1178 typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
1180 /// atomic_int_fast32_t
1181 typedef atomic<int_fast32_t> atomic_int_fast32_t;
1183 /// atomic_uint_fast32_t
1184 typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
1186 /// atomic_int_fast64_t
1187 typedef atomic<int_fast64_t> atomic_int_fast64_t;
1189 /// atomic_uint_fast64_t
1190 typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
1194 typedef atomic<intptr_t> atomic_intptr_t;
1196 /// atomic_uintptr_t
1197 typedef atomic<uintptr_t> atomic_uintptr_t;
1200 typedef atomic<size_t> atomic_size_t;
1202 /// atomic_ptrdiff_t
1203 typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
1206 typedef atomic<intmax_t> atomic_intmax_t;
1208 /// atomic_uintmax_t
1209 typedef atomic<uintmax_t> atomic_uintmax_t;
1211 // Function definitions, atomic_flag operations.
1213 atomic_flag_test_and_set_explicit(atomic_flag* __a,
1214 memory_order __m) noexcept
1215 { return __a->test_and_set(__m); }
1218 atomic_flag_test_and_set_explicit(volatile atomic_flag* __a,
1219 memory_order __m) noexcept
1220 { return __a->test_and_set(__m); }
1222#if __cpp_lib_atomic_flag_test
1224 atomic_flag_test(const atomic_flag* __a) noexcept
1225 { return __a->test(); }
1228 atomic_flag_test(const volatile atomic_flag* __a) noexcept
1229 { return __a->test(); }
1232 atomic_flag_test_explicit(const atomic_flag* __a,
1233 memory_order __m) noexcept
1234 { return __a->test(__m); }
1237 atomic_flag_test_explicit(const volatile atomic_flag* __a,
1238 memory_order __m) noexcept
1239 { return __a->test(__m); }
1243 atomic_flag_clear_explicit(atomic_flag* __a, memory_order __m) noexcept
1244 { __a->clear(__m); }
1247 atomic_flag_clear_explicit(volatile atomic_flag* __a,
1248 memory_order __m) noexcept
1249 { __a->clear(__m); }
1252 atomic_flag_test_and_set(atomic_flag* __a) noexcept
1253 { return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
1256 atomic_flag_test_and_set(volatile atomic_flag* __a) noexcept
1257 { return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
1260 atomic_flag_clear(atomic_flag* __a) noexcept
1261 { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
1264 atomic_flag_clear(volatile atomic_flag* __a) noexcept
1265 { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
1267#if __cpp_lib_atomic_wait
1269 atomic_flag_wait(atomic_flag* __a, bool __old) noexcept
1270 { __a->wait(__old); }
1273 atomic_flag_wait_explicit(atomic_flag* __a, bool __old,
1274 memory_order __m) noexcept
1275 { __a->wait(__old, __m); }
1278 atomic_flag_notify_one(atomic_flag* __a) noexcept
1279 { __a->notify_one(); }
1282 atomic_flag_notify_all(atomic_flag* __a) noexcept
1283 { __a->notify_all(); }
1284#endif // __cpp_lib_atomic_wait
1286 /// @cond undocumented
1287 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1288 // 3220. P0558 broke conforming C++14 uses of atomic shared_ptr
1289 template<typename _Tp>
1290 using __atomic_val_t = __type_identity_t<_Tp>;
1291 template<typename _Tp>
1292 using __atomic_diff_t = typename atomic<_Tp>::difference_type;
1295 // [atomics.nonmembers] Non-member functions.
1296 // Function templates generally applicable to atomic types.
1297 template<typename _ITp>
1299 atomic_is_lock_free(const atomic<_ITp>* __a) noexcept
1300 { return __a->is_lock_free(); }
1302 template<typename _ITp>
1304 atomic_is_lock_free(const volatile atomic<_ITp>* __a) noexcept
1305 { return __a->is_lock_free(); }
1307 template<typename _ITp>
1309 atomic_init(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1310 { __a->store(__i, memory_order_relaxed); }
1312 template<typename _ITp>
1314 atomic_init(volatile atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1315 { __a->store(__i, memory_order_relaxed); }
1317 template<typename _ITp>
1319 atomic_store_explicit(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1320 memory_order __m) noexcept
1321 { __a->store(__i, __m); }
1323 template<typename _ITp>
1325 atomic_store_explicit(volatile atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1326 memory_order __m) noexcept
1327 { __a->store(__i, __m); }
1329 template<typename _ITp>
1331 atomic_load_explicit(const atomic<_ITp>* __a, memory_order __m) noexcept
1332 { return __a->load(__m); }
1334 template<typename _ITp>
1336 atomic_load_explicit(const volatile atomic<_ITp>* __a,
1337 memory_order __m) noexcept
1338 { return __a->load(__m); }
1340 template<typename _ITp>
1342 atomic_exchange_explicit(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1343 memory_order __m) noexcept
1344 { return __a->exchange(__i, __m); }
1346 template<typename _ITp>
1348 atomic_exchange_explicit(volatile atomic<_ITp>* __a,
1349 __atomic_val_t<_ITp> __i,
1350 memory_order __m) noexcept
1351 { return __a->exchange(__i, __m); }
1353 template<typename _ITp>
1355 atomic_compare_exchange_weak_explicit(atomic<_ITp>* __a,
1356 __atomic_val_t<_ITp>* __i1,
1357 __atomic_val_t<_ITp> __i2,
1359 memory_order __m2) noexcept
1360 { return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
1362 template<typename _ITp>
1364 atomic_compare_exchange_weak_explicit(volatile atomic<_ITp>* __a,
1365 __atomic_val_t<_ITp>* __i1,
1366 __atomic_val_t<_ITp> __i2,
1368 memory_order __m2) noexcept
1369 { return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
1371 template<typename _ITp>
1373 atomic_compare_exchange_strong_explicit(atomic<_ITp>* __a,
1374 __atomic_val_t<_ITp>* __i1,
1375 __atomic_val_t<_ITp> __i2,
1377 memory_order __m2) noexcept
1378 { return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
1380 template<typename _ITp>
1382 atomic_compare_exchange_strong_explicit(volatile atomic<_ITp>* __a,
1383 __atomic_val_t<_ITp>* __i1,
1384 __atomic_val_t<_ITp> __i2,
1386 memory_order __m2) noexcept
1387 { return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
1390 template<typename _ITp>
1392 atomic_store(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1393 { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
1395 template<typename _ITp>
1397 atomic_store(volatile 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_load(const atomic<_ITp>* __a) noexcept
1403 { return atomic_load_explicit(__a, memory_order_seq_cst); }
1405 template<typename _ITp>
1407 atomic_load(const volatile atomic<_ITp>* __a) noexcept
1408 { return atomic_load_explicit(__a, memory_order_seq_cst); }
1410 template<typename _ITp>
1412 atomic_exchange(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1413 { return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
1415 template<typename _ITp>
1417 atomic_exchange(volatile atomic<_ITp>* __a,
1418 __atomic_val_t<_ITp> __i) noexcept
1419 { return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
1421 template<typename _ITp>
1423 atomic_compare_exchange_weak(atomic<_ITp>* __a,
1424 __atomic_val_t<_ITp>* __i1,
1425 __atomic_val_t<_ITp> __i2) noexcept
1427 return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
1428 memory_order_seq_cst,
1429 memory_order_seq_cst);
1432 template<typename _ITp>
1434 atomic_compare_exchange_weak(volatile atomic<_ITp>* __a,
1435 __atomic_val_t<_ITp>* __i1,
1436 __atomic_val_t<_ITp> __i2) noexcept
1438 return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
1439 memory_order_seq_cst,
1440 memory_order_seq_cst);
1443 template<typename _ITp>
1445 atomic_compare_exchange_strong(atomic<_ITp>* __a,
1446 __atomic_val_t<_ITp>* __i1,
1447 __atomic_val_t<_ITp> __i2) noexcept
1449 return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
1450 memory_order_seq_cst,
1451 memory_order_seq_cst);
1454 template<typename _ITp>
1456 atomic_compare_exchange_strong(volatile atomic<_ITp>* __a,
1457 __atomic_val_t<_ITp>* __i1,
1458 __atomic_val_t<_ITp> __i2) noexcept
1460 return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
1461 memory_order_seq_cst,
1462 memory_order_seq_cst);
1466#if __cpp_lib_atomic_wait
1467 template<typename _Tp>
1469 atomic_wait(const atomic<_Tp>* __a,
1470 typename std::atomic<_Tp>::value_type __old) noexcept
1471 { __a->wait(__old); }
1473 template<typename _Tp>
1475 atomic_wait_explicit(const atomic<_Tp>* __a,
1476 typename std::atomic<_Tp>::value_type __old,
1477 std::memory_order __m) noexcept
1478 { __a->wait(__old, __m); }
1480 template<typename _Tp>
1482 atomic_notify_one(atomic<_Tp>* __a) noexcept
1483 { __a->notify_one(); }
1485 template<typename _Tp>
1487 atomic_notify_all(atomic<_Tp>* __a) noexcept
1488 { __a->notify_all(); }
1489#endif // __cpp_lib_atomic_wait
1491 // Function templates for atomic_integral and atomic_pointer operations only.
1492 // Some operations (and, or, xor) are only available for atomic integrals,
1493 // which is implemented by taking a parameter of type __atomic_base<_ITp>*.
1495 template<typename _ITp>
1497 atomic_fetch_add_explicit(atomic<_ITp>* __a,
1498 __atomic_diff_t<_ITp> __i,
1499 memory_order __m) noexcept
1500 { return __a->fetch_add(__i, __m); }
1502 template<typename _ITp>
1504 atomic_fetch_add_explicit(volatile 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_sub_explicit(atomic<_ITp>* __a,
1512 __atomic_diff_t<_ITp> __i,
1513 memory_order __m) noexcept
1514 { return __a->fetch_sub(__i, __m); }
1516 template<typename _ITp>
1518 atomic_fetch_sub_explicit(volatile 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_and_explicit(__atomic_base<_ITp>* __a,
1526 __atomic_val_t<_ITp> __i,
1527 memory_order __m) noexcept
1528 { return __a->fetch_and(__i, __m); }
1530 template<typename _ITp>
1532 atomic_fetch_and_explicit(volatile __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_or_explicit(__atomic_base<_ITp>* __a,
1540 __atomic_val_t<_ITp> __i,
1541 memory_order __m) noexcept
1542 { return __a->fetch_or(__i, __m); }
1544 template<typename _ITp>
1546 atomic_fetch_or_explicit(volatile __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_xor_explicit(__atomic_base<_ITp>* __a,
1554 __atomic_val_t<_ITp> __i,
1555 memory_order __m) noexcept
1556 { return __a->fetch_xor(__i, __m); }
1558 template<typename _ITp>
1560 atomic_fetch_xor_explicit(volatile __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_add(atomic<_ITp>* __a,
1568 __atomic_diff_t<_ITp> __i) noexcept
1569 { return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
1571 template<typename _ITp>
1573 atomic_fetch_add(volatile atomic<_ITp>* __a,
1574 __atomic_diff_t<_ITp> __i) noexcept
1575 { return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
1577 template<typename _ITp>
1579 atomic_fetch_sub(atomic<_ITp>* __a,
1580 __atomic_diff_t<_ITp> __i) noexcept
1581 { return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
1583 template<typename _ITp>
1585 atomic_fetch_sub(volatile atomic<_ITp>* __a,
1586 __atomic_diff_t<_ITp> __i) noexcept
1587 { return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
1589 template<typename _ITp>
1591 atomic_fetch_and(__atomic_base<_ITp>* __a,
1592 __atomic_val_t<_ITp> __i) noexcept
1593 { return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
1595 template<typename _ITp>
1597 atomic_fetch_and(volatile __atomic_base<_ITp>* __a,
1598 __atomic_val_t<_ITp> __i) noexcept
1599 { return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
1601 template<typename _ITp>
1603 atomic_fetch_or(__atomic_base<_ITp>* __a,
1604 __atomic_val_t<_ITp> __i) noexcept
1605 { return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
1607 template<typename _ITp>
1609 atomic_fetch_or(volatile __atomic_base<_ITp>* __a,
1610 __atomic_val_t<_ITp> __i) noexcept
1611 { return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
1613 template<typename _ITp>
1615 atomic_fetch_xor(__atomic_base<_ITp>* __a,
1616 __atomic_val_t<_ITp> __i) noexcept
1617 { return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
1619 template<typename _ITp>
1621 atomic_fetch_xor(volatile __atomic_base<_ITp>* __a,
1622 __atomic_val_t<_ITp> __i) noexcept
1623 { return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
1625#ifdef __cpp_lib_atomic_float
1627 struct atomic<float> : __atomic_float<float>
1629 atomic() noexcept = default;
1632 atomic(float __fp) noexcept : __atomic_float<float>(__fp)
1635 atomic& operator=(const atomic&) volatile = delete;
1636 atomic& operator=(const atomic&) = delete;
1638 using __atomic_float<float>::operator=;
1642 struct atomic<double> : __atomic_float<double>
1644 atomic() noexcept = default;
1647 atomic(double __fp) noexcept : __atomic_float<double>(__fp)
1650 atomic& operator=(const atomic&) volatile = delete;
1651 atomic& operator=(const atomic&) = delete;
1653 using __atomic_float<double>::operator=;
1657 struct atomic<long double> : __atomic_float<long double>
1659 atomic() noexcept = default;
1662 atomic(long double __fp) noexcept : __atomic_float<long double>(__fp)
1665 atomic& operator=(const atomic&) volatile = delete;
1666 atomic& operator=(const atomic&) = delete;
1668 using __atomic_float<long double>::operator=;
1671#ifdef __STDCPP_FLOAT16_T__
1673 struct atomic<_Float16> : __atomic_float<_Float16>
1675 atomic() noexcept = default;
1678 atomic(_Float16 __fp) noexcept : __atomic_float<_Float16>(__fp)
1681 atomic& operator=(const atomic&) volatile = delete;
1682 atomic& operator=(const atomic&) = delete;
1684 using __atomic_float<_Float16>::operator=;
1688#ifdef __STDCPP_FLOAT32_T__
1690 struct atomic<_Float32> : __atomic_float<_Float32>
1692 atomic() noexcept = default;
1695 atomic(_Float32 __fp) noexcept : __atomic_float<_Float32>(__fp)
1698 atomic& operator=(const atomic&) volatile = delete;
1699 atomic& operator=(const atomic&) = delete;
1701 using __atomic_float<_Float32>::operator=;
1705#ifdef __STDCPP_FLOAT64_T__
1707 struct atomic<_Float64> : __atomic_float<_Float64>
1709 atomic() noexcept = default;
1712 atomic(_Float64 __fp) noexcept : __atomic_float<_Float64>(__fp)
1715 atomic& operator=(const atomic&) volatile = delete;
1716 atomic& operator=(const atomic&) = delete;
1718 using __atomic_float<_Float64>::operator=;
1722#ifdef __STDCPP_FLOAT128_T__
1724 struct atomic<_Float128> : __atomic_float<_Float128>
1726 atomic() noexcept = default;
1729 atomic(_Float128 __fp) noexcept : __atomic_float<_Float128>(__fp)
1732 atomic& operator=(const atomic&) volatile = delete;
1733 atomic& operator=(const atomic&) = delete;
1735 using __atomic_float<_Float128>::operator=;
1739#ifdef __STDCPP_BFLOAT16_T__
1741 struct atomic<__gnu_cxx::__bfloat16_t> : __atomic_float<__gnu_cxx::__bfloat16_t>
1743 atomic() noexcept = default;
1746 atomic(__gnu_cxx::__bfloat16_t __fp) noexcept : __atomic_float<__gnu_cxx::__bfloat16_t>(__fp)
1749 atomic& operator=(const atomic&) volatile = delete;
1750 atomic& operator=(const atomic&) = delete;
1752 using __atomic_float<__gnu_cxx::__bfloat16_t>::operator=;
1755#endif // __cpp_lib_atomic_float
1757#ifdef __cpp_lib_atomic_ref
1758 /// Class template to provide atomic operations on a non-atomic variable.
1759 template<typename _Tp>
1760 struct atomic_ref : __atomic_ref<_Tp>
1763 atomic_ref(_Tp& __t) noexcept : __atomic_ref<_Tp>(__t)
1766 atomic_ref& operator=(const atomic_ref&) = delete;
1768 atomic_ref(const atomic_ref&) = default;
1770 using __atomic_ref<_Tp>::operator=;
1772#endif // __cpp_lib_atomic_ref
1774#ifdef __cpp_lib_atomic_lock_free_type_aliases
1775# ifdef _GLIBCXX_HAVE_PLATFORM_WAIT
1776 using atomic_signed_lock_free
1777 = atomic<make_signed_t<__detail::__platform_wait_t>>;
1778 using atomic_unsigned_lock_free
1779 = atomic<make_unsigned_t<__detail::__platform_wait_t>>;
1780# elif ATOMIC_INT_LOCK_FREE == 2
1781 using atomic_signed_lock_free = atomic<signed int>;
1782 using atomic_unsigned_lock_free = atomic<unsigned int>;
1783# elif ATOMIC_LONG_LOCK_FREE == 2
1784 using atomic_signed_lock_free = atomic<signed long>;
1785 using atomic_unsigned_lock_free = atomic<unsigned long>;
1786# elif ATOMIC_CHAR_LOCK_FREE == 2
1787 using atomic_signed_lock_free = atomic<signed char>;
1788 using atomic_unsigned_lock_free = atomic<unsigned char>;
1790# error "libstdc++ bug: no lock-free atomics but they were emitted in <version>"
1794 /// @} group atomics
1796_GLIBCXX_END_NAMESPACE_VERSION
1801#endif // _GLIBCXX_ATOMIC