NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
atomic.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_ASYNC_ATOMIC_HPP__
2#define NEFORCE_CORE_ASYNC_ATOMIC_HPP__
3
10
12NEFORCE_BEGIN_NAMESPACE__
13
19
25
26template <typename T>
27struct atomic;
28
36template <typename T>
37struct atomic {
38 using value_type = T;
39
40private:
41 static constexpr int min_align = (sizeof(T) & (sizeof(T) - 1)) != 0U || sizeof(T) > 16 ? 0 : sizeof(T);
42 static constexpr int align_inner = min_align > alignof(T) ? min_align : alignof(T);
43
44 alignas(align_inner) T value_;
45
46 static_assert(is_trivially_copyable_v<T>, "atomic requires a trivially copyable type");
47 static_assert(is_complete_v<T>, "Incomplete or zero-sized types are not supported");
48 static_assert(is_copy_constructible_v<T>, "atomic need copy constructible T");
49 static_assert(is_move_constructible_v<T>, "atomic need move constructible T");
50 static_assert(is_copy_assignable_v<T>, "atomic copy move assignable T");
51 static_assert(is_move_assignable_v<T>, "atomic need move assignable T");
52
53public:
54 atomic() = default;
55 ~atomic() noexcept = default;
56 atomic(const atomic&) = delete;
57 atomic& operator=(const atomic&) = delete;
58 atomic& operator=(const atomic&) volatile = delete;
59 atomic(atomic&&) noexcept = default;
60 atomic& operator=(atomic&&) noexcept = default;
61
66 constexpr atomic(T value) noexcept :
67 value_(value) {}
68
73 operator T() const noexcept { return load(); }
74
78 operator T() const volatile noexcept { return load(); }
79
85 T operator=(T value) noexcept {
86 atomic::store(value);
87 return value;
88 }
89
93 T operator=(T value) volatile noexcept {
94 atomic::store(value);
95 return value;
96 }
97
102 NEFORCE_NODISCARD bool is_lock_free() const noexcept {
104 }
105
109 NEFORCE_NODISCARD bool is_lock_free() const volatile noexcept {
111 }
112
118 void store(T value, const memory_order mo = memory_order_seq_cst) noexcept {
119 _NEFORCE atomic_store_any(_NEFORCE addressof(value_), value, mo);
120 }
121
125 void store(T value, const memory_order mo = memory_order_seq_cst) volatile noexcept {
126 _NEFORCE atomic_store_any(_NEFORCE addressof(value_), value, mo);
127 }
128
134 T load(const memory_order mo = memory_order_seq_cst) const noexcept {
135 return _NEFORCE atomic_load_any(_NEFORCE addressof(value_), mo);
136 }
137
141 T load(const memory_order mo = memory_order_seq_cst) const volatile noexcept {
142 return _NEFORCE atomic_load_any(_NEFORCE addressof(value_), mo);
143 }
144
151 T exchange(T value, const memory_order mo = memory_order_seq_cst) noexcept {
152 return _NEFORCE atomic_exchange_any(_NEFORCE addressof(value_), value, mo);
153 }
154
158 T exchange(T value, const memory_order mo = memory_order_seq_cst) volatile noexcept {
159 return _NEFORCE atomic_exchange_any(_NEFORCE addressof(value_), value, mo);
160 }
161
170 bool compare_exchange_weak(T& expected, T desired, const memory_order success,
171 const memory_order failure) noexcept {
173 return _NEFORCE atomic_cmpexch_weak_any(_NEFORCE addressof(value_), &expected, &desired, success, failure);
174 }
175
179 bool compare_exchange_weak(T& expected, T desired, const memory_order success,
180 const memory_order failure) volatile noexcept {
182 return _NEFORCE atomic_cmpexch_weak_any(_NEFORCE addressof(value_), &expected, &desired, success, failure);
183 }
184
192 bool compare_exchange_weak(T& expected, T desired, const memory_order mo = memory_order_seq_cst) noexcept {
193 return atomic::compare_exchange_weak(expected, desired, mo, cmpexch_failure_order(mo));
194 }
195
199 bool compare_exchange_weak(T& expected, T desired, const memory_order mo = memory_order_seq_cst) volatile noexcept {
200 return atomic::compare_exchange_weak(expected, desired, mo, cmpexch_failure_order(mo));
201 }
202
211 bool compare_exchange_strong(T& expected, T desired, const memory_order success,
212 const memory_order failure) noexcept {
214 return _NEFORCE atomic_cmpexch_strong_any(_NEFORCE addressof(value_), _NEFORCE addressof(expected),
215 _NEFORCE addressof(desired), success, failure);
216 }
217
221 bool compare_exchange_strong(T& expected, T desired, const memory_order success,
222 const memory_order failure) volatile noexcept {
224 return _NEFORCE atomic_cmpexch_strong_any(_NEFORCE addressof(value_), _NEFORCE addressof(expected),
225 _NEFORCE addressof(desired), success, failure);
226 }
227
235 bool compare_exchange_strong(T& expected, T value, const memory_order mo = memory_order_seq_cst) noexcept {
236 return atomic::compare_exchange_strong(expected, value, mo, cmpexch_failure_order(mo));
237 }
238
242 bool compare_exchange_strong(T& expected, T value, const memory_order mo = memory_order_seq_cst) volatile noexcept {
243 return atomic::compare_exchange_strong(expected, value, mo, cmpexch_failure_order(mo));
244 }
245};
246
251template <typename T>
252struct atomic<T*> : atomic_base<T*> {
253 atomic() = default;
254 ~atomic() noexcept = default;
255 atomic(const atomic&) = delete;
256 atomic& operator=(const atomic&) = delete;
257 atomic& operator=(const atomic&) volatile = delete;
258 atomic(atomic&&) noexcept = default;
259 atomic& operator=(atomic&&) noexcept = default;
260
261 explicit atomic(T* value) noexcept :
262 atomic_base<T*>(value) {}
263
264 using atomic_base<T*>::operator=;
265};
266
271template <typename T>
272struct atomic<T&> : atomic_ref_base<T> {
273 atomic() = default;
274 ~atomic() noexcept = default;
275 atomic(const atomic&) = delete;
276 atomic& operator=(const atomic&) = delete;
277 atomic& operator=(const atomic&) volatile = delete;
278 atomic(atomic&&) noexcept = default;
279 atomic& operator=(atomic&&) noexcept = default;
280
281 explicit atomic(T& value) noexcept :
282 atomic_ref_base<T>(value) {}
283
284 using atomic_ref_base<T>::operator=;
285};
286
287
292template <>
293struct atomic<bool> {
294 using value_type = bool;
295
296private:
297 atomic_base<bool> base_;
298
299public:
300 atomic() = default;
301 ~atomic() noexcept = default;
302 atomic(const atomic&) = delete;
303 atomic& operator=(const atomic&) = delete;
304 atomic& operator=(const atomic&) volatile = delete;
305 atomic(atomic&&) noexcept = default;
306 atomic& operator=(atomic&&) noexcept = default;
307
312 constexpr atomic(const bool value) noexcept :
313 base_(value) {}
314
320 bool operator=(const bool value) noexcept { return base_.operator=(value); }
321
325 bool operator=(const bool value) volatile noexcept { return base_.operator=(value); }
326
331 operator bool() const noexcept { return base_.load(); }
332
336 operator bool() const volatile noexcept { return base_.load(); }
337
342 NEFORCE_NODISCARD bool is_lock_free() const noexcept { return base_.is_lock_free(); }
343
347 NEFORCE_NODISCARD bool is_lock_free() const volatile noexcept { return base_.is_lock_free(); }
348
354 void store(const bool value, const memory_order mo = memory_order_seq_cst) noexcept { base_.store(value, mo); }
355
359 void store(const bool value, const memory_order mo = memory_order_seq_cst) volatile noexcept {
360 base_.store(value, mo);
361 }
362
368 NEFORCE_NODISCARD bool load(const memory_order mo = memory_order_seq_cst) const noexcept { return base_.load(mo); }
369
373 NEFORCE_NODISCARD bool load(const memory_order mo = memory_order_seq_cst) const volatile noexcept {
374 return base_.load(mo);
375 }
376
383 bool exchange(const bool value, const memory_order mo = memory_order_seq_cst) noexcept {
384 return base_.exchange(value, mo);
385 }
386
390 bool exchange(const bool value, const memory_order mo = memory_order_seq_cst) volatile noexcept {
391 return base_.exchange(value, mo);
392 }
393
402 bool compare_exchange_weak(bool& value1, const bool value2, const memory_order success,
403 const memory_order failure) noexcept {
404 return base_.compare_exchange_weak(value1, value2, success, failure);
405 }
406
410 bool compare_exchange_weak(bool& value1, const bool value2, const memory_order success,
411 const memory_order failure) volatile noexcept {
412 return base_.compare_exchange_weak(value1, value2, success, failure);
413 }
414
422 bool compare_exchange_weak(bool& value1, const bool value2, const memory_order mo = memory_order_seq_cst) noexcept {
423 return base_.compare_exchange_weak(value1, value2, mo);
424 }
425
429 bool compare_exchange_weak(bool& value1, const bool value2,
430 const memory_order mo = memory_order_seq_cst) volatile noexcept {
431 return base_.compare_exchange_weak(value1, value2, mo);
432 }
433
442 bool compare_exchange_strong(bool& value1, const bool value2, const memory_order success,
443 const memory_order failure) noexcept {
444 return base_.compare_exchange_strong(value1, value2, success, failure);
445 }
446
450 bool compare_exchange_strong(bool& value1, const bool value2, const memory_order success,
451 const memory_order failure) volatile noexcept {
452 return base_.compare_exchange_strong(value1, value2, success, failure);
453 }
454
462 bool compare_exchange_strong(bool& value1, const bool value2,
463 const memory_order mo = memory_order_seq_cst) noexcept {
464 return base_.compare_exchange_strong(value1, value2, mo);
465 }
466
470 bool compare_exchange_strong(bool& value1, const bool value2,
471 const memory_order mo = memory_order_seq_cst) volatile noexcept {
472 return base_.compare_exchange_strong(value1, value2, mo);
473 }
474
480 void wait(const bool old, const memory_order mo = memory_order_seq_cst) const noexcept { base_.wait(old, mo); }
481
485 void notify_one() noexcept { base_.notify_one(); }
486
490 void notify_all() noexcept { base_.notify_all(); }
491};
492
494template <>
495struct atomic<char> : atomic_base<char> {
496 using integral_type = char;
497 using base_type = atomic_base<char>;
498
499 atomic() = default;
500 ~atomic() noexcept = default;
501 atomic(const atomic&) = delete;
502 atomic& operator=(const atomic&) = delete;
503 atomic& operator=(const atomic&) volatile = delete;
504 atomic(atomic&&) noexcept = default;
505 atomic& operator=(atomic&&) noexcept = default;
506
507 constexpr atomic(const integral_type value) noexcept :
508 base_type(value) {}
509
510 using base_type::operator integral_type;
511 using base_type::operator=;
512
513 static constexpr bool is_always_lock_free = true;
514};
515
517template <>
518struct atomic<signed char> : atomic_base<signed char> {
519 using integral_type = signed char;
520 using base_type = atomic_base<signed char>;
521
522 atomic() = default;
523 ~atomic() noexcept = default;
524 atomic(const atomic&) = delete;
525 atomic& operator=(const atomic&) = delete;
526 atomic& operator=(const atomic&) volatile = delete;
527 atomic(atomic&&) noexcept = default;
528 atomic& operator=(atomic&&) noexcept = default;
529
530 constexpr atomic(const integral_type value) noexcept :
531 base_type(value) {}
532
533 using base_type::operator integral_type;
534 using base_type::operator=;
535
536 static constexpr bool is_always_lock_free = true;
537};
538
540template <>
541struct atomic<unsigned char> : atomic_base<unsigned char> {
542 using integral_type = unsigned char;
543 using base_type = atomic_base<unsigned char>;
544
545 atomic() = default;
546 ~atomic() noexcept = default;
547 atomic(const atomic&) = delete;
548 atomic& operator=(const atomic&) = delete;
549 atomic& operator=(const atomic&) volatile = delete;
550 atomic(atomic&&) noexcept = default;
551 atomic& operator=(atomic&&) noexcept = default;
552
553 constexpr atomic(const integral_type value) noexcept :
554 base_type(value) {}
555
556 using base_type::operator integral_type;
557 using base_type::operator=;
558
559 static constexpr bool is_always_lock_free = true;
560};
561
563template <>
564struct atomic<short> : atomic_base<short> {
565 using integral_type = short;
566 using base_type = atomic_base<short>;
567
568 atomic() = default;
569 ~atomic() noexcept = default;
570 atomic(const atomic&) = delete;
571 atomic& operator=(const atomic&) = delete;
572 atomic& operator=(const atomic&) volatile = delete;
573 atomic(atomic&&) noexcept = default;
574 atomic& operator=(atomic&&) noexcept = default;
575
576 constexpr atomic(const integral_type value) noexcept :
577 base_type(value) {}
578
579 using base_type::operator integral_type;
580 using base_type::operator=;
581
582 static constexpr bool is_always_lock_free = true;
583};
584
586template <>
587struct atomic<unsigned short> : atomic_base<unsigned short> {
588 using integral_type = unsigned short;
589 using base_type = atomic_base<unsigned short>;
590
591 atomic() = default;
592 ~atomic() noexcept = default;
593 atomic(const atomic&) = delete;
594 atomic& operator=(const atomic&) = delete;
595 atomic& operator=(const atomic&) volatile = delete;
596 atomic(atomic&&) noexcept = default;
597 atomic& operator=(atomic&&) noexcept = default;
598
599 constexpr atomic(const integral_type value) noexcept :
600 base_type(value) {}
601
602 using base_type::operator integral_type;
603 using base_type::operator=;
604
605 static constexpr bool is_always_lock_free = true;
606};
607
609template <>
610struct atomic<int> : atomic_base<int> {
611 using integral_type = int;
612 using base_type = atomic_base<int>;
613
614 atomic() = default;
615 ~atomic() noexcept = default;
616 atomic(const atomic&) = delete;
617 atomic& operator=(const atomic&) = delete;
618 atomic& operator=(const atomic&) volatile = delete;
619 atomic(atomic&&) noexcept = default;
620 atomic& operator=(atomic&&) noexcept = default;
621
622 constexpr atomic(const integral_type value) noexcept :
623 base_type(value) {}
624
625 using base_type::operator integral_type;
626 using base_type::operator=;
627
628 static constexpr bool is_always_lock_free = true;
629};
630
632template <>
633struct atomic<unsigned int> : atomic_base<unsigned int> {
634 using integral_type = unsigned int;
635 using base_type = atomic_base<unsigned int>;
636
637 atomic() = default;
638 ~atomic() noexcept = default;
639 atomic(const atomic&) = delete;
640 atomic& operator=(const atomic&) = delete;
641 atomic& operator=(const atomic&) volatile = delete;
642 atomic(atomic&&) noexcept = default;
643 atomic& operator=(atomic&&) noexcept = default;
644
645 constexpr atomic(const integral_type value) noexcept :
646 base_type(value) {}
647
648 using base_type::operator integral_type;
649 using base_type::operator=;
650
651 static constexpr bool is_always_lock_free = true;
652};
653
655template <>
656struct atomic<long> : atomic_base<long> {
657 using integral_type = long;
658 using base_type = atomic_base<long>;
659
660 atomic() = default;
661 ~atomic() noexcept = default;
662 atomic(const atomic&) = delete;
663 atomic& operator=(const atomic&) = delete;
664 atomic& operator=(const atomic&) volatile = delete;
665 atomic(atomic&&) noexcept = default;
666 atomic& operator=(atomic&&) noexcept = default;
667
668 constexpr atomic(const integral_type value) noexcept :
669 base_type(value) {}
670
671 using base_type::operator integral_type;
672 using base_type::operator=;
673
674 static constexpr bool is_always_lock_free = true;
675};
676
678template <>
679struct atomic<unsigned long> : atomic_base<unsigned long> {
680 using integral_type = unsigned long;
681 using base_type = atomic_base<unsigned long>;
682
683 atomic() = default;
684 ~atomic() noexcept = default;
685 atomic(const atomic&) = delete;
686 atomic& operator=(const atomic&) = delete;
687 atomic& operator=(const atomic&) volatile = delete;
688 atomic(atomic&&) noexcept = default;
689 atomic& operator=(atomic&&) noexcept = default;
690
691 constexpr atomic(const integral_type value) noexcept :
692 base_type(value) {}
693
694 using base_type::operator integral_type;
695 using base_type::operator=;
696
697 static constexpr bool is_always_lock_free = true;
698};
699
701template <>
702struct atomic<long long> : atomic_base<long long> {
703 using integral_type = long long;
704 using base_type = atomic_base<long long>;
705
706 atomic() = default;
707 ~atomic() noexcept = default;
708 atomic(const atomic&) = delete;
709 atomic& operator=(const atomic&) = delete;
710 atomic& operator=(const atomic&) volatile = delete;
711 atomic(atomic&&) noexcept = default;
712 atomic& operator=(atomic&&) noexcept = default;
713
714 constexpr atomic(const integral_type value) noexcept :
715 base_type(value) {}
716
717 using base_type::operator integral_type;
718 using base_type::operator=;
719
720 static constexpr bool is_always_lock_free = true;
721};
722
724template <>
725struct atomic<unsigned long long> : atomic_base<unsigned long long> {
726 using integral_type = unsigned long long;
727 using base_type = atomic_base<unsigned long long>;
728
729 atomic() = default;
730 ~atomic() noexcept = default;
731 atomic(const atomic&) = delete;
732 atomic& operator=(const atomic&) = delete;
733 atomic& operator=(const atomic&) volatile = delete;
734 atomic(atomic&&) noexcept = default;
735 atomic& operator=(atomic&&) noexcept = default;
736
737 constexpr atomic(const integral_type value) noexcept :
738 base_type(value) {}
739
740 using base_type::operator integral_type;
741 using base_type::operator=;
742
743 static constexpr bool is_always_lock_free = true;
744};
745
747template <>
748struct atomic<wchar_t> : atomic_base<wchar_t> {
749 using integral_type = wchar_t;
750 using base_type = atomic_base<wchar_t>;
751
752 atomic() = default;
753 ~atomic() noexcept = default;
754 atomic(const atomic&) = delete;
755 atomic& operator=(const atomic&) = delete;
756 atomic& operator=(const atomic&) volatile = delete;
757 atomic(atomic&&) noexcept = default;
758 atomic& operator=(atomic&&) noexcept = default;
759
760 constexpr atomic(const integral_type value) noexcept :
761 base_type(value) {}
762
763 using base_type::operator integral_type;
764 using base_type::operator=;
765
766 static constexpr bool is_always_lock_free = true;
767};
768
769#ifdef NEFORCE_STANDARD_20
771template <>
772struct atomic<char8_t> : atomic_base<char8_t> {
773 using integral_type = char8_t;
774 using base_type = atomic_base<char8_t>;
775
776 atomic() = default;
777 ~atomic() noexcept = default;
778 atomic(const atomic&) = delete;
779 atomic& operator=(const atomic&) = delete;
780 atomic& operator=(const atomic&) volatile = delete;
781 atomic(atomic&&) noexcept = default;
782 atomic& operator=(atomic&&) noexcept = default;
783
784 constexpr atomic(const integral_type value) noexcept :
785 base_type(value) {}
786
787 using base_type::operator integral_type;
788 using base_type::operator=;
789
790 static constexpr bool is_always_lock_free = true;
791};
792#endif
793
795template <>
796struct atomic<char16_t> : atomic_base<char16_t> {
797 using integral_type = char16_t;
798 using base_type = atomic_base<char16_t>;
799
800 atomic() = default;
801 ~atomic() noexcept = default;
802 atomic(const atomic&) = delete;
803 atomic& operator=(const atomic&) = delete;
804 atomic& operator=(const atomic&) volatile = delete;
805 atomic(atomic&&) noexcept = default;
806 atomic& operator=(atomic&&) noexcept = default;
807
808 constexpr atomic(const integral_type value) noexcept :
809 base_type(value) {}
810
811 using base_type::operator integral_type;
812 using base_type::operator=;
813
814 static constexpr bool is_always_lock_free = true;
815};
816
818template <>
819struct atomic<char32_t> : atomic_base<char32_t> {
820 using integral_type = char32_t;
821 using base_type = atomic_base<char32_t>;
822
823 atomic() = default;
824 ~atomic() noexcept = default;
825 atomic(const atomic&) = delete;
826 atomic& operator=(const atomic&) = delete;
827 atomic& operator=(const atomic&) volatile = delete;
828 atomic(atomic&&) noexcept = default;
829 atomic& operator=(atomic&&) noexcept = default;
830
831 constexpr atomic(const integral_type value) noexcept :
832 base_type(value) {}
833
834 using base_type::operator integral_type;
835 using base_type::operator=;
836
837 static constexpr bool is_always_lock_free = true;
838};
839
841template <>
842struct atomic<float> : atomic_float_base<float> {
843 atomic() = default;
844 ~atomic() noexcept = default;
845 atomic(const atomic&) = delete;
846 atomic& operator=(const atomic&) = delete;
847 atomic& operator=(const atomic&) volatile = delete;
848 atomic(atomic&&) noexcept = default;
849 atomic& operator=(atomic&&) noexcept = default;
850
851 constexpr atomic(const float value) noexcept :
852 atomic_float_base<float>(value) {}
853
854 using atomic_float_base<float>::operator=;
855};
856
858template <>
859struct atomic<double> : atomic_float_base<double> {
860 atomic() = default;
861 ~atomic() noexcept = default;
862 atomic(const atomic&) = delete;
863 atomic& operator=(const atomic&) = delete;
864 atomic& operator=(const atomic&) volatile = delete;
865 atomic(atomic&&) noexcept = default;
866 atomic& operator=(atomic&&) noexcept = default;
867
868 constexpr atomic(const double value) noexcept :
869 atomic_float_base<double>(value) {}
870
871 using atomic_float_base<double>::operator=;
872};
873
875template <>
876struct atomic<long double> : atomic_float_base<long double> {
877 atomic() = default;
878 ~atomic() noexcept = default;
879 atomic(const atomic&) = delete;
880 atomic& operator=(const atomic&) = delete;
881 atomic& operator=(const atomic&) volatile = delete;
882 atomic(atomic&&) noexcept = default;
883 atomic& operator=(atomic&&) noexcept = default;
884
885 constexpr atomic(const long double value) noexcept :
886 atomic_float_base<long double>(value) {}
887
888 using atomic_float_base<long double>::operator=;
889};
890 // AtomicOperations
892 // AsyncComponents
894
895NEFORCE_END_NAMESPACE__
896#endif // NEFORCE_CORE_ASYNC_ATOMIC_HPP__
原子操作基本工具
constexpr T * addressof(T &x) noexcept
获取对象的地址
bool atomic_cmpexch_strong_any(volatile T *ptr, remove_volatile_t< T > *expected, remove_volatile_t< T > *desired, const memory_order success, const memory_order failure) noexcept
通用强比较交换操作
bool atomic_cmpexch_weak_any(volatile T *ptr, remove_volatile_t< T > *expected, remove_volatile_t< T > *desired, const memory_order success, const memory_order failure) noexcept
通用弱比较交换操作
constexpr bool is_always_lock_free() noexcept
检查是否支持无锁操作
remove_volatile_t< T > atomic_load_any(const T *ptr, memory_order mo) noexcept
通用原子加载操作
void atomic_store_any(T *ptr, remove_volatile_t< T > value, const memory_order mo) noexcept
通用原子存储操作
remove_volatile_t< T > atomic_exchange_any(T *ptr, remove_volatile_t< T > desired, memory_order mo) noexcept
通用原子交换操作
#define NEFORCE_CONSTEXPR_ASSERT(COND)
编译时常量断言
constexpr bool is_valid_cmpexch_failure_order(const memory_order mo) noexcept
检查比较交换失败内存顺序是否有效
constexpr auto memory_order_seq_cst
顺序一致性内存顺序常量
memory_order
内存顺序
constexpr memory_order cmpexch_failure_order(const memory_order mo) noexcept
获取原子比较交换操作失败时的内存顺序
constexpr bool is_copy_constructible_v
is_copy_constructible的便捷变量模板
constexpr bool is_move_constructible_v
is_move_constructible的便捷变量模板
constexpr bool is_trivially_copyable_v
is_trivially_copyable的便捷变量模板
constexpr bool is_move_assignable_v
is_move_assignable的便捷变量模板
constexpr bool is_copy_assignable_v
is_copy_assignable的便捷变量模板
bool is_lock_free() const noexcept
检查是否支持无锁操作
bool compare_exchange_strong(bool &value1, const bool value2, const memory_order mo=memory_order_seq_cst) noexcept
简化版强比较交换操作
bool operator=(const bool value) noexcept
赋值运算符
void store(const bool value, const memory_order mo=memory_order_seq_cst) volatile noexcept
volatile版本的原子存储操作
bool operator=(const bool value) volatile noexcept
volatile版本的赋值运算符
void store(const bool value, const memory_order mo=memory_order_seq_cst) noexcept
原子存储操作
bool compare_exchange_weak(bool &value1, const bool value2, const memory_order success, const memory_order failure) noexcept
弱比较交换操作
bool load(const memory_order mo=memory_order_seq_cst) const volatile noexcept
volatile版本的原子加载操作
bool exchange(const bool value, const memory_order mo=memory_order_seq_cst) noexcept
原子交换操作
bool compare_exchange_strong(bool &value1, const bool value2, const memory_order mo=memory_order_seq_cst) volatile noexcept
volatile版本的简化版强比较交换操作
bool compare_exchange_weak(bool &value1, const bool value2, const memory_order mo=memory_order_seq_cst) volatile noexcept
volatile版本的简化版弱比较交换操作
void wait(const bool old, const memory_order mo=memory_order_seq_cst) const noexcept
等待值改变
bool value_type
值类型
bool compare_exchange_strong(bool &value1, const bool value2, const memory_order success, const memory_order failure) noexcept
强比较交换操作
void notify_one() noexcept
通知一个等待线程
bool is_lock_free() const volatile noexcept
volatile版本的检查是否支持无锁操作
bool exchange(const bool value, const memory_order mo=memory_order_seq_cst) volatile noexcept
volatile版本的原子交换操作
bool compare_exchange_weak(bool &value1, const bool value2, const memory_order mo=memory_order_seq_cst) noexcept
简化版弱比较交换操作
bool compare_exchange_weak(bool &value1, const bool value2, const memory_order success, const memory_order failure) volatile noexcept
volatile版本的弱比较交换操作
bool compare_exchange_strong(bool &value1, const bool value2, const memory_order success, const memory_order failure) volatile noexcept
volatile版本的强比较交换操作
void notify_all() noexcept
通知所有等待线程
bool load(const memory_order mo=memory_order_seq_cst) const noexcept
原子加载操作
原子类型基础模板类
原子引用基础模板类
通用原子类型模板
bool compare_exchange_strong(T &expected, T value, const memory_order mo=memory_order_seq_cst) noexcept
简化版强比较交换操作
T load(const memory_order mo=memory_order_seq_cst) const noexcept
原子加载操作
bool is_lock_free() const noexcept
检查是否支持无锁操作
bool compare_exchange_strong(T &expected, T desired, const memory_order success, const memory_order failure) noexcept
强比较交换操作
void store(T value, const memory_order mo=memory_order_seq_cst) volatile noexcept
volatile版本的原子存储操作
T operator=(T value) noexcept
赋值运算符
void store(T value, const memory_order mo=memory_order_seq_cst) noexcept
原子存储操作
T value_type
值类型
T exchange(T value, const memory_order mo=memory_order_seq_cst) noexcept
原子交换操作
T operator=(T value) volatile noexcept
volatile版本的赋值运算符
bool compare_exchange_weak(T &expected, T desired, const memory_order mo=memory_order_seq_cst) noexcept
简化版弱比较交换操作
bool compare_exchange_weak(T &expected, T desired, const memory_order success, const memory_order failure) volatile noexcept
volatile版本的弱比较交换操作
bool compare_exchange_weak(T &expected, T desired, const memory_order mo=memory_order_seq_cst) volatile noexcept
volatile版本的简化版弱比较交换操作
T exchange(T value, const memory_order mo=memory_order_seq_cst) volatile noexcept
volatile版本的原子交换操作
bool compare_exchange_strong(T &expected, T desired, const memory_order success, const memory_order failure) volatile noexcept
volatile版本的强比较交换操作
bool is_lock_free() const volatile noexcept
volatile版本的检查是否支持无锁操作
T load(const memory_order mo=memory_order_seq_cst) const volatile noexcept
volatile版本的原子加载操作
bool compare_exchange_weak(T &expected, T desired, const memory_order success, const memory_order failure) noexcept
弱比较交换操作
bool compare_exchange_strong(T &expected, T value, const memory_order mo=memory_order_seq_cst) volatile noexcept
volatile版本的简化版强比较交换操作