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)) || 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(sizeof(T) > 0, "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 bool is_lock_free() const noexcept { return _NEFORCE is_always_lock_free<sizeof(value_), align_inner>(); }
103
107 bool is_lock_free() const volatile noexcept { return _NEFORCE is_always_lock_free<sizeof(value_), align_inner>(); }
108
114 void store(T value, const memory_order mo = memory_order_seq_cst) noexcept {
115 _NEFORCE atomic_store_any(_NEFORCE addressof(value_), value, mo);
116 }
117
121 void store(T value, const memory_order mo = memory_order_seq_cst) volatile noexcept {
122 _NEFORCE atomic_store_any(_NEFORCE addressof(value_), value, mo);
123 }
124
130 T load(const memory_order mo = memory_order_seq_cst) const noexcept {
131 return _NEFORCE atomic_load_any(_NEFORCE addressof(value_), mo);
132 }
133
137 T load(const memory_order mo = memory_order_seq_cst) const volatile noexcept {
138 return _NEFORCE atomic_load_any(_NEFORCE addressof(value_), mo);
139 }
140
147 T exchange(T value, const memory_order mo = memory_order_seq_cst) noexcept {
148 return _NEFORCE atomic_exchange_any(_NEFORCE addressof(value_), value, mo);
149 }
150
154 T exchange(T value, const memory_order mo = memory_order_seq_cst) volatile noexcept {
155 return _NEFORCE atomic_exchange_any(_NEFORCE addressof(value_), value, mo);
156 }
157
166 bool compare_exchange_weak(T& expected, T desired, const memory_order success,
167 const memory_order failure) noexcept {
169 return _NEFORCE atomic_cmpexch_weak_any(_NEFORCE addressof(value_), &expected, &desired, success, failure);
170 }
171
175 bool compare_exchange_weak(T& expected, T desired, const memory_order success,
176 const memory_order failure) volatile noexcept {
178 return _NEFORCE atomic_cmpexch_weak_any(_NEFORCE addressof(value_), &expected, &desired, success, failure);
179 }
180
188 bool compare_exchange_weak(T& expected, T desired, const memory_order mo = memory_order_seq_cst) noexcept {
189 return atomic::compare_exchange_weak(expected, desired, mo, cmpexch_failure_order(mo));
190 }
191
195 bool compare_exchange_weak(T& expected, T desired, const memory_order mo = memory_order_seq_cst) volatile noexcept {
196 return atomic::compare_exchange_weak(expected, desired, mo, cmpexch_failure_order(mo));
197 }
198
207 bool compare_exchange_strong(T& expected, T desired, const memory_order success,
208 const memory_order failure) noexcept {
210 return _NEFORCE atomic_cmpexch_strong_any(_NEFORCE addressof(value_), _NEFORCE addressof(expected),
211 _NEFORCE addressof(desired), success, failure);
212 }
213
217 bool compare_exchange_strong(T& expected, T desired, const memory_order success,
218 const memory_order failure) volatile noexcept {
220 return _NEFORCE atomic_cmpexch_strong_any(_NEFORCE addressof(value_), _NEFORCE addressof(expected),
221 _NEFORCE addressof(desired), success, failure);
222 }
223
231 bool compare_exchange_strong(T& expected, T value, const memory_order mo = memory_order_seq_cst) noexcept {
232 return atomic::compare_exchange_strong(expected, value, mo, cmpexch_failure_order(mo));
233 }
234
238 bool compare_exchange_strong(T& expected, T value, const memory_order mo = memory_order_seq_cst) volatile noexcept {
239 return atomic::compare_exchange_strong(expected, value, mo, cmpexch_failure_order(mo));
240 }
241};
242
247template <typename T>
248struct atomic<T*> : atomic_base<T*> {
249 atomic() = default;
250 ~atomic() noexcept = default;
251 atomic(const atomic&) = delete;
252 atomic& operator=(const atomic&) = delete;
253 atomic& operator=(const atomic&) volatile = delete;
254 atomic(atomic&&) noexcept = default;
255 atomic& operator=(atomic&&) noexcept = default;
256
257 explicit atomic(T* value) noexcept :
258 atomic_base<T*>(value) {}
259
260 using atomic_base<T*>::operator=;
261};
262
267template <typename T>
268struct atomic<T&> : atomic_ref_base<T> {
269 atomic() = default;
270 ~atomic() noexcept = default;
271 atomic(const atomic&) = delete;
272 atomic& operator=(const atomic&) = delete;
273 atomic& operator=(const atomic&) volatile = delete;
274 atomic(atomic&&) noexcept = default;
275 atomic& operator=(atomic&&) noexcept = default;
276
277 explicit atomic(T& value) noexcept :
278 atomic_ref_base<T>(value) {}
279
280 using atomic_ref_base<T>::operator=;
281};
282
283
288template <>
289struct atomic<bool> {
290 using value_type = bool;
291
292private:
293 atomic_base<bool> base_;
294
295public:
296 atomic() = default;
297 ~atomic() noexcept = default;
298 atomic(const atomic&) = delete;
299 atomic& operator=(const atomic&) = delete;
300 atomic& operator=(const atomic&) volatile = delete;
301 atomic(atomic&&) noexcept = default;
302 atomic& operator=(atomic&&) noexcept = default;
303
308 constexpr atomic(const bool value) noexcept :
309 base_(value) {}
310
316 bool operator=(const bool value) noexcept { return base_.operator=(value); }
317
321 bool operator=(const bool value) volatile noexcept { return base_.operator=(value); }
322
327 operator bool() const noexcept { return base_.load(); }
328
332 operator bool() const volatile noexcept { return base_.load(); }
333
338 bool is_lock_free() const noexcept { return base_.is_lock_free(); }
339
343 bool is_lock_free() const volatile noexcept { return base_.is_lock_free(); }
344
350 void store(const bool value, const memory_order mo = memory_order_seq_cst) noexcept { base_.store(value, mo); }
351
355 void store(const bool value, const memory_order mo = memory_order_seq_cst) volatile noexcept {
356 base_.store(value, mo);
357 }
358
364 bool load(const memory_order mo = memory_order_seq_cst) const noexcept { return base_.load(mo); }
365
369 bool load(const memory_order mo = memory_order_seq_cst) const volatile noexcept { return base_.load(mo); }
370
377 bool exchange(const bool value, const memory_order mo = memory_order_seq_cst) noexcept {
378 return base_.exchange(value, mo);
379 }
380
384 bool exchange(const bool value, const memory_order mo = memory_order_seq_cst) volatile noexcept {
385 return base_.exchange(value, mo);
386 }
387
396 bool compare_exchange_weak(bool& value1, const bool value2, const memory_order success,
397 const memory_order failure) noexcept {
398 return base_.compare_exchange_weak(value1, value2, success, failure);
399 }
400
404 bool compare_exchange_weak(bool& value1, const bool value2, const memory_order success,
405 const memory_order failure) volatile noexcept {
406 return base_.compare_exchange_weak(value1, value2, success, failure);
407 }
408
416 bool compare_exchange_weak(bool& value1, const bool value2, const memory_order mo = memory_order_seq_cst) noexcept {
417 return base_.compare_exchange_weak(value1, value2, mo);
418 }
419
423 bool compare_exchange_weak(bool& value1, const bool value2,
424 const memory_order mo = memory_order_seq_cst) volatile noexcept {
425 return base_.compare_exchange_weak(value1, value2, mo);
426 }
427
436 bool compare_exchange_strong(bool& value1, const bool value2, const memory_order success,
437 const memory_order failure) noexcept {
438 return base_.compare_exchange_strong(value1, value2, success, failure);
439 }
440
444 bool compare_exchange_strong(bool& value1, const bool value2, const memory_order success,
445 const memory_order failure) volatile noexcept {
446 return base_.compare_exchange_strong(value1, value2, success, failure);
447 }
448
456 bool compare_exchange_strong(bool& value1, const bool value2,
457 const memory_order mo = memory_order_seq_cst) noexcept {
458 return base_.compare_exchange_strong(value1, value2, mo);
459 }
460
464 bool compare_exchange_strong(bool& value1, const bool value2,
465 const memory_order mo = memory_order_seq_cst) volatile noexcept {
466 return base_.compare_exchange_strong(value1, value2, mo);
467 }
468
474 void wait(const bool old, const memory_order mo = memory_order_seq_cst) const noexcept { base_.wait(old, mo); }
475
479 void notify_one() noexcept { base_.notify_one(); }
480
484 void notify_all() noexcept { base_.notify_all(); }
485};
486
488template <>
489struct atomic<char> : atomic_base<char> {
490 using integral_type = char;
491 using base_type = atomic_base<char>;
492
493 atomic() = default;
494 ~atomic() noexcept = default;
495 atomic(const atomic&) = delete;
496 atomic& operator=(const atomic&) = delete;
497 atomic& operator=(const atomic&) volatile = delete;
498 atomic(atomic&&) noexcept = default;
499 atomic& operator=(atomic&&) noexcept = default;
500
501 constexpr atomic(const integral_type value) noexcept :
502 base_type(value) {}
503
504 using base_type::operator integral_type;
505 using base_type::operator=;
506
507 static constexpr bool is_always_lock_free = true;
508};
509
511template <>
512struct atomic<signed char> : atomic_base<signed char> {
513 using integral_type = signed char;
514 using base_type = atomic_base<signed char>;
515
516 atomic() = default;
517 ~atomic() noexcept = default;
518 atomic(const atomic&) = delete;
519 atomic& operator=(const atomic&) = delete;
520 atomic& operator=(const atomic&) volatile = delete;
521 atomic(atomic&&) noexcept = default;
522 atomic& operator=(atomic&&) noexcept = default;
523
524 constexpr atomic(const integral_type value) noexcept :
525 base_type(value) {}
526
527 using base_type::operator integral_type;
528 using base_type::operator=;
529
530 static constexpr bool is_always_lock_free = true;
531};
532
534template <>
535struct atomic<unsigned char> : atomic_base<unsigned char> {
536 using integral_type = unsigned char;
537 using base_type = atomic_base<unsigned char>;
538
539 atomic() = default;
540 ~atomic() noexcept = default;
541 atomic(const atomic&) = delete;
542 atomic& operator=(const atomic&) = delete;
543 atomic& operator=(const atomic&) volatile = delete;
544 atomic(atomic&&) noexcept = default;
545 atomic& operator=(atomic&&) noexcept = default;
546
547 constexpr atomic(const integral_type value) noexcept :
548 base_type(value) {}
549
550 using base_type::operator integral_type;
551 using base_type::operator=;
552
553 static constexpr bool is_always_lock_free = true;
554};
555
557template <>
558struct atomic<short> : atomic_base<short> {
559 using integral_type = short;
560 using base_type = atomic_base<short>;
561
562 atomic() = default;
563 ~atomic() noexcept = default;
564 atomic(const atomic&) = delete;
565 atomic& operator=(const atomic&) = delete;
566 atomic& operator=(const atomic&) volatile = delete;
567 atomic(atomic&&) noexcept = default;
568 atomic& operator=(atomic&&) noexcept = default;
569
570 constexpr atomic(const integral_type value) noexcept :
571 base_type(value) {}
572
573 using base_type::operator integral_type;
574 using base_type::operator=;
575
576 static constexpr bool is_always_lock_free = true;
577};
578
580template <>
581struct atomic<unsigned short> : atomic_base<unsigned short> {
582 using integral_type = unsigned short;
583 using base_type = atomic_base<unsigned short>;
584
585 atomic() = default;
586 ~atomic() noexcept = default;
587 atomic(const atomic&) = delete;
588 atomic& operator=(const atomic&) = delete;
589 atomic& operator=(const atomic&) volatile = delete;
590 atomic(atomic&&) noexcept = default;
591 atomic& operator=(atomic&&) noexcept = default;
592
593 constexpr atomic(const integral_type value) noexcept :
594 base_type(value) {}
595
596 using base_type::operator integral_type;
597 using base_type::operator=;
598
599 static constexpr bool is_always_lock_free = true;
600};
601
603template <>
604struct atomic<int> : atomic_base<int> {
605 using integral_type = int;
606 using base_type = atomic_base<int>;
607
608 atomic() = default;
609 ~atomic() noexcept = default;
610 atomic(const atomic&) = delete;
611 atomic& operator=(const atomic&) = delete;
612 atomic& operator=(const atomic&) volatile = delete;
613 atomic(atomic&&) noexcept = default;
614 atomic& operator=(atomic&&) noexcept = default;
615
616 constexpr atomic(const integral_type value) noexcept :
617 base_type(value) {}
618
619 using base_type::operator integral_type;
620 using base_type::operator=;
621
622 static constexpr bool is_always_lock_free = true;
623};
624
626template <>
627struct atomic<unsigned int> : atomic_base<unsigned int> {
628 using integral_type = unsigned int;
629 using base_type = atomic_base<unsigned int>;
630
631 atomic() = default;
632 ~atomic() noexcept = default;
633 atomic(const atomic&) = delete;
634 atomic& operator=(const atomic&) = delete;
635 atomic& operator=(const atomic&) volatile = delete;
636 atomic(atomic&&) noexcept = default;
637 atomic& operator=(atomic&&) noexcept = default;
638
639 constexpr atomic(const integral_type value) noexcept :
640 base_type(value) {}
641
642 using base_type::operator integral_type;
643 using base_type::operator=;
644
645 static constexpr bool is_always_lock_free = true;
646};
647
649template <>
650struct atomic<long> : atomic_base<long> {
651 using integral_type = long;
652 using base_type = atomic_base<long>;
653
654 atomic() = default;
655 ~atomic() noexcept = default;
656 atomic(const atomic&) = delete;
657 atomic& operator=(const atomic&) = delete;
658 atomic& operator=(const atomic&) volatile = delete;
659 atomic(atomic&&) noexcept = default;
660 atomic& operator=(atomic&&) noexcept = default;
661
662 constexpr atomic(const integral_type value) noexcept :
663 base_type(value) {}
664
665 using base_type::operator integral_type;
666 using base_type::operator=;
667
668 static constexpr bool is_always_lock_free = true;
669};
670
672template <>
673struct atomic<unsigned long> : atomic_base<unsigned long> {
674 using integral_type = unsigned long;
675 using base_type = atomic_base<unsigned long>;
676
677 atomic() = default;
678 ~atomic() noexcept = default;
679 atomic(const atomic&) = delete;
680 atomic& operator=(const atomic&) = delete;
681 atomic& operator=(const atomic&) volatile = delete;
682 atomic(atomic&&) noexcept = default;
683 atomic& operator=(atomic&&) noexcept = default;
684
685 constexpr atomic(const integral_type value) noexcept :
686 base_type(value) {}
687
688 using base_type::operator integral_type;
689 using base_type::operator=;
690
691 static constexpr bool is_always_lock_free = true;
692};
693
695template <>
696struct atomic<long long> : atomic_base<long long> {
697 using integral_type = long long;
698 using base_type = atomic_base<long long>;
699
700 atomic() = default;
701 ~atomic() noexcept = default;
702 atomic(const atomic&) = delete;
703 atomic& operator=(const atomic&) = delete;
704 atomic& operator=(const atomic&) volatile = delete;
705 atomic(atomic&&) noexcept = default;
706 atomic& operator=(atomic&&) noexcept = default;
707
708 constexpr atomic(const integral_type value) noexcept :
709 base_type(value) {}
710
711 using base_type::operator integral_type;
712 using base_type::operator=;
713
714 static constexpr bool is_always_lock_free = true;
715};
716
718template <>
719struct atomic<unsigned long long> : atomic_base<unsigned long long> {
720 using integral_type = unsigned long long;
721 using base_type = atomic_base<unsigned long long>;
722
723 atomic() = default;
724 ~atomic() noexcept = default;
725 atomic(const atomic&) = delete;
726 atomic& operator=(const atomic&) = delete;
727 atomic& operator=(const atomic&) volatile = delete;
728 atomic(atomic&&) noexcept = default;
729 atomic& operator=(atomic&&) noexcept = default;
730
731 constexpr atomic(const integral_type value) noexcept :
732 base_type(value) {}
733
734 using base_type::operator integral_type;
735 using base_type::operator=;
736
737 static constexpr bool is_always_lock_free = true;
738};
739
741template <>
742struct atomic<wchar_t> : atomic_base<wchar_t> {
743 using integral_type = wchar_t;
744 using base_type = atomic_base<wchar_t>;
745
746 atomic() = default;
747 ~atomic() noexcept = default;
748 atomic(const atomic&) = delete;
749 atomic& operator=(const atomic&) = delete;
750 atomic& operator=(const atomic&) volatile = delete;
751 atomic(atomic&&) noexcept = default;
752 atomic& operator=(atomic&&) noexcept = default;
753
754 constexpr atomic(const integral_type value) noexcept :
755 base_type(value) {}
756
757 using base_type::operator integral_type;
758 using base_type::operator=;
759
760 static constexpr bool is_always_lock_free = true;
761};
762
763#ifdef NEFORCE_STANDARD_20
765template <>
766struct atomic<char8_t> : atomic_base<char8_t> {
767 using integral_type = char8_t;
768 using base_type = atomic_base<char8_t>;
769
770 atomic() = default;
771 ~atomic() noexcept = default;
772 atomic(const atomic&) = delete;
773 atomic& operator=(const atomic&) = delete;
774 atomic& operator=(const atomic&) volatile = delete;
775 atomic(atomic&&) noexcept = default;
776 atomic& operator=(atomic&&) noexcept = default;
777
778 constexpr atomic(const integral_type value) noexcept :
779 base_type(value) {}
780
781 using base_type::operator integral_type;
782 using base_type::operator=;
783
784 static constexpr bool is_always_lock_free = true;
785};
786#endif
787
789template <>
790struct atomic<char16_t> : atomic_base<char16_t> {
791 using integral_type = char16_t;
792 using base_type = atomic_base<char16_t>;
793
794 atomic() = default;
795 ~atomic() noexcept = default;
796 atomic(const atomic&) = delete;
797 atomic& operator=(const atomic&) = delete;
798 atomic& operator=(const atomic&) volatile = delete;
799 atomic(atomic&&) noexcept = default;
800 atomic& operator=(atomic&&) noexcept = default;
801
802 constexpr atomic(const integral_type value) noexcept :
803 base_type(value) {}
804
805 using base_type::operator integral_type;
806 using base_type::operator=;
807
808 static constexpr bool is_always_lock_free = true;
809};
810
812template <>
813struct atomic<char32_t> : atomic_base<char32_t> {
814 using integral_type = char32_t;
815 using base_type = atomic_base<char32_t>;
816
817 atomic() = default;
818 ~atomic() noexcept = default;
819 atomic(const atomic&) = delete;
820 atomic& operator=(const atomic&) = delete;
821 atomic& operator=(const atomic&) volatile = delete;
822 atomic(atomic&&) noexcept = default;
823 atomic& operator=(atomic&&) noexcept = default;
824
825 constexpr atomic(const integral_type value) noexcept :
826 base_type(value) {}
827
828 using base_type::operator integral_type;
829 using base_type::operator=;
830
831 static constexpr bool is_always_lock_free = true;
832};
833
835template <>
836struct atomic<float> : atomic_float_base<float> {
837 atomic() = default;
838 ~atomic() noexcept = default;
839 atomic(const atomic&) = delete;
840 atomic& operator=(const atomic&) = delete;
841 atomic& operator=(const atomic&) volatile = delete;
842 atomic(atomic&&) noexcept = default;
843 atomic& operator=(atomic&&) noexcept = default;
844
845 constexpr atomic(const float value) noexcept :
846 atomic_float_base<float>(value) {}
847
848 using atomic_float_base<float>::operator=;
849};
850
852template <>
853struct atomic<double> : atomic_float_base<double> {
854 atomic() = default;
855 ~atomic() noexcept = default;
856 atomic(const atomic&) = delete;
857 atomic& operator=(const atomic&) = delete;
858 atomic& operator=(const atomic&) volatile = delete;
859 atomic(atomic&&) noexcept = default;
860 atomic& operator=(atomic&&) noexcept = default;
861
862 constexpr atomic(const double value) noexcept :
863 atomic_float_base<double>(value) {}
864
865 using atomic_float_base<double>::operator=;
866};
867
869template <>
870struct atomic<long double> : atomic_float_base<long double> {
871 atomic() = default;
872 ~atomic() noexcept = default;
873 atomic(const atomic&) = delete;
874 atomic& operator=(const atomic&) = delete;
875 atomic& operator=(const atomic&) volatile = delete;
876 atomic(atomic&&) noexcept = default;
877 atomic& operator=(atomic&&) noexcept = default;
878
879 constexpr atomic(const long double value) noexcept :
880 atomic_float_base<long double>(value) {}
881
882 using atomic_float_base<long double>::operator=;
883};
884 // AtomicOperations
886 // AsyncComponents
888
889NEFORCE_END_NAMESPACE__
890#endif // NEFORCE_CORE_ASYNC_ATOMIC_HPP__
原子操作基本工具
NEFORCE_NODISCARD constexpr T * addressof(T &x) noexcept
获取对象的地址
NEFORCE_ALWAYS_INLINE_INLINE void atomic_store_any(T *ptr, remove_volatile_t< T > value, const memory_order mo) noexcept
通用原子存储操作
NEFORCE_CONSTEXPR17 bool is_always_lock_free() noexcept
检查是否支持无锁操作
NEFORCE_ALWAYS_INLINE_INLINE remove_volatile_t< T > atomic_load_any(const T *ptr, memory_order mo) noexcept
通用原子加载操作
NEFORCE_ALWAYS_INLINE_INLINE 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
通用弱比较交换操作
NEFORCE_ALWAYS_INLINE_INLINE remove_volatile_t< T > atomic_exchange_any(T *ptr, remove_volatile_t< T > desired, memory_order mo) noexcept
通用原子交换操作
NEFORCE_ALWAYS_INLINE_INLINE 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
通用强比较交换操作
#define NEFORCE_CONSTEXPR_ASSERT(COND)
编译时常量断言
constexpr bool is_valid_cmpexch_failure_order(const memory_order mo) noexcept
检查比较交换失败内存顺序是否有效
NEFORCE_INLINE17 constexpr auto memory_order_seq_cst
顺序一致性内存顺序常量
memory_order
内存顺序
constexpr memory_order cmpexch_failure_order(const memory_order mo) noexcept
获取原子比较交换操作失败时的内存顺序
NEFORCE_INLINE17 constexpr bool is_copy_constructible_v
is_copy_constructible的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_move_assignable_v
is_move_assignable的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_trivially_copyable_v
is_trivially_copyable的便捷变量模板
NEFORCE_INLINE17 constexpr bool is_move_constructible_v
is_move_constructible的便捷变量模板
NEFORCE_INLINE17 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版本的简化版强比较交换操作