libstdc++
atomic
Go to the documentation of this file.
1 // -*- C++ -*- header.
2 
3 // Copyright (C) 2008-2019 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
10 
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.
15 
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.
19 
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/>.
24 
25 /** @file include/atomic
26  * This is a Standard C++ Library header.
27  */
28 
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
31 
32 #ifndef _GLIBCXX_ATOMIC
33 #define _GLIBCXX_ATOMIC 1
34 
35 #pragma GCC system_header
36 
37 #if __cplusplus < 201103L
38 # include <bits/c++0x_warning.h>
39 #else
40 
41 #include <bits/atomic_base.h>
42 
43 namespace std _GLIBCXX_VISIBILITY(default)
44 {
45 _GLIBCXX_BEGIN_NAMESPACE_VERSION
46 
47  /**
48  * @addtogroup atomics
49  * @{
50  */
51 
52 #if __cplusplus >= 201703L
53 # define __cpp_lib_atomic_is_always_lock_free 201603
54 #endif
55 
56  template<typename _Tp>
57  struct atomic;
58 
59  /// atomic<bool>
60  // NB: No operators or fetch-operations for this type.
61  template<>
62  struct atomic<bool>
63  {
64  using value_type = bool;
65 
66  private:
67  __atomic_base<bool> _M_base;
68 
69  public:
70  atomic() noexcept = default;
71  ~atomic() noexcept = default;
72  atomic(const atomic&) = delete;
73  atomic& operator=(const atomic&) = delete;
74  atomic& operator=(const atomic&) volatile = delete;
75 
76  constexpr atomic(bool __i) noexcept : _M_base(__i) { }
77 
78  bool
79  operator=(bool __i) noexcept
80  { return _M_base.operator=(__i); }
81 
82  bool
83  operator=(bool __i) volatile noexcept
84  { return _M_base.operator=(__i); }
85 
86  operator bool() const noexcept
87  { return _M_base.load(); }
88 
89  operator bool() const volatile noexcept
90  { return _M_base.load(); }
91 
92  bool
93  is_lock_free() const noexcept { return _M_base.is_lock_free(); }
94 
95  bool
96  is_lock_free() const volatile noexcept { return _M_base.is_lock_free(); }
97 
98 #if __cplusplus >= 201703L
99  static constexpr bool is_always_lock_free = ATOMIC_BOOL_LOCK_FREE == 2;
100 #endif
101 
102  void
103  store(bool __i, memory_order __m = memory_order_seq_cst) noexcept
104  { _M_base.store(__i, __m); }
105 
106  void
107  store(bool __i, memory_order __m = memory_order_seq_cst) volatile noexcept
108  { _M_base.store(__i, __m); }
109 
110  bool
111  load(memory_order __m = memory_order_seq_cst) const noexcept
112  { return _M_base.load(__m); }
113 
114  bool
115  load(memory_order __m = memory_order_seq_cst) const volatile noexcept
116  { return _M_base.load(__m); }
117 
118  bool
119  exchange(bool __i, memory_order __m = memory_order_seq_cst) noexcept
120  { return _M_base.exchange(__i, __m); }
121 
122  bool
123  exchange(bool __i,
124  memory_order __m = memory_order_seq_cst) volatile noexcept
125  { return _M_base.exchange(__i, __m); }
126 
127  bool
128  compare_exchange_weak(bool& __i1, bool __i2, memory_order __m1,
129  memory_order __m2) noexcept
130  { return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); }
131 
132  bool
133  compare_exchange_weak(bool& __i1, bool __i2, memory_order __m1,
134  memory_order __m2) volatile noexcept
135  { return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); }
136 
137  bool
138  compare_exchange_weak(bool& __i1, bool __i2,
139  memory_order __m = memory_order_seq_cst) noexcept
140  { return _M_base.compare_exchange_weak(__i1, __i2, __m); }
141 
142  bool
143  compare_exchange_weak(bool& __i1, bool __i2,
144  memory_order __m = memory_order_seq_cst) volatile noexcept
145  { return _M_base.compare_exchange_weak(__i1, __i2, __m); }
146 
147  bool
148  compare_exchange_strong(bool& __i1, bool __i2, memory_order __m1,
149  memory_order __m2) noexcept
150  { return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); }
151 
152  bool
153  compare_exchange_strong(bool& __i1, bool __i2, memory_order __m1,
154  memory_order __m2) volatile noexcept
155  { return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); }
156 
157  bool
158  compare_exchange_strong(bool& __i1, bool __i2,
159  memory_order __m = memory_order_seq_cst) noexcept
160  { return _M_base.compare_exchange_strong(__i1, __i2, __m); }
161 
162  bool
163  compare_exchange_strong(bool& __i1, bool __i2,
164  memory_order __m = memory_order_seq_cst) volatile noexcept
165  { return _M_base.compare_exchange_strong(__i1, __i2, __m); }
166  };
167 
168 
169  /**
170  * @brief Generic atomic type, primary class template.
171  *
172  * @tparam _Tp Type to be made atomic, must be trivally copyable.
173  */
174  template<typename _Tp>
175  struct atomic
176  {
177  using value_type = _Tp;
178 
179  private:
180  // Align 1/2/4/8/16-byte types to at least their size.
181  static constexpr int _S_min_alignment
182  = (sizeof(_Tp) & (sizeof(_Tp) - 1)) || sizeof(_Tp) > 16
183  ? 0 : sizeof(_Tp);
184 
185  static constexpr int _S_alignment
186  = _S_min_alignment > alignof(_Tp) ? _S_min_alignment : alignof(_Tp);
187 
188  alignas(_S_alignment) _Tp _M_i;
189 
190  static_assert(__is_trivially_copyable(_Tp),
191  "std::atomic requires a trivially copyable type");
192 
193  static_assert(sizeof(_Tp) > 0,
194  "Incomplete or zero-sized types are not supported");
195 
196  public:
197  atomic() noexcept = default;
198  ~atomic() noexcept = default;
199  atomic(const atomic&) = delete;
200  atomic& operator=(const atomic&) = delete;
201  atomic& operator=(const atomic&) volatile = delete;
202 
203  constexpr atomic(_Tp __i) noexcept : _M_i(__i) { }
204 
205  operator _Tp() const noexcept
206  { return load(); }
207 
208  operator _Tp() const volatile noexcept
209  { return load(); }
210 
211  _Tp
212  operator=(_Tp __i) noexcept
213  { store(__i); return __i; }
214 
215  _Tp
216  operator=(_Tp __i) volatile noexcept
217  { store(__i); return __i; }
218 
219  bool
220  is_lock_free() const noexcept
221  {
222  // Produce a fake, minimally aligned pointer.
223  return __atomic_is_lock_free(sizeof(_M_i),
224  reinterpret_cast<void *>(-_S_alignment));
225  }
226 
227  bool
228  is_lock_free() const volatile noexcept
229  {
230  // Produce a fake, minimally aligned pointer.
231  return __atomic_is_lock_free(sizeof(_M_i),
232  reinterpret_cast<void *>(-_S_alignment));
233  }
234 
235 #if __cplusplus >= 201703L
236  static constexpr bool is_always_lock_free
237  = __atomic_always_lock_free(sizeof(_M_i), 0);
238 #endif
239 
240  void
241  store(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept
242  { __atomic_store(std::__addressof(_M_i), std::__addressof(__i), int(__m)); }
243 
244  void
245  store(_Tp __i, memory_order __m = memory_order_seq_cst) volatile noexcept
246  { __atomic_store(std::__addressof(_M_i), std::__addressof(__i), int(__m)); }
247 
248  _Tp
249  load(memory_order __m = memory_order_seq_cst) const noexcept
250  {
251  alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
252  _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
253  __atomic_load(std::__addressof(_M_i), __ptr, int(__m));
254  return *__ptr;
255  }
256 
257  _Tp
258  load(memory_order __m = memory_order_seq_cst) const volatile noexcept
259  {
260  alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
261  _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
262  __atomic_load(std::__addressof(_M_i), __ptr, int(__m));
263  return *__ptr;
264  }
265 
266  _Tp
267  exchange(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept
268  {
269  alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
270  _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
271  __atomic_exchange(std::__addressof(_M_i), std::__addressof(__i),
272  __ptr, int(__m));
273  return *__ptr;
274  }
275 
276  _Tp
277  exchange(_Tp __i,
278  memory_order __m = memory_order_seq_cst) volatile noexcept
279  {
280  alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
281  _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
282  __atomic_exchange(std::__addressof(_M_i), std::__addressof(__i),
283  __ptr, int(__m));
284  return *__ptr;
285  }
286 
287  bool
288  compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s,
289  memory_order __f) noexcept
290  {
291  return __atomic_compare_exchange(std::__addressof(_M_i),
292  std::__addressof(__e),
293  std::__addressof(__i),
294  true, int(__s), int(__f));
295  }
296 
297  bool
298  compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s,
299  memory_order __f) volatile noexcept
300  {
301  return __atomic_compare_exchange(std::__addressof(_M_i),
302  std::__addressof(__e),
303  std::__addressof(__i),
304  true, int(__s), int(__f));
305  }
306 
307  bool
308  compare_exchange_weak(_Tp& __e, _Tp __i,
309  memory_order __m = memory_order_seq_cst) noexcept
310  { return compare_exchange_weak(__e, __i, __m,
311  __cmpexch_failure_order(__m)); }
312 
313  bool
314  compare_exchange_weak(_Tp& __e, _Tp __i,
315  memory_order __m = memory_order_seq_cst) volatile noexcept
316  { return compare_exchange_weak(__e, __i, __m,
317  __cmpexch_failure_order(__m)); }
318 
319  bool
320  compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s,
321  memory_order __f) noexcept
322  {
323  return __atomic_compare_exchange(std::__addressof(_M_i),
324  std::__addressof(__e),
325  std::__addressof(__i),
326  false, int(__s), int(__f));
327  }
328 
329  bool
330  compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s,
331  memory_order __f) volatile noexcept
332  {
333  return __atomic_compare_exchange(std::__addressof(_M_i),
334  std::__addressof(__e),
335  std::__addressof(__i),
336  false, int(__s), int(__f));
337  }
338 
339  bool
340  compare_exchange_strong(_Tp& __e, _Tp __i,
341  memory_order __m = memory_order_seq_cst) noexcept
342  { return compare_exchange_strong(__e, __i, __m,
343  __cmpexch_failure_order(__m)); }
344 
345  bool
346  compare_exchange_strong(_Tp& __e, _Tp __i,
347  memory_order __m = memory_order_seq_cst) volatile noexcept
348  { return compare_exchange_strong(__e, __i, __m,
349  __cmpexch_failure_order(__m)); }
350  };
351 
352 
353  /// Partial specialization for pointer types.
354  template<typename _Tp>
355  struct atomic<_Tp*>
356  {
357  using value_type = _Tp*;
358  using difference_type = ptrdiff_t;
359 
360  typedef _Tp* __pointer_type;
362  __base_type _M_b;
363 
364  atomic() noexcept = default;
365  ~atomic() noexcept = default;
366  atomic(const atomic&) = delete;
367  atomic& operator=(const atomic&) = delete;
368  atomic& operator=(const atomic&) volatile = delete;
369 
370  constexpr atomic(__pointer_type __p) noexcept : _M_b(__p) { }
371 
372  operator __pointer_type() const noexcept
373  { return __pointer_type(_M_b); }
374 
375  operator __pointer_type() const volatile noexcept
376  { return __pointer_type(_M_b); }
377 
378  __pointer_type
379  operator=(__pointer_type __p) noexcept
380  { return _M_b.operator=(__p); }
381 
382  __pointer_type
383  operator=(__pointer_type __p) volatile noexcept
384  { return _M_b.operator=(__p); }
385 
386  __pointer_type
387  operator++(int) noexcept
388  {
389 #if __cplusplus >= 201703L
390  static_assert( is_object<_Tp>::value, "pointer to object type" );
391 #endif
392  return _M_b++;
393  }
394 
395  __pointer_type
396  operator++(int) volatile noexcept
397  {
398 #if __cplusplus >= 201703L
399  static_assert( is_object<_Tp>::value, "pointer to object type" );
400 #endif
401  return _M_b++;
402  }
403 
404  __pointer_type
405  operator--(int) noexcept
406  {
407 #if __cplusplus >= 201703L
408  static_assert( is_object<_Tp>::value, "pointer to object type" );
409 #endif
410  return _M_b--;
411  }
412 
413  __pointer_type
414  operator--(int) volatile noexcept
415  {
416 #if __cplusplus >= 201703L
417  static_assert( is_object<_Tp>::value, "pointer to object type" );
418 #endif
419  return _M_b--;
420  }
421 
422  __pointer_type
423  operator++() noexcept
424  {
425 #if __cplusplus >= 201703L
426  static_assert( is_object<_Tp>::value, "pointer to object type" );
427 #endif
428  return ++_M_b;
429  }
430 
431  __pointer_type
432  operator++() volatile noexcept
433  {
434 #if __cplusplus >= 201703L
435  static_assert( is_object<_Tp>::value, "pointer to object type" );
436 #endif
437  return ++_M_b;
438  }
439 
440  __pointer_type
441  operator--() noexcept
442  {
443 #if __cplusplus >= 201703L
444  static_assert( is_object<_Tp>::value, "pointer to object type" );
445 #endif
446  return --_M_b;
447  }
448 
449  __pointer_type
450  operator--() volatile noexcept
451  {
452 #if __cplusplus >= 201703L
453  static_assert( is_object<_Tp>::value, "pointer to object type" );
454 #endif
455  return --_M_b;
456  }
457 
458  __pointer_type
459  operator+=(ptrdiff_t __d) noexcept
460  {
461 #if __cplusplus >= 201703L
462  static_assert( is_object<_Tp>::value, "pointer to object type" );
463 #endif
464  return _M_b.operator+=(__d);
465  }
466 
467  __pointer_type
468  operator+=(ptrdiff_t __d) volatile noexcept
469  {
470 #if __cplusplus >= 201703L
471  static_assert( is_object<_Tp>::value, "pointer to object type" );
472 #endif
473  return _M_b.operator+=(__d);
474  }
475 
476  __pointer_type
477  operator-=(ptrdiff_t __d) noexcept
478  {
479 #if __cplusplus >= 201703L
480  static_assert( is_object<_Tp>::value, "pointer to object type" );
481 #endif
482  return _M_b.operator-=(__d);
483  }
484 
485  __pointer_type
486  operator-=(ptrdiff_t __d) volatile noexcept
487  {
488 #if __cplusplus >= 201703L
489  static_assert( is_object<_Tp>::value, "pointer to object type" );
490 #endif
491  return _M_b.operator-=(__d);
492  }
493 
494  bool
495  is_lock_free() const noexcept
496  { return _M_b.is_lock_free(); }
497 
498  bool
499  is_lock_free() const volatile noexcept
500  { return _M_b.is_lock_free(); }
501 
502 #if __cplusplus >= 201703L
503  static constexpr bool is_always_lock_free = ATOMIC_POINTER_LOCK_FREE == 2;
504 #endif
505 
506  void
507  store(__pointer_type __p,
508  memory_order __m = memory_order_seq_cst) noexcept
509  { return _M_b.store(__p, __m); }
510 
511  void
512  store(__pointer_type __p,
513  memory_order __m = memory_order_seq_cst) volatile noexcept
514  { return _M_b.store(__p, __m); }
515 
516  __pointer_type
517  load(memory_order __m = memory_order_seq_cst) const noexcept
518  { return _M_b.load(__m); }
519 
520  __pointer_type
521  load(memory_order __m = memory_order_seq_cst) const volatile noexcept
522  { return _M_b.load(__m); }
523 
524  __pointer_type
525  exchange(__pointer_type __p,
526  memory_order __m = memory_order_seq_cst) noexcept
527  { return _M_b.exchange(__p, __m); }
528 
529  __pointer_type
530  exchange(__pointer_type __p,
531  memory_order __m = memory_order_seq_cst) volatile noexcept
532  { return _M_b.exchange(__p, __m); }
533 
534  bool
535  compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
536  memory_order __m1, memory_order __m2) noexcept
537  { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
538 
539  bool
540  compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
541  memory_order __m1,
542  memory_order __m2) volatile noexcept
543  { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
544 
545  bool
546  compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
547  memory_order __m = memory_order_seq_cst) noexcept
548  {
549  return compare_exchange_weak(__p1, __p2, __m,
550  __cmpexch_failure_order(__m));
551  }
552 
553  bool
554  compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
555  memory_order __m = memory_order_seq_cst) volatile noexcept
556  {
557  return compare_exchange_weak(__p1, __p2, __m,
558  __cmpexch_failure_order(__m));
559  }
560 
561  bool
562  compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
563  memory_order __m1, memory_order __m2) noexcept
564  { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
565 
566  bool
567  compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
568  memory_order __m1,
569  memory_order __m2) volatile noexcept
570  { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
571 
572  bool
573  compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
574  memory_order __m = memory_order_seq_cst) noexcept
575  {
576  return _M_b.compare_exchange_strong(__p1, __p2, __m,
577  __cmpexch_failure_order(__m));
578  }
579 
580  bool
581  compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
582  memory_order __m = memory_order_seq_cst) volatile noexcept
583  {
584  return _M_b.compare_exchange_strong(__p1, __p2, __m,
585  __cmpexch_failure_order(__m));
586  }
587 
588  __pointer_type
589  fetch_add(ptrdiff_t __d,
590  memory_order __m = memory_order_seq_cst) noexcept
591  {
592 #if __cplusplus >= 201703L
593  static_assert( is_object<_Tp>::value, "pointer to object type" );
594 #endif
595  return _M_b.fetch_add(__d, __m);
596  }
597 
598  __pointer_type
599  fetch_add(ptrdiff_t __d,
600  memory_order __m = memory_order_seq_cst) volatile noexcept
601  {
602 #if __cplusplus >= 201703L
603  static_assert( is_object<_Tp>::value, "pointer to object type" );
604 #endif
605  return _M_b.fetch_add(__d, __m);
606  }
607 
608  __pointer_type
609  fetch_sub(ptrdiff_t __d,
610  memory_order __m = memory_order_seq_cst) noexcept
611  {
612 #if __cplusplus >= 201703L
613  static_assert( is_object<_Tp>::value, "pointer to object type" );
614 #endif
615  return _M_b.fetch_sub(__d, __m);
616  }
617 
618  __pointer_type
619  fetch_sub(ptrdiff_t __d,
620  memory_order __m = memory_order_seq_cst) volatile noexcept
621  {
622 #if __cplusplus >= 201703L
623  static_assert( is_object<_Tp>::value, "pointer to object type" );
624 #endif
625  return _M_b.fetch_sub(__d, __m);
626  }
627  };
628 
629 
630  /// Explicit specialization for char.
631  template<>
632  struct atomic<char> : __atomic_base<char>
633  {
634  typedef char __integral_type;
636 
637  atomic() noexcept = default;
638  ~atomic() noexcept = default;
639  atomic(const atomic&) = delete;
640  atomic& operator=(const atomic&) = delete;
641  atomic& operator=(const atomic&) volatile = delete;
642 
643  constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
644 
645  using __base_type::operator __integral_type;
646  using __base_type::operator=;
647 
648 #if __cplusplus >= 201703L
649  static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
650 #endif
651  };
652 
653  /// Explicit specialization for signed char.
654  template<>
655  struct atomic<signed char> : __atomic_base<signed char>
656  {
657  typedef signed char __integral_type;
659 
660  atomic() noexcept= default;
661  ~atomic() noexcept = default;
662  atomic(const atomic&) = delete;
663  atomic& operator=(const atomic&) = delete;
664  atomic& operator=(const atomic&) volatile = delete;
665 
666  constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
667 
668  using __base_type::operator __integral_type;
669  using __base_type::operator=;
670 
671 #if __cplusplus >= 201703L
672  static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
673 #endif
674  };
675 
676  /// Explicit specialization for unsigned char.
677  template<>
678  struct atomic<unsigned char> : __atomic_base<unsigned char>
679  {
680  typedef unsigned char __integral_type;
682 
683  atomic() noexcept= default;
684  ~atomic() noexcept = default;
685  atomic(const atomic&) = delete;
686  atomic& operator=(const atomic&) = delete;
687  atomic& operator=(const atomic&) volatile = delete;
688 
689  constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
690 
691  using __base_type::operator __integral_type;
692  using __base_type::operator=;
693 
694 #if __cplusplus >= 201703L
695  static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
696 #endif
697  };
698 
699  /// Explicit specialization for short.
700  template<>
701  struct atomic<short> : __atomic_base<short>
702  {
703  typedef short __integral_type;
705 
706  atomic() noexcept = default;
707  ~atomic() noexcept = default;
708  atomic(const atomic&) = delete;
709  atomic& operator=(const atomic&) = delete;
710  atomic& operator=(const atomic&) volatile = delete;
711 
712  constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
713 
714  using __base_type::operator __integral_type;
715  using __base_type::operator=;
716 
717 #if __cplusplus >= 201703L
718  static constexpr bool is_always_lock_free = ATOMIC_SHORT_LOCK_FREE == 2;
719 #endif
720  };
721 
722  /// Explicit specialization for unsigned short.
723  template<>
724  struct atomic<unsigned short> : __atomic_base<unsigned short>
725  {
726  typedef unsigned short __integral_type;
728 
729  atomic() noexcept = default;
730  ~atomic() noexcept = default;
731  atomic(const atomic&) = delete;
732  atomic& operator=(const atomic&) = delete;
733  atomic& operator=(const atomic&) volatile = delete;
734 
735  constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
736 
737  using __base_type::operator __integral_type;
738  using __base_type::operator=;
739 
740 #if __cplusplus >= 201703L
741  static constexpr bool is_always_lock_free = ATOMIC_SHORT_LOCK_FREE == 2;
742 #endif
743  };
744 
745  /// Explicit specialization for int.
746  template<>
747  struct atomic<int> : __atomic_base<int>
748  {
749  typedef int __integral_type;
751 
752  atomic() noexcept = default;
753  ~atomic() noexcept = default;
754  atomic(const atomic&) = delete;
755  atomic& operator=(const atomic&) = delete;
756  atomic& operator=(const atomic&) volatile = delete;
757 
758  constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
759 
760  using __base_type::operator __integral_type;
761  using __base_type::operator=;
762 
763 #if __cplusplus >= 201703L
764  static constexpr bool is_always_lock_free = ATOMIC_INT_LOCK_FREE == 2;
765 #endif
766  };
767 
768  /// Explicit specialization for unsigned int.
769  template<>
770  struct atomic<unsigned int> : __atomic_base<unsigned int>
771  {
772  typedef unsigned int __integral_type;
774 
775  atomic() noexcept = default;
776  ~atomic() noexcept = default;
777  atomic(const atomic&) = delete;
778  atomic& operator=(const atomic&) = delete;
779  atomic& operator=(const atomic&) volatile = delete;
780 
781  constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
782 
783  using __base_type::operator __integral_type;
784  using __base_type::operator=;
785 
786 #if __cplusplus >= 201703L
787  static constexpr bool is_always_lock_free = ATOMIC_INT_LOCK_FREE == 2;
788 #endif
789  };
790 
791  /// Explicit specialization for long.
792  template<>
793  struct atomic<long> : __atomic_base<long>
794  {
795  typedef long __integral_type;
797 
798  atomic() noexcept = default;
799  ~atomic() noexcept = default;
800  atomic(const atomic&) = delete;
801  atomic& operator=(const atomic&) = delete;
802  atomic& operator=(const atomic&) volatile = delete;
803 
804  constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
805 
806  using __base_type::operator __integral_type;
807  using __base_type::operator=;
808 
809 #if __cplusplus >= 201703L
810  static constexpr bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2;
811 #endif
812  };
813 
814  /// Explicit specialization for unsigned long.
815  template<>
816  struct atomic<unsigned long> : __atomic_base<unsigned long>
817  {
818  typedef unsigned long __integral_type;
820 
821  atomic() noexcept = default;
822  ~atomic() noexcept = default;
823  atomic(const atomic&) = delete;
824  atomic& operator=(const atomic&) = delete;
825  atomic& operator=(const atomic&) volatile = delete;
826 
827  constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
828 
829  using __base_type::operator __integral_type;
830  using __base_type::operator=;
831 
832 #if __cplusplus >= 201703L
833  static constexpr bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2;
834 #endif
835  };
836 
837  /// Explicit specialization for long long.
838  template<>
839  struct atomic<long long> : __atomic_base<long long>
840  {
841  typedef long long __integral_type;
843 
844  atomic() noexcept = default;
845  ~atomic() noexcept = default;
846  atomic(const atomic&) = delete;
847  atomic& operator=(const atomic&) = delete;
848  atomic& operator=(const atomic&) volatile = delete;
849 
850  constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
851 
852  using __base_type::operator __integral_type;
853  using __base_type::operator=;
854 
855 #if __cplusplus >= 201703L
856  static constexpr bool is_always_lock_free = ATOMIC_LLONG_LOCK_FREE == 2;
857 #endif
858  };
859 
860  /// Explicit specialization for unsigned long long.
861  template<>
862  struct atomic<unsigned long long> : __atomic_base<unsigned long long>
863  {
864  typedef unsigned long long __integral_type;
866 
867  atomic() noexcept = default;
868  ~atomic() noexcept = default;
869  atomic(const atomic&) = delete;
870  atomic& operator=(const atomic&) = delete;
871  atomic& operator=(const atomic&) volatile = delete;
872 
873  constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
874 
875  using __base_type::operator __integral_type;
876  using __base_type::operator=;
877 
878 #if __cplusplus >= 201703L
879  static constexpr bool is_always_lock_free = ATOMIC_LLONG_LOCK_FREE == 2;
880 #endif
881  };
882 
883  /// Explicit specialization for wchar_t.
884  template<>
885  struct atomic<wchar_t> : __atomic_base<wchar_t>
886  {
887  typedef wchar_t __integral_type;
889 
890  atomic() noexcept = default;
891  ~atomic() noexcept = default;
892  atomic(const atomic&) = delete;
893  atomic& operator=(const atomic&) = delete;
894  atomic& operator=(const atomic&) volatile = delete;
895 
896  constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
897 
898  using __base_type::operator __integral_type;
899  using __base_type::operator=;
900 
901 #if __cplusplus >= 201703L
902  static constexpr bool is_always_lock_free = ATOMIC_WCHAR_T_LOCK_FREE == 2;
903 #endif
904  };
905 
906 #ifdef _GLIBCXX_USE_CHAR8_T
907  /// Explicit specialization for char8_t.
908  template<>
909  struct atomic<char8_t> : __atomic_base<char8_t>
910  {
911  typedef char8_t __integral_type;
912  typedef __atomic_base<char8_t> __base_type;
913 
914  atomic() noexcept = default;
915  ~atomic() noexcept = default;
916  atomic(const atomic&) = delete;
917  atomic& operator=(const atomic&) = delete;
918  atomic& operator=(const atomic&) volatile = delete;
919 
920  constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
921 
922  using __base_type::operator __integral_type;
923  using __base_type::operator=;
924 
925 #if __cplusplus > 201402L
926  static constexpr bool is_always_lock_free = ATOMIC_CHAR8_T_LOCK_FREE == 2;
927 #endif
928  };
929 #endif
930 
931  /// Explicit specialization for char16_t.
932  template<>
933  struct atomic<char16_t> : __atomic_base<char16_t>
934  {
935  typedef char16_t __integral_type;
937 
938  atomic() noexcept = default;
939  ~atomic() noexcept = default;
940  atomic(const atomic&) = delete;
941  atomic& operator=(const atomic&) = delete;
942  atomic& operator=(const atomic&) volatile = delete;
943 
944  constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
945 
946  using __base_type::operator __integral_type;
947  using __base_type::operator=;
948 
949 #if __cplusplus >= 201703L
950  static constexpr bool is_always_lock_free = ATOMIC_CHAR16_T_LOCK_FREE == 2;
951 #endif
952  };
953 
954  /// Explicit specialization for char32_t.
955  template<>
956  struct atomic<char32_t> : __atomic_base<char32_t>
957  {
958  typedef char32_t __integral_type;
960 
961  atomic() noexcept = default;
962  ~atomic() noexcept = default;
963  atomic(const atomic&) = delete;
964  atomic& operator=(const atomic&) = delete;
965  atomic& operator=(const atomic&) volatile = delete;
966 
967  constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
968 
969  using __base_type::operator __integral_type;
970  using __base_type::operator=;
971 
972 #if __cplusplus >= 201703L
973  static constexpr bool is_always_lock_free = ATOMIC_CHAR32_T_LOCK_FREE == 2;
974 #endif
975  };
976 
977 
978  /// atomic_bool
980 
981  /// atomic_char
983 
984  /// atomic_schar
986 
987  /// atomic_uchar
989 
990  /// atomic_short
992 
993  /// atomic_ushort
995 
996  /// atomic_int
998 
999  /// atomic_uint
1001 
1002  /// atomic_long
1004 
1005  /// atomic_ulong
1007 
1008  /// atomic_llong
1010 
1011  /// atomic_ullong
1013 
1014  /// atomic_wchar_t
1016 
1017 #ifdef _GLIBCXX_USE_CHAR8_T
1018  /// atomic_char8_t
1019  typedef atomic<char8_t> atomic_char8_t;
1020 #endif
1021 
1022  /// atomic_char16_t
1024 
1025  /// atomic_char32_t
1027 
1028 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
1029  // _GLIBCXX_RESOLVE_LIB_DEFECTS
1030  // 2441. Exact-width atomic typedefs should be provided
1031 
1032  /// atomic_int8_t
1034 
1035  /// atomic_uint8_t
1037 
1038  /// atomic_int16_t
1040 
1041  /// atomic_uint16_t
1043 
1044  /// atomic_int32_t
1046 
1047  /// atomic_uint32_t
1049 
1050  /// atomic_int64_t
1052 
1053  /// atomic_uint64_t
1055 
1056 
1057  /// atomic_int_least8_t
1059 
1060  /// atomic_uint_least8_t
1062 
1063  /// atomic_int_least16_t
1065 
1066  /// atomic_uint_least16_t
1068 
1069  /// atomic_int_least32_t
1071 
1072  /// atomic_uint_least32_t
1074 
1075  /// atomic_int_least64_t
1077 
1078  /// atomic_uint_least64_t
1080 
1081 
1082  /// atomic_int_fast8_t
1084 
1085  /// atomic_uint_fast8_t
1087 
1088  /// atomic_int_fast16_t
1090 
1091  /// atomic_uint_fast16_t
1093 
1094  /// atomic_int_fast32_t
1096 
1097  /// atomic_uint_fast32_t
1099 
1100  /// atomic_int_fast64_t
1102 
1103  /// atomic_uint_fast64_t
1105 #endif
1106 
1107 
1108  /// atomic_intptr_t
1110 
1111  /// atomic_uintptr_t
1113 
1114  /// atomic_size_t
1116 
1117  /// atomic_ptrdiff_t
1119 
1120 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
1121  /// atomic_intmax_t
1123 
1124  /// atomic_uintmax_t
1126 #endif
1127 
1128  // Function definitions, atomic_flag operations.
1129  inline bool
1130  atomic_flag_test_and_set_explicit(atomic_flag* __a,
1131  memory_order __m) noexcept
1132  { return __a->test_and_set(__m); }
1133 
1134  inline bool
1135  atomic_flag_test_and_set_explicit(volatile atomic_flag* __a,
1136  memory_order __m) noexcept
1137  { return __a->test_and_set(__m); }
1138 
1139  inline void
1140  atomic_flag_clear_explicit(atomic_flag* __a, memory_order __m) noexcept
1141  { __a->clear(__m); }
1142 
1143  inline void
1144  atomic_flag_clear_explicit(volatile atomic_flag* __a,
1145  memory_order __m) noexcept
1146  { __a->clear(__m); }
1147 
1148  inline bool
1149  atomic_flag_test_and_set(atomic_flag* __a) noexcept
1150  { return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
1151 
1152  inline bool
1153  atomic_flag_test_and_set(volatile atomic_flag* __a) noexcept
1154  { return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
1155 
1156  inline void
1157  atomic_flag_clear(atomic_flag* __a) noexcept
1158  { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
1159 
1160  inline void
1161  atomic_flag_clear(volatile atomic_flag* __a) noexcept
1162  { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
1163 
1164 
1165  template<typename _Tp>
1166  using __atomic_val_t = typename atomic<_Tp>::value_type;
1167  template<typename _Tp>
1168  using __atomic_diff_t = typename atomic<_Tp>::difference_type;
1169 
1170  // [atomics.nonmembers] Non-member functions.
1171  // Function templates generally applicable to atomic types.
1172  template<typename _ITp>
1173  inline bool
1174  atomic_is_lock_free(const atomic<_ITp>* __a) noexcept
1175  { return __a->is_lock_free(); }
1176 
1177  template<typename _ITp>
1178  inline bool
1179  atomic_is_lock_free(const volatile atomic<_ITp>* __a) noexcept
1180  { return __a->is_lock_free(); }
1181 
1182  template<typename _ITp>
1183  inline void
1184  atomic_init(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1185  { __a->store(__i, memory_order_relaxed); }
1186 
1187  template<typename _ITp>
1188  inline void
1189  atomic_init(volatile atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1190  { __a->store(__i, memory_order_relaxed); }
1191 
1192  template<typename _ITp>
1193  inline void
1194  atomic_store_explicit(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1195  memory_order __m) noexcept
1196  { __a->store(__i, __m); }
1197 
1198  template<typename _ITp>
1199  inline void
1200  atomic_store_explicit(volatile atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1201  memory_order __m) noexcept
1202  { __a->store(__i, __m); }
1203 
1204  template<typename _ITp>
1205  inline _ITp
1206  atomic_load_explicit(const atomic<_ITp>* __a, memory_order __m) noexcept
1207  { return __a->load(__m); }
1208 
1209  template<typename _ITp>
1210  inline _ITp
1211  atomic_load_explicit(const volatile atomic<_ITp>* __a,
1212  memory_order __m) noexcept
1213  { return __a->load(__m); }
1214 
1215  template<typename _ITp>
1216  inline _ITp
1217  atomic_exchange_explicit(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i,
1218  memory_order __m) noexcept
1219  { return __a->exchange(__i, __m); }
1220 
1221  template<typename _ITp>
1222  inline _ITp
1223  atomic_exchange_explicit(volatile atomic<_ITp>* __a,
1224  __atomic_val_t<_ITp> __i,
1225  memory_order __m) noexcept
1226  { return __a->exchange(__i, __m); }
1227 
1228  template<typename _ITp>
1229  inline bool
1230  atomic_compare_exchange_weak_explicit(atomic<_ITp>* __a,
1231  __atomic_val_t<_ITp>* __i1,
1232  __atomic_val_t<_ITp> __i2,
1233  memory_order __m1,
1234  memory_order __m2) noexcept
1235  { return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
1236 
1237  template<typename _ITp>
1238  inline bool
1239  atomic_compare_exchange_weak_explicit(volatile atomic<_ITp>* __a,
1240  __atomic_val_t<_ITp>* __i1,
1241  __atomic_val_t<_ITp> __i2,
1242  memory_order __m1,
1243  memory_order __m2) noexcept
1244  { return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
1245 
1246  template<typename _ITp>
1247  inline bool
1248  atomic_compare_exchange_strong_explicit(atomic<_ITp>* __a,
1249  __atomic_val_t<_ITp>* __i1,
1250  __atomic_val_t<_ITp> __i2,
1251  memory_order __m1,
1252  memory_order __m2) noexcept
1253  { return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
1254 
1255  template<typename _ITp>
1256  inline bool
1257  atomic_compare_exchange_strong_explicit(volatile atomic<_ITp>* __a,
1258  __atomic_val_t<_ITp>* __i1,
1259  __atomic_val_t<_ITp> __i2,
1260  memory_order __m1,
1261  memory_order __m2) noexcept
1262  { return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
1263 
1264 
1265  template<typename _ITp>
1266  inline void
1267  atomic_store(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1268  { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
1269 
1270  template<typename _ITp>
1271  inline void
1272  atomic_store(volatile atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1273  { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
1274 
1275  template<typename _ITp>
1276  inline _ITp
1277  atomic_load(const atomic<_ITp>* __a) noexcept
1278  { return atomic_load_explicit(__a, memory_order_seq_cst); }
1279 
1280  template<typename _ITp>
1281  inline _ITp
1282  atomic_load(const volatile atomic<_ITp>* __a) noexcept
1283  { return atomic_load_explicit(__a, memory_order_seq_cst); }
1284 
1285  template<typename _ITp>
1286  inline _ITp
1287  atomic_exchange(atomic<_ITp>* __a, __atomic_val_t<_ITp> __i) noexcept
1288  { return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
1289 
1290  template<typename _ITp>
1291  inline _ITp
1292  atomic_exchange(volatile atomic<_ITp>* __a,
1293  __atomic_val_t<_ITp> __i) noexcept
1294  { return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
1295 
1296  template<typename _ITp>
1297  inline bool
1298  atomic_compare_exchange_weak(atomic<_ITp>* __a,
1299  __atomic_val_t<_ITp>* __i1,
1300  __atomic_val_t<_ITp> __i2) noexcept
1301  {
1302  return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
1303  memory_order_seq_cst,
1304  memory_order_seq_cst);
1305  }
1306 
1307  template<typename _ITp>
1308  inline bool
1309  atomic_compare_exchange_weak(volatile atomic<_ITp>* __a,
1310  __atomic_val_t<_ITp>* __i1,
1311  __atomic_val_t<_ITp> __i2) noexcept
1312  {
1313  return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
1314  memory_order_seq_cst,
1315  memory_order_seq_cst);
1316  }
1317 
1318  template<typename _ITp>
1319  inline bool
1320  atomic_compare_exchange_strong(atomic<_ITp>* __a,
1321  __atomic_val_t<_ITp>* __i1,
1322  __atomic_val_t<_ITp> __i2) noexcept
1323  {
1324  return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
1325  memory_order_seq_cst,
1326  memory_order_seq_cst);
1327  }
1328 
1329  template<typename _ITp>
1330  inline bool
1331  atomic_compare_exchange_strong(volatile atomic<_ITp>* __a,
1332  __atomic_val_t<_ITp>* __i1,
1333  __atomic_val_t<_ITp> __i2) noexcept
1334  {
1335  return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
1336  memory_order_seq_cst,
1337  memory_order_seq_cst);
1338  }
1339 
1340  // Function templates for atomic_integral and atomic_pointer operations only.
1341  // Some operations (and, or, xor) are only available for atomic integrals,
1342  // which is implemented by taking a parameter of type __atomic_base<_ITp>*.
1343 
1344  template<typename _ITp>
1345  inline _ITp
1346  atomic_fetch_add_explicit(atomic<_ITp>* __a,
1347  __atomic_diff_t<_ITp> __i,
1348  memory_order __m) noexcept
1349  { return __a->fetch_add(__i, __m); }
1350 
1351  template<typename _ITp>
1352  inline _ITp
1353  atomic_fetch_add_explicit(volatile atomic<_ITp>* __a,
1354  __atomic_diff_t<_ITp> __i,
1355  memory_order __m) noexcept
1356  { return __a->fetch_add(__i, __m); }
1357 
1358  template<typename _ITp>
1359  inline _ITp
1360  atomic_fetch_sub_explicit(atomic<_ITp>* __a,
1361  __atomic_diff_t<_ITp> __i,
1362  memory_order __m) noexcept
1363  { return __a->fetch_sub(__i, __m); }
1364 
1365  template<typename _ITp>
1366  inline _ITp
1367  atomic_fetch_sub_explicit(volatile atomic<_ITp>* __a,
1368  __atomic_diff_t<_ITp> __i,
1369  memory_order __m) noexcept
1370  { return __a->fetch_sub(__i, __m); }
1371 
1372  template<typename _ITp>
1373  inline _ITp
1374  atomic_fetch_and_explicit(__atomic_base<_ITp>* __a,
1375  __atomic_val_t<_ITp> __i,
1376  memory_order __m) noexcept
1377  { return __a->fetch_and(__i, __m); }
1378 
1379  template<typename _ITp>
1380  inline _ITp
1381  atomic_fetch_and_explicit(volatile __atomic_base<_ITp>* __a,
1382  __atomic_val_t<_ITp> __i,
1383  memory_order __m) noexcept
1384  { return __a->fetch_and(__i, __m); }
1385 
1386  template<typename _ITp>
1387  inline _ITp
1388  atomic_fetch_or_explicit(__atomic_base<_ITp>* __a,
1389  __atomic_val_t<_ITp> __i,
1390  memory_order __m) noexcept
1391  { return __a->fetch_or(__i, __m); }
1392 
1393  template<typename _ITp>
1394  inline _ITp
1395  atomic_fetch_or_explicit(volatile __atomic_base<_ITp>* __a,
1396  __atomic_val_t<_ITp> __i,
1397  memory_order __m) noexcept
1398  { return __a->fetch_or(__i, __m); }
1399 
1400  template<typename _ITp>
1401  inline _ITp
1402  atomic_fetch_xor_explicit(__atomic_base<_ITp>* __a,
1403  __atomic_val_t<_ITp> __i,
1404  memory_order __m) noexcept
1405  { return __a->fetch_xor(__i, __m); }
1406 
1407  template<typename _ITp>
1408  inline _ITp
1409  atomic_fetch_xor_explicit(volatile __atomic_base<_ITp>* __a,
1410  __atomic_val_t<_ITp> __i,
1411  memory_order __m) noexcept
1412  { return __a->fetch_xor(__i, __m); }
1413 
1414  template<typename _ITp>
1415  inline _ITp
1416  atomic_fetch_add(atomic<_ITp>* __a,
1417  __atomic_diff_t<_ITp> __i) noexcept
1418  { return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
1419 
1420  template<typename _ITp>
1421  inline _ITp
1422  atomic_fetch_add(volatile atomic<_ITp>* __a,
1423  __atomic_diff_t<_ITp> __i) noexcept
1424  { return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
1425 
1426  template<typename _ITp>
1427  inline _ITp
1428  atomic_fetch_sub(atomic<_ITp>* __a,
1429  __atomic_diff_t<_ITp> __i) noexcept
1430  { return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
1431 
1432  template<typename _ITp>
1433  inline _ITp
1434  atomic_fetch_sub(volatile atomic<_ITp>* __a,
1435  __atomic_diff_t<_ITp> __i) noexcept
1436  { return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
1437 
1438  template<typename _ITp>
1439  inline _ITp
1440  atomic_fetch_and(__atomic_base<_ITp>* __a,
1441  __atomic_val_t<_ITp> __i) noexcept
1442  { return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
1443 
1444  template<typename _ITp>
1445  inline _ITp
1446  atomic_fetch_and(volatile __atomic_base<_ITp>* __a,
1447  __atomic_val_t<_ITp> __i) noexcept
1448  { return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
1449 
1450  template<typename _ITp>
1451  inline _ITp
1452  atomic_fetch_or(__atomic_base<_ITp>* __a,
1453  __atomic_val_t<_ITp> __i) noexcept
1454  { return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
1455 
1456  template<typename _ITp>
1457  inline _ITp
1458  atomic_fetch_or(volatile __atomic_base<_ITp>* __a,
1459  __atomic_val_t<_ITp> __i) noexcept
1460  { return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
1461 
1462  template<typename _ITp>
1463  inline _ITp
1464  atomic_fetch_xor(__atomic_base<_ITp>* __a,
1465  __atomic_val_t<_ITp> __i) noexcept
1466  { return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
1467 
1468  template<typename _ITp>
1469  inline _ITp
1470  atomic_fetch_xor(volatile __atomic_base<_ITp>* __a,
1471  __atomic_val_t<_ITp> __i) noexcept
1472  { return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
1473 
1474 #if __cplusplus > 201703L
1475  template<>
1476  struct atomic<float> : __atomic_float<float>
1477  {
1478  atomic() noexcept = default;
1479 
1480  constexpr
1481  atomic(float __fp) noexcept : __atomic_float<float>(__fp)
1482  { }
1483 
1484  atomic& operator=(const atomic&) volatile = delete;
1485  atomic& operator=(const atomic&) = delete;
1486 
1487  using __atomic_float<float>::operator=;
1488  };
1489 
1490  template<>
1491  struct atomic<double> : __atomic_float<double>
1492  {
1493  atomic() noexcept = default;
1494 
1495  constexpr
1496  atomic(double __fp) noexcept : __atomic_float<double>(__fp)
1497  { }
1498 
1499  atomic& operator=(const atomic&) volatile = delete;
1500  atomic& operator=(const atomic&) = delete;
1501 
1502  using __atomic_float<double>::operator=;
1503  };
1504 
1505  template<>
1506  struct atomic<long double> : __atomic_float<long double>
1507  {
1508  atomic() noexcept = default;
1509 
1510  constexpr
1511  atomic(long double __fp) noexcept : __atomic_float<long double>(__fp)
1512  { }
1513 
1514  atomic& operator=(const atomic&) volatile = delete;
1515  atomic& operator=(const atomic&) = delete;
1516 
1517  using __atomic_float<long double>::operator=;
1518  };
1519 
1520 #define __cpp_lib_atomic_ref 201806L
1521 
1522  /// Class template to provide atomic operations on a non-atomic variable.
1523  template<typename _Tp>
1524  struct atomic_ref : __atomic_ref<_Tp>
1525  {
1526  explicit
1527  atomic_ref(_Tp& __t) noexcept : __atomic_ref<_Tp>(__t)
1528  { }
1529 
1530  atomic_ref& operator=(const atomic_ref&) = delete;
1531 
1532  atomic_ref(const atomic_ref&) = default;
1533 
1534  using __atomic_ref<_Tp>::operator=;
1535  };
1536 
1537 #endif // C++2a
1538 
1539  // @} group atomics
1540 
1541 _GLIBCXX_END_NAMESPACE_VERSION
1542 } // namespace
1543 
1544 #endif // C++11
1545 
1546 #endif // _GLIBCXX_ATOMIC
std::atomic_bool
atomic< bool > atomic_bool
atomic_bool
Definition: atomic:979
std::atomic_ulong
atomic< unsigned long > atomic_ulong
atomic_ulong
Definition: atomic:1006
std::atomic_wchar_t
atomic< wchar_t > atomic_wchar_t
atomic_wchar_t
Definition: atomic:1015
std::atomic_uint_fast8_t
atomic< uint_fast8_t > atomic_uint_fast8_t
atomic_uint_fast8_t
Definition: atomic:1086
std::atomic< char32_t >
Explicit specialization for char32_t.
Definition: atomic:956
std::atomic_schar
atomic< signed char > atomic_schar
atomic_schar
Definition: atomic:985
std::atomic_uint_fast32_t
atomic< uint_fast32_t > atomic_uint_fast32_t
atomic_uint_fast32_t
Definition: atomic:1098
std::atomic_int_least64_t
atomic< int_least64_t > atomic_int_least64_t
atomic_int_least64_t
Definition: atomic:1076
std::__addressof
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
Definition: move.h:49
std::atomic_uint32_t
atomic< uint32_t > atomic_uint32_t
atomic_uint32_t
Definition: atomic:1048
std::atomic_flag
atomic_flag
Definition: atomic_base.h:180
std::atomic_int_least32_t
atomic< int_least32_t > atomic_int_least32_t
atomic_int_least32_t
Definition: atomic:1070
std::atomic_uintptr_t
atomic< uintptr_t > atomic_uintptr_t
atomic_uintptr_t
Definition: atomic:1112
std::atomic< unsigned long >
Explicit specialization for unsigned long.
Definition: atomic:816
std::atomic< unsigned short >
Explicit specialization for unsigned short.
Definition: atomic:724
std::atomic_int_fast16_t
atomic< int_fast16_t > atomic_int_fast16_t
atomic_int_fast16_t
Definition: atomic:1089
std::atomic_char16_t
atomic< char16_t > atomic_char16_t
atomic_char16_t
Definition: atomic:1023
std::atomic< char16_t >
Explicit specialization for char16_t.
Definition: atomic:933
std::atomic_int_least16_t
atomic< int_least16_t > atomic_int_least16_t
atomic_int_least16_t
Definition: atomic:1064
std::atomic< signed char >
Explicit specialization for signed char.
Definition: atomic:655
atomic_base.h
std
ISO C++ entities toplevel namespace is std.
std::atomic< unsigned long long >
Explicit specialization for unsigned long long.
Definition: atomic:862
std::atomic< long >
Explicit specialization for long.
Definition: atomic:793
std::atomic_intmax_t
atomic< intmax_t > atomic_intmax_t
atomic_intmax_t
Definition: atomic:1122
std::atomic_uint16_t
atomic< uint16_t > atomic_uint16_t
atomic_uint16_t
Definition: atomic:1042
std::atomic_ushort
atomic< unsigned short > atomic_ushort
atomic_ushort
Definition: atomic:994
std::atomic_uint_least64_t
atomic< uint_least64_t > atomic_uint_least64_t
atomic_uint_least64_t
Definition: atomic:1079
std::atomic_int_fast64_t
atomic< int_fast64_t > atomic_int_fast64_t
atomic_int_fast64_t
Definition: atomic:1101
ATOMIC_BOOL_LOCK_FREE
#define ATOMIC_BOOL_LOCK_FREE
Definition: atomic_lockfree_defines.h:49
std::atomic_ptrdiff_t
atomic< ptrdiff_t > atomic_ptrdiff_t
atomic_ptrdiff_t
Definition: atomic:1118
std::exchange
constexpr _Tp exchange(_Tp &__obj, _Up &&__new_val)
Assign __new_val to __obj and return its previous value.
Definition: utility:291
std::atomic_uint8_t
atomic< uint8_t > atomic_uint8_t
atomic_uint8_t
Definition: atomic:1036
std::atomic_int_fast8_t
atomic< int_fast8_t > atomic_int_fast8_t
atomic_int_fast8_t
Definition: atomic:1083
std::atomic< short >
Explicit specialization for short.
Definition: atomic:701
std::atomic_size_t
atomic< size_t > atomic_size_t
atomic_size_t
Definition: atomic:1115
std::atomic_char
atomic< char > atomic_char
atomic_char
Definition: atomic:982
std::atomic_ullong
atomic< unsigned long long > atomic_ullong
atomic_ullong
Definition: atomic:1012
std::atomic_int8_t
atomic< int8_t > atomic_int8_t
atomic_int8_t
Definition: atomic:1033
std::atomic_intptr_t
atomic< intptr_t > atomic_intptr_t
atomic_intptr_t
Definition: atomic:1109
std::atomic< bool >
atomic<bool>
Definition: atomic:62
std::atomic< int >
Explicit specialization for int.
Definition: atomic:747
std::atomic< unsigned char >
Explicit specialization for unsigned char.
Definition: atomic:678
std::is_object
is_object
Definition: type_traits:547
std::atomic_char32_t
atomic< char32_t > atomic_char32_t
atomic_char32_t
Definition: atomic:1026
std::memory_order
memory_order
Enumeration for memory_order.
Definition: atomic_base.h:74
std::atomic_uint_fast64_t
atomic< uint_fast64_t > atomic_uint_fast64_t
atomic_uint_fast64_t
Definition: atomic:1104
std::atomic_int64_t
atomic< int64_t > atomic_int64_t
atomic_int64_t
Definition: atomic:1051
std::atomic< char >
Explicit specialization for char.
Definition: atomic:632
std::atomic
Generic atomic type, primary class template.
Definition: atomic:57
std::atomic_short
atomic< short > atomic_short
atomic_short
Definition: atomic:991
std::atomic_uintmax_t
atomic< uintmax_t > atomic_uintmax_t
atomic_uintmax_t
Definition: atomic:1125
std::atomic_int32_t
atomic< int32_t > atomic_int32_t
atomic_int32_t
Definition: atomic:1045
std::atomic< wchar_t >
Explicit specialization for wchar_t.
Definition: atomic:885
std::atomic_uint_least32_t
atomic< uint_least32_t > atomic_uint_least32_t
atomic_uint_least32_t
Definition: atomic:1073
std::atomic_int_fast32_t
atomic< int_fast32_t > atomic_int_fast32_t
atomic_int_fast32_t
Definition: atomic:1095
std::atomic_uint_fast16_t
atomic< uint_fast16_t > atomic_uint_fast16_t
atomic_uint_fast16_t
Definition: atomic:1092
std::atomic_uint_least8_t
atomic< uint_least8_t > atomic_uint_least8_t
atomic_uint_least8_t
Definition: atomic:1061
std::atomic_uint64_t
atomic< uint64_t > atomic_uint64_t
atomic_uint64_t
Definition: atomic:1054
c++0x_warning.h
std::atomic_int16_t
atomic< int16_t > atomic_int16_t
atomic_int16_t
Definition: atomic:1039
std::atomic_llong
atomic< long long > atomic_llong
atomic_llong
Definition: atomic:1009
std::atomic_long
atomic< long > atomic_long
atomic_long
Definition: atomic:1003
std::__atomic_base< bool >
std::atomic< long long >
Explicit specialization for long long.
Definition: atomic:839
std::atomic_uint_least16_t
atomic< uint_least16_t > atomic_uint_least16_t
atomic_uint_least16_t
Definition: atomic:1067
std::atomic< unsigned int >
Explicit specialization for unsigned int.
Definition: atomic:770
std::atomic_uchar
atomic< unsigned char > atomic_uchar
atomic_uchar
Definition: atomic:988
std::atomic_int
atomic< int > atomic_int
atomic_int
Definition: atomic:997
std::atomic_int_least8_t
atomic< int_least8_t > atomic_int_least8_t
atomic_int_least8_t
Definition: atomic:1058
std::atomic_uint
atomic< unsigned int > atomic_uint
atomic_uint
Definition: atomic:1000