30 #ifndef _GLIBCXX_ATOMIC_BASE_H
31 #define _GLIBCXX_ATOMIC_BASE_H 1
33 #pragma GCC system_header
40 namespace std _GLIBCXX_VISIBILITY(default)
42 _GLIBCXX_BEGIN_NAMESPACE_VERSION
66 return __m == memory_order_acq_rel ? memory_order_acquire
67 : __m == memory_order_release ? memory_order_relaxed : __m;
72 { __atomic_thread_fence(__m); }
76 { __atomic_signal_fence(__m); }
79 template<
typename _Tp>
89 template<
typename _IntTp>
207 #define ATOMIC_VAR_INIT(_VI) { _VI }
209 template<
typename _Tp>
212 template<
typename _Tp>
216 #if __GCC_ATOMIC_TEST_AND_SET_TRUEVAL == 1
217 typedef bool __atomic_flag_data_type;
219 typedef unsigned char __atomic_flag_data_type;
232 _GLIBCXX_BEGIN_EXTERN_C
236 __atomic_flag_data_type _M_i;
239 _GLIBCXX_END_EXTERN_C
241 #define ATOMIC_FLAG_INIT { 0 }
258 test_and_set(
memory_order __m = memory_order_seq_cst) noexcept
260 return __atomic_test_and_set (&_M_i, __m);
264 test_and_set(
memory_order __m = memory_order_seq_cst)
volatile noexcept
266 return __atomic_test_and_set (&_M_i, __m);
272 __glibcxx_assert(__m != memory_order_consume);
273 __glibcxx_assert(__m != memory_order_acquire);
274 __glibcxx_assert(__m != memory_order_acq_rel);
276 __atomic_clear (&_M_i, __m);
280 clear(
memory_order __m = memory_order_seq_cst)
volatile noexcept
282 __glibcxx_assert(__m != memory_order_consume);
283 __glibcxx_assert(__m != memory_order_acquire);
284 __glibcxx_assert(__m != memory_order_acq_rel);
286 __atomic_clear (&_M_i, __m);
290 static constexpr __atomic_flag_data_type
292 {
return __i ? __GCC_ATOMIC_TEST_AND_SET_TRUEVAL : 0; }
319 template<
typename _ITp>
323 typedef _ITp __int_type;
335 constexpr
__atomic_base(__int_type __i) noexcept : _M_i (__i) { }
337 operator __int_type() const noexcept
340 operator __int_type() const volatile noexcept
344 operator=(__int_type __i) noexcept
351 operator=(__int_type __i)
volatile noexcept
358 operator++(
int) noexcept
359 {
return fetch_add(1); }
362 operator++(
int) volatile noexcept
363 {
return fetch_add(1); }
366 operator--(
int) noexcept
367 {
return fetch_sub(1); }
370 operator--(
int) volatile noexcept
371 {
return fetch_sub(1); }
374 operator++() noexcept
375 {
return __atomic_add_fetch(&_M_i, 1, memory_order_seq_cst); }
378 operator++() volatile noexcept
379 {
return __atomic_add_fetch(&_M_i, 1, memory_order_seq_cst); }
382 operator--() noexcept
383 {
return __atomic_sub_fetch(&_M_i, 1, memory_order_seq_cst); }
386 operator--() volatile noexcept
387 {
return __atomic_sub_fetch(&_M_i, 1, memory_order_seq_cst); }
390 operator+=(__int_type __i) noexcept
391 {
return __atomic_add_fetch(&_M_i, __i, memory_order_seq_cst); }
394 operator+=(__int_type __i)
volatile noexcept
395 {
return __atomic_add_fetch(&_M_i, __i, memory_order_seq_cst); }
398 operator-=(__int_type __i) noexcept
399 {
return __atomic_sub_fetch(&_M_i, __i, memory_order_seq_cst); }
402 operator-=(__int_type __i)
volatile noexcept
403 {
return __atomic_sub_fetch(&_M_i, __i, memory_order_seq_cst); }
406 operator&=(__int_type __i) noexcept
407 {
return __atomic_and_fetch(&_M_i, __i, memory_order_seq_cst); }
410 operator&=(__int_type __i)
volatile noexcept
411 {
return __atomic_and_fetch(&_M_i, __i, memory_order_seq_cst); }
414 operator|=(__int_type __i) noexcept
415 {
return __atomic_or_fetch(&_M_i, __i, memory_order_seq_cst); }
418 operator|=(__int_type __i)
volatile noexcept
419 {
return __atomic_or_fetch(&_M_i, __i, memory_order_seq_cst); }
422 operator^=(__int_type __i) noexcept
423 {
return __atomic_xor_fetch(&_M_i, __i, memory_order_seq_cst); }
426 operator^=(__int_type __i)
volatile noexcept
427 {
return __atomic_xor_fetch(&_M_i, __i, memory_order_seq_cst); }
430 is_lock_free() const noexcept
431 {
return __atomic_is_lock_free (
sizeof (_M_i), &_M_i); }
434 is_lock_free() const volatile noexcept
435 {
return __atomic_is_lock_free (
sizeof (_M_i), &_M_i); }
438 store(__int_type __i,
memory_order __m = memory_order_seq_cst) noexcept
440 __glibcxx_assert(__m != memory_order_acquire);
441 __glibcxx_assert(__m != memory_order_acq_rel);
442 __glibcxx_assert(__m != memory_order_consume);
444 __atomic_store_n(&_M_i, __i, __m);
448 store(__int_type __i,
449 memory_order __m = memory_order_seq_cst) volatile noexcept
451 __glibcxx_assert(__m != memory_order_acquire);
452 __glibcxx_assert(__m != memory_order_acq_rel);
453 __glibcxx_assert(__m != memory_order_consume);
455 __atomic_store_n(&_M_i, __i, __m);
459 load(
memory_order __m = memory_order_seq_cst) const noexcept
461 __glibcxx_assert(__m != memory_order_release);
462 __glibcxx_assert(__m != memory_order_acq_rel);
464 return __atomic_load_n(&_M_i, __m);
468 load(
memory_order __m = memory_order_seq_cst) const volatile noexcept
470 __glibcxx_assert(__m != memory_order_release);
471 __glibcxx_assert(__m != memory_order_acq_rel);
473 return __atomic_load_n(&_M_i, __m);
477 exchange(__int_type __i,
480 return __atomic_exchange_n(&_M_i, __i, __m);
485 exchange(__int_type __i,
486 memory_order __m = memory_order_seq_cst) volatile noexcept
488 return __atomic_exchange_n(&_M_i, __i, __m);
492 compare_exchange_weak(__int_type& __i1, __int_type __i2,
495 __glibcxx_assert(__m2 != memory_order_release);
496 __glibcxx_assert(__m2 != memory_order_acq_rel);
497 __glibcxx_assert(__m2 <= __m1);
499 return __atomic_compare_exchange_n(&_M_i, &__i1, __i2, 1, __m1, __m2);
503 compare_exchange_weak(__int_type& __i1, __int_type __i2,
507 __glibcxx_assert(__m2 != memory_order_release);
508 __glibcxx_assert(__m2 != memory_order_acq_rel);
509 __glibcxx_assert(__m2 <= __m1);
511 return __atomic_compare_exchange_n(&_M_i, &__i1, __i2, 1, __m1, __m2);
515 compare_exchange_weak(__int_type& __i1, __int_type __i2,
518 return compare_exchange_weak(__i1, __i2, __m,
519 __cmpexch_failure_order(__m));
523 compare_exchange_weak(__int_type& __i1, __int_type __i2,
524 memory_order __m = memory_order_seq_cst) volatile noexcept
526 return compare_exchange_weak(__i1, __i2, __m,
527 __cmpexch_failure_order(__m));
531 compare_exchange_strong(__int_type& __i1, __int_type __i2,
534 __glibcxx_assert(__m2 != memory_order_release);
535 __glibcxx_assert(__m2 != memory_order_acq_rel);
536 __glibcxx_assert(__m2 <= __m1);
538 return __atomic_compare_exchange_n(&_M_i, &__i1, __i2, 0, __m1, __m2);
542 compare_exchange_strong(__int_type& __i1, __int_type __i2,
546 __glibcxx_assert(__m2 != memory_order_release);
547 __glibcxx_assert(__m2 != memory_order_acq_rel);
548 __glibcxx_assert(__m2 <= __m1);
550 return __atomic_compare_exchange_n(&_M_i, &__i1, __i2, 0, __m1, __m2);
554 compare_exchange_strong(__int_type& __i1, __int_type __i2,
557 return compare_exchange_strong(__i1, __i2, __m,
558 __cmpexch_failure_order(__m));
562 compare_exchange_strong(__int_type& __i1, __int_type __i2,
563 memory_order __m = memory_order_seq_cst) volatile noexcept
565 return compare_exchange_strong(__i1, __i2, __m,
566 __cmpexch_failure_order(__m));
570 fetch_add(__int_type __i,
572 {
return __atomic_fetch_add(&_M_i, __i, __m); }
575 fetch_add(__int_type __i,
576 memory_order __m = memory_order_seq_cst) volatile noexcept
577 {
return __atomic_fetch_add(&_M_i, __i, __m); }
580 fetch_sub(__int_type __i,
582 {
return __atomic_fetch_sub(&_M_i, __i, __m); }
585 fetch_sub(__int_type __i,
586 memory_order __m = memory_order_seq_cst) volatile noexcept
587 {
return __atomic_fetch_sub(&_M_i, __i, __m); }
590 fetch_and(__int_type __i,
592 {
return __atomic_fetch_and(&_M_i, __i, __m); }
595 fetch_and(__int_type __i,
596 memory_order __m = memory_order_seq_cst) volatile noexcept
597 {
return __atomic_fetch_and(&_M_i, __i, __m); }
600 fetch_or(__int_type __i,
602 {
return __atomic_fetch_or(&_M_i, __i, __m); }
605 fetch_or(__int_type __i,
606 memory_order __m = memory_order_seq_cst) volatile noexcept
607 {
return __atomic_fetch_or(&_M_i, __i, __m); }
610 fetch_xor(__int_type __i,
612 {
return __atomic_fetch_xor(&_M_i, __i, __m); }
615 fetch_xor(__int_type __i,
616 memory_order __m = memory_order_seq_cst) volatile noexcept
617 {
return __atomic_fetch_xor(&_M_i, __i, __m); }
622 template<
typename _PTp>
626 typedef _PTp* __pointer_type;
632 _M_type_size(ptrdiff_t __d) {
return __d *
sizeof(_PTp); }
635 _M_type_size(ptrdiff_t __d)
volatile {
return __d *
sizeof(_PTp); }
645 constexpr
__atomic_base(__pointer_type __p) noexcept : _M_p (__p) { }
647 operator __pointer_type()
const noexcept
650 operator __pointer_type()
const volatile noexcept
654 operator=(__pointer_type __p) noexcept
661 operator=(__pointer_type __p)
volatile noexcept
668 operator++(
int) noexcept
669 {
return fetch_add(1); }
672 operator++(
int)
volatile noexcept
673 {
return fetch_add(1); }
676 operator--(
int) noexcept
677 {
return fetch_sub(1); }
680 operator--(
int)
volatile noexcept
681 {
return fetch_sub(1); }
684 operator++() noexcept
685 {
return __atomic_add_fetch(&_M_p, _M_type_size(1),
686 memory_order_seq_cst); }
689 operator++()
volatile noexcept
690 {
return __atomic_add_fetch(&_M_p, _M_type_size(1),
691 memory_order_seq_cst); }
694 operator--() noexcept
695 {
return __atomic_sub_fetch(&_M_p, _M_type_size(1),
696 memory_order_seq_cst); }
699 operator--()
volatile noexcept
700 {
return __atomic_sub_fetch(&_M_p, _M_type_size(1),
701 memory_order_seq_cst); }
704 operator+=(ptrdiff_t __d) noexcept
705 {
return __atomic_add_fetch(&_M_p, _M_type_size(__d),
706 memory_order_seq_cst); }
709 operator+=(ptrdiff_t __d)
volatile noexcept
710 {
return __atomic_add_fetch(&_M_p, _M_type_size(__d),
711 memory_order_seq_cst); }
714 operator-=(ptrdiff_t __d) noexcept
715 {
return __atomic_sub_fetch(&_M_p, _M_type_size(__d),
716 memory_order_seq_cst); }
719 operator-=(ptrdiff_t __d)
volatile noexcept
720 {
return __atomic_sub_fetch(&_M_p, _M_type_size(__d),
721 memory_order_seq_cst); }
724 is_lock_free()
const noexcept
725 {
return __atomic_is_lock_free(
sizeof(__pointer_type), &_M_p); }
728 is_lock_free()
const volatile noexcept
729 {
return __atomic_is_lock_free(
sizeof(__pointer_type), &_M_p); }
732 store(__pointer_type __p,
735 __glibcxx_assert(__m != memory_order_acquire);
736 __glibcxx_assert(__m != memory_order_acq_rel);
737 __glibcxx_assert(__m != memory_order_consume);
739 __atomic_store_n(&_M_p, __p, __m);
743 store(__pointer_type __p,
744 memory_order __m = memory_order_seq_cst)
volatile noexcept
746 __glibcxx_assert(__m != memory_order_acquire);
747 __glibcxx_assert(__m != memory_order_acq_rel);
748 __glibcxx_assert(__m != memory_order_consume);
750 __atomic_store_n(&_M_p, __p, __m);
754 load(
memory_order __m = memory_order_seq_cst)
const noexcept
756 __glibcxx_assert(__m != memory_order_release);
757 __glibcxx_assert(__m != memory_order_acq_rel);
759 return __atomic_load_n(&_M_p, __m);
763 load(
memory_order __m = memory_order_seq_cst)
const volatile noexcept
765 __glibcxx_assert(__m != memory_order_release);
766 __glibcxx_assert(__m != memory_order_acq_rel);
768 return __atomic_load_n(&_M_p, __m);
772 exchange(__pointer_type __p,
775 return __atomic_exchange_n(&_M_p, __p, __m);
780 exchange(__pointer_type __p,
781 memory_order __m = memory_order_seq_cst)
volatile noexcept
783 return __atomic_exchange_n(&_M_p, __p, __m);
787 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
791 __glibcxx_assert(__m2 != memory_order_release);
792 __glibcxx_assert(__m2 != memory_order_acq_rel);
793 __glibcxx_assert(__m2 <= __m1);
795 return __atomic_compare_exchange_n(&_M_p, &__p1, __p2, 0, __m1, __m2);
799 compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
803 __glibcxx_assert(__m2 != memory_order_release);
804 __glibcxx_assert(__m2 != memory_order_acq_rel);
805 __glibcxx_assert(__m2 <= __m1);
807 return __atomic_compare_exchange_n(&_M_p, &__p1, __p2, 0, __m1, __m2);
811 fetch_add(ptrdiff_t __d,
813 {
return __atomic_fetch_add(&_M_p, _M_type_size(__d), __m); }
816 fetch_add(ptrdiff_t __d,
817 memory_order __m = memory_order_seq_cst)
volatile noexcept
818 {
return __atomic_fetch_add(&_M_p, _M_type_size(__d), __m); }
821 fetch_sub(ptrdiff_t __d,
823 {
return __atomic_fetch_sub(&_M_p, _M_type_size(__d), __m); }
826 fetch_sub(ptrdiff_t __d,
827 memory_order __m = memory_order_seq_cst)
volatile noexcept
828 {
return __atomic_fetch_sub(&_M_p, _M_type_size(__d), __m); }
833 _GLIBCXX_END_NAMESPACE_VERSION
__atomic_base< int_least16_t > atomic_int_least16_t
atomic_int_least16_t
memory_order
Enumeration for memory_order.
__atomic_base< unsigned int > atomic_uint
atomic_uint
__atomic_base< unsigned long long > atomic_ullong
atomic_ullong
__atomic_base< wchar_t > atomic_wchar_t
atomic_wchar_t
__atomic_base< int_fast32_t > atomic_int_fast32_t
atomic_int_fast32_t
__atomic_base< uint_fast16_t > atomic_uint_fast16_t
atomic_uint_fast16_t
__atomic_base< uintptr_t > atomic_uintptr_t
atomic_uintptr_t
__atomic_base< int_fast64_t > atomic_int_fast64_t
atomic_int_fast64_t
__atomic_base< signed char > atomic_schar
atomic_schar
__atomic_base< unsigned char > atomic_uchar
atomic_uchar
_Tp kill_dependency(_Tp __y) noexcept
kill_dependency
__atomic_base< char32_t > atomic_char32_t
atomic_char32_t
__atomic_base< unsigned short > atomic_ushort
atomic_ushort
__atomic_base< uint_fast8_t > atomic_uint_fast8_t
atomic_uint_fast8_t
__atomic_base< int_least64_t > atomic_int_least64_t
atomic_int_least64_t
atomic 29.4.3, Generic atomic type, primary class template.
__atomic_base< int > atomic_int
atomic_int
__atomic_base< ptrdiff_t > atomic_ptrdiff_t
atomic_ptrdiff_t
__atomic_base< int_fast16_t > atomic_int_fast16_t
atomic_int_fast16_t
__atomic_base< long > atomic_long
atomic_long
__atomic_base< intmax_t > atomic_intmax_t
atomic_intmax_t
__atomic_base< int_least32_t > atomic_int_least32_t
atomic_int_least32_t
__atomic_base< long long > atomic_llong
atomic_llong
__atomic_base< uint_least16_t > atomic_uint_least16_t
atomic_uint_least16_t
Base type for atomic_flag.
__atomic_base< uint_least32_t > atomic_uint_least32_t
atomic_uint_least32_t
__atomic_base< char > atomic_char
atomic_char
__atomic_base< uint_least64_t > atomic_uint_least64_t
atomic_uint_least64_t
__atomic_base< unsigned long > atomic_ulong
atomic_ulong
__atomic_base< uintmax_t > atomic_uintmax_t
atomic_uintmax_t
__atomic_base< int_least8_t > atomic_int_least8_t
atomic_int_least8_t
__atomic_base< uint_least8_t > atomic_uint_least8_t
atomic_uint_least8_t
__atomic_base< size_t > atomic_size_t
atomic_size_t
__atomic_base< uint_fast32_t > atomic_uint_fast32_t
atomic_uint_fast32_t
__atomic_base< int_fast8_t > atomic_int_fast8_t
atomic_int_fast8_t
__atomic_base< uint_fast64_t > atomic_uint_fast64_t
atomic_uint_fast64_t
__atomic_base< intptr_t > atomic_intptr_t
atomic_intptr_t
__atomic_base< short > atomic_short
atomic_short
__atomic_base< char16_t > atomic_char16_t
atomic_char16_t
Base class for atomic integrals.