MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
atomic.hpp
浏览该文件的文档.
1#ifndef MSTL_CORE_ASYNC_ATOMIC_HPP__
2#define MSTL_CORE_ASYNC_ATOMIC_HPP__
3
10
11#include "atomic_base.hpp"
13
19
20template <typename T>
21struct atomic;
22
23#define __MSTL_ATOMIC_CONSTRUCTIONS \
24 atomic() = default; \
25 ~atomic() noexcept = default; \
26 atomic(const atomic&) = delete; \
27 atomic& operator =(const atomic&) = delete; \
28 atomic& operator =(const atomic&) volatile = delete; \
29 atomic(atomic&&) noexcept = default; \
30 atomic& operator =(atomic&&) noexcept = default;
31
39template <typename T>
40struct atomic {
41 using value_type = T;
42
43private:
44 static constexpr int min_align = (sizeof(T) & (sizeof(T) - 1)) || sizeof(T) > 16 ? 0 : sizeof(T);
45 static constexpr int align_inner = min_align > alignof(T) ? min_align : alignof(T);
46
47 alignas(align_inner) T value_;
48
49 static_assert(is_trivially_copyable_v<T>, "atomic requires a trivially copyable type");
50 static_assert(sizeof(T) > 0, "Incomplete or zero-sized types are not supported");
51 static_assert(is_copy_constructible_v<T>, "atomic need copy constructible T");
52 static_assert(is_move_constructible_v<T>, "atomic need move constructible T");
53 static_assert(is_copy_assignable_v<T>, "atomic copy move assignable T");
54 static_assert(is_move_assignable_v<T>, "atomic need move assignable T");
55
56public:
59
60 __MSTL_ATOMIC_CONSTRUCTIONS
61
66 constexpr atomic(T value) noexcept
67 : value_(value) {}
68
73 operator T() const noexcept {
74 return load();
75 }
76
80 operator T() const volatile noexcept {
81 return load();
82 }
83
89 T operator =(T value) noexcept {
90 atomic::store(value);
91 return value;
92 }
93
97 T operator =(T value) volatile noexcept {
98 atomic::store(value);
99 return value;
100 }
101
106 bool is_lock_free() const noexcept {
107 return is_always_lock_free;
108 }
109
113 bool is_lock_free() const volatile noexcept {
114 return is_always_lock_free;
115 }
116
122 void store(T value, const memory_order mo = memory_order_seq_cst) noexcept {
123 _MSTL atomic_store_any(_MSTL addressof(value_), value, mo);
124 }
125
129 void store(T value, const memory_order mo = memory_order_seq_cst) volatile noexcept {
130 _MSTL atomic_store_any(_MSTL addressof(value_), value, mo);
131 }
132
138 T load(const memory_order mo = memory_order_seq_cst) const noexcept {
139 return _MSTL atomic_load_any(_MSTL addressof(value_), mo);
140 }
141
145 T load(const memory_order mo = memory_order_seq_cst) const volatile noexcept {
146 return _MSTL atomic_load_any(_MSTL addressof(value_), mo);
147 }
148
155 T exchange(T value, const memory_order mo = memory_order_seq_cst) noexcept {
156 return _MSTL atomic_exchange_any(_MSTL addressof(value_), value, mo);
157 }
158
162 T exchange(T value, const memory_order mo = memory_order_seq_cst) volatile noexcept {
163 return _MSTL atomic_exchange_any(_MSTL addressof(value_), value, mo);
164 }
165
174 bool compare_exchange_weak(T& expected, T desired,
175 const memory_order success, const memory_order failure) noexcept {
176 MSTL_CONSTEXPR_ASSERT(is_valid_cmpexch_failure_order(failure));
177 return _MSTL atomic_cmpexch_weak_any(_MSTL addressof(value_), &expected, &desired, success, failure);
178 }
179
183 bool compare_exchange_weak(T& expected, T desired,
184 const memory_order success, const memory_order failure) volatile noexcept {
185 MSTL_CONSTEXPR_ASSERT(is_valid_cmpexch_failure_order(failure));
186 return _MSTL atomic_cmpexch_weak_any(_MSTL addressof(value_), &expected, &desired, success, failure);
187 }
188
196 bool compare_exchange_weak(T& expected, T desired,
197 const memory_order mo = memory_order_seq_cst) noexcept {
198 return atomic::compare_exchange_weak(expected, desired, mo, cmpexch_failure_order(mo));
199 }
200
204 bool compare_exchange_weak(T& expected, T desired,
205 const memory_order mo = memory_order_seq_cst) volatile noexcept {
206 return atomic::compare_exchange_weak(expected, desired, mo, cmpexch_failure_order(mo));
207 }
208
217 bool compare_exchange_strong(T& expected, T desired,
218 const memory_order success, const memory_order failure) noexcept {
219 MSTL_CONSTEXPR_ASSERT(is_valid_cmpexch_failure_order(failure));
221 _MSTL addressof(value_), _MSTL addressof(expected),
222 _MSTL addressof(desired), success, failure);
223 }
224
228 bool compare_exchange_strong(T& expected, T desired,
229 const memory_order success, const memory_order failure) volatile noexcept {
230 MSTL_CONSTEXPR_ASSERT(is_valid_cmpexch_failure_order(failure));
232 _MSTL addressof(value_), _MSTL addressof(expected),
233 _MSTL addressof(desired), success, failure);
234 }
235
243 bool compare_exchange_strong(T& expected, T value,
244 const memory_order mo = memory_order_seq_cst) noexcept {
245 return atomic::compare_exchange_strong(expected, value, mo, cmpexch_failure_order(mo));
246 }
247
251 bool compare_exchange_strong(T& expected, T value,
252 const memory_order mo = memory_order_seq_cst) volatile noexcept {
253 return atomic::compare_exchange_strong(expected, value, mo, cmpexch_failure_order(mo));
254 }
255};
256
261template <typename T>
262struct atomic<T*> : atomic_base<T*> {
263 __MSTL_ATOMIC_CONSTRUCTIONS
264
265 explicit atomic(T* value) noexcept : atomic_base<T*>(value) {}
266
267 using atomic_base<T*>::operator =;
268};
269
274template <typename T>
275struct atomic<T&> : atomic_ref_base<T> {
276 __MSTL_ATOMIC_CONSTRUCTIONS
277
278 explicit atomic(T& value) noexcept : 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:
297 static constexpr bool is_always_lock_free = true;
298
299 __MSTL_ATOMIC_CONSTRUCTIONS
300
305 constexpr atomic(const bool value) noexcept
306 : base_(value) {}
307
313 bool operator =(const bool value) noexcept {
314 return base_.operator =(value);
315 }
316
320 bool operator =(const bool value) volatile noexcept {
321 return base_.operator =(value);
322 }
323
328 operator bool() const noexcept {
329 return base_.load();
330 }
331
335 operator bool() const volatile noexcept {
336 return base_.load();
337 }
338
343 bool is_lock_free() const noexcept {
344 return base_.is_lock_free();
345 }
346
350 bool is_lock_free() const volatile noexcept {
351 return base_.is_lock_free();
352 }
353
359 void store(const bool value, const memory_order mo = memory_order_seq_cst) noexcept {
360 base_.store(value, mo);
361 }
362
366 void store(const bool value, const memory_order mo = memory_order_seq_cst) volatile noexcept {
367 base_.store(value, mo);
368 }
369
375 bool load(const memory_order mo = memory_order_seq_cst) const noexcept {
376 return base_.load(mo);
377 }
378
382 bool load(const memory_order mo = memory_order_seq_cst) const volatile noexcept {
383 return base_.load(mo);
384 }
385
392 bool exchange(const bool value, const memory_order mo = memory_order_seq_cst) noexcept {
393 return base_.exchange(value, mo);
394 }
395
399 bool exchange(const bool value, const memory_order mo = memory_order_seq_cst) volatile noexcept {
400 return base_.exchange(value, mo);
401 }
402
411 bool compare_exchange_weak(bool& value1, const bool value2,
412 const memory_order success, const memory_order failure) noexcept {
413 return base_.compare_exchange_weak(value1, value2, success, failure);
414 }
415
419 bool compare_exchange_weak(bool& value1, const bool value2,
420 const memory_order success, const memory_order failure) volatile noexcept {
421 return base_.compare_exchange_weak(value1, value2, success, failure);
422 }
423
431 bool compare_exchange_weak(bool& value1, const bool value2,
432 const memory_order mo = memory_order_seq_cst) noexcept {
433 return base_.compare_exchange_weak(value1, value2, mo);
434 }
435
439 bool compare_exchange_weak(bool& value1, const bool value2,
440 const memory_order mo = memory_order_seq_cst) volatile noexcept {
441 return base_.compare_exchange_weak(value1, value2, mo);
442 }
443
452 bool compare_exchange_strong(bool& value1, const bool value2,
453 const memory_order success, const memory_order failure) noexcept {
454 return base_.compare_exchange_strong(value1, value2, success, failure);
455 }
456
460 bool compare_exchange_strong(bool& value1, const bool value2,
461 const memory_order success, const memory_order failure) volatile noexcept {
462 return base_.compare_exchange_strong(value1, value2, success, failure);
463 }
464
472 bool compare_exchange_strong(bool& value1, const bool value2,
473 const memory_order mo = memory_order_seq_cst) noexcept {
474 return base_.compare_exchange_strong(value1, value2, mo);
475 }
476
480 bool compare_exchange_strong(bool& value1, const bool value2,
481 const memory_order mo = memory_order_seq_cst) volatile noexcept {
482 return base_.compare_exchange_strong(value1, value2, mo);
483 }
484
490 void wait(const bool old, const memory_order mo = memory_order_seq_cst) const noexcept {
491 base_.wait(old, mo);
492 }
493
497 void notify_one() noexcept {
498 base_.notify_one();
499 }
500
504 void notify_all() noexcept {
505 base_.notify_all();
506 }
507};
508
510template <>
511struct atomic<char> : atomic_base<char> {
512 using integral_type = char;
513 using base_type = atomic_base<char>;
514
515 __MSTL_ATOMIC_CONSTRUCTIONS
516
517 constexpr atomic(const integral_type value) noexcept : base_type(value) {}
518
519 using base_type::operator integral_type;
520 using base_type::operator =;
521
522 static constexpr bool is_always_lock_free = true;
523};
524
526template <>
527struct atomic<signed char> : atomic_base<signed char> {
528 using integral_type = signed char;
529 using base_type = atomic_base<signed char>;
530
531 __MSTL_ATOMIC_CONSTRUCTIONS
532
533 constexpr atomic(const integral_type value) noexcept : base_type(value) {}
534
535 using base_type::operator integral_type;
536 using base_type::operator =;
537
538 static constexpr bool is_always_lock_free = true;
539};
540
542template <>
543struct atomic<unsigned char> : atomic_base<unsigned char> {
544 using integral_type = unsigned char;
545 using base_type = atomic_base<unsigned char>;
546
547 __MSTL_ATOMIC_CONSTRUCTIONS
548
549 constexpr atomic(const integral_type value) noexcept : base_type(value) {}
550
551 using base_type::operator integral_type;
552 using base_type::operator =;
553
554 static constexpr bool is_always_lock_free = true;
555};
556
558template <>
559struct atomic<short> : atomic_base<short> {
560 using integral_type = short;
561 using base_type = atomic_base<short>;
562
563 __MSTL_ATOMIC_CONSTRUCTIONS
564
565 constexpr atomic(const integral_type value) noexcept : base_type(value) {}
566
567 using base_type::operator integral_type;
568 using base_type::operator =;
569
570 static constexpr bool is_always_lock_free = true;
571};
572
574template <>
575struct atomic<unsigned short> : atomic_base<unsigned short> {
576 using integral_type = unsigned short;
577 using base_type = atomic_base<unsigned short>;
578
579 __MSTL_ATOMIC_CONSTRUCTIONS
580
581 constexpr atomic(const integral_type value) noexcept : base_type(value) {}
582
583 using base_type::operator integral_type;
584 using base_type::operator =;
585
586 static constexpr bool is_always_lock_free = true;
587};
588
590template <>
591struct atomic<int> : atomic_base<int> {
592 using integral_type = int;
593 using base_type = atomic_base<int>;
594
595 __MSTL_ATOMIC_CONSTRUCTIONS
596
597 constexpr atomic(const integral_type value) noexcept : base_type(value) {}
598
599 using base_type::operator integral_type;
600 using base_type::operator =;
601
602 static constexpr bool is_always_lock_free = true;
603};
604
606template <>
607struct atomic<unsigned int> : atomic_base<unsigned int> {
608 using integral_type = unsigned int;
609 using base_type = atomic_base<unsigned int>;
610
611 __MSTL_ATOMIC_CONSTRUCTIONS
612
613 constexpr atomic(const integral_type value) noexcept : base_type(value) {}
614
615 using base_type::operator integral_type;
616 using base_type::operator =;
617
618 static constexpr bool is_always_lock_free = true;
619};
620
622template <>
623struct atomic<long> : atomic_base<long> {
624 using integral_type = long;
625 using base_type = atomic_base<long>;
626
627 __MSTL_ATOMIC_CONSTRUCTIONS
628
629 constexpr atomic(const integral_type value) noexcept : base_type(value) {}
630
631 using base_type::operator integral_type;
632 using base_type::operator =;
633
634 static constexpr bool is_always_lock_free = true;
635};
636
638template <>
639struct atomic<unsigned long> : atomic_base<unsigned long> {
640 using integral_type = unsigned long;
641 using base_type = atomic_base<unsigned long>;
642
643 __MSTL_ATOMIC_CONSTRUCTIONS
644
645 constexpr atomic(const integral_type value) noexcept : base_type(value) {}
646
647 using base_type::operator integral_type;
648 using base_type::operator =;
649
650 static constexpr bool is_always_lock_free = true;
651};
652
654template <>
655struct atomic<long long> : atomic_base<long long> {
656 using integral_type = long long;
657 using base_type = atomic_base<long long>;
658
659 __MSTL_ATOMIC_CONSTRUCTIONS
660
661 constexpr atomic(const integral_type value) noexcept : base_type(value) {}
662
663 using base_type::operator integral_type;
664 using base_type::operator =;
665
666 static constexpr bool is_always_lock_free = true;
667};
668
670template <>
671struct atomic<unsigned long long> : atomic_base<unsigned long long> {
672 using integral_type = unsigned long long;
673 using base_type = atomic_base<unsigned long long>;
674
675 __MSTL_ATOMIC_CONSTRUCTIONS
676
677 constexpr atomic(const integral_type value) noexcept : base_type(value) {}
678
679 using base_type::operator integral_type;
680 using base_type::operator =;
681
682 static constexpr bool is_always_lock_free = true;
683};
684
686template <>
687struct atomic<wchar_t> : atomic_base<wchar_t> {
688 using integral_type = wchar_t;
689 using base_type = atomic_base<wchar_t>;
690
691 __MSTL_ATOMIC_CONSTRUCTIONS
692
693 constexpr atomic(const integral_type value) noexcept : base_type(value) {}
694
695 using base_type::operator integral_type;
696 using base_type::operator =;
697
698 static constexpr bool is_always_lock_free = true;
699};
700
701#ifdef MSTL_STANDARD_20__
703template <>
704struct atomic<char8_t> : atomic_base<char8_t> {
705 using integral_type = char8_t;
706 using base_type = atomic_base<char8_t>;
707
708 __MSTL_ATOMIC_CONSTRUCTIONS
709
710 constexpr atomic(const integral_type value) noexcept : base_type(value) {}
711
712 using base_type::operator integral_type;
713 using base_type::operator =;
714
715 static constexpr bool is_always_lock_free = true;
716};
717#endif
718
720template <>
721struct atomic<char16_t> : atomic_base<char16_t> {
722 using integral_type = char16_t;
723 using base_type = atomic_base<char16_t>;
724
725 __MSTL_ATOMIC_CONSTRUCTIONS
726
727 constexpr atomic(const integral_type value) noexcept : base_type(value) {}
728
729 using base_type::operator integral_type;
730 using base_type::operator =;
731
732 static constexpr bool is_always_lock_free = true;
733};
734
736template <>
737struct atomic<char32_t> : atomic_base<char32_t> {
738 using integral_type = char32_t;
739 using base_type = atomic_base<char32_t>;
740
741 __MSTL_ATOMIC_CONSTRUCTIONS
742
743 constexpr atomic(const integral_type value) noexcept : base_type(value) {}
744
745 using base_type::operator integral_type;
746 using base_type::operator =;
747
748 static constexpr bool is_always_lock_free = true;
749};
750
752template <>
753struct atomic<float> : atomic_float_base<float> {
754 __MSTL_ATOMIC_CONSTRUCTIONS
755
756 constexpr atomic(const float value) noexcept
757 : atomic_float_base<float>(value) {}
758
759 using atomic_float_base<float>::operator =;
760};
761
763template <>
764struct atomic<double> : atomic_float_base<double> {
765 __MSTL_ATOMIC_CONSTRUCTIONS
766
767 constexpr atomic(const double value) noexcept
768 : atomic_float_base<double>(value) {}
769
770 using atomic_float_base<double>::operator =;
771};
772
774template <>
775struct atomic<long double> : atomic_float_base<long double> {
776 __MSTL_ATOMIC_CONSTRUCTIONS
777
778 constexpr atomic(const long double value) noexcept
779 : atomic_float_base<long double>(value) {}
780
781 using atomic_float_base<long double>::operator =;
782};
783
784#undef __MSTL_ATOMIC_CONSTRUCTIONS
785
797
801
804#ifdef MSTL_STANDARD_20__
805using atomic_char8_t = atomic<char8_t>;
806#endif
809
818
822
827
830 // AtomicOperations
832
834#endif // MSTL_CORE_ASYNC_ATOMIC_HPP__
MSTL原子操作基本工具
MSTL_NODISCARD constexpr T * addressof(T &x) noexcept
获取对象的地址
atomic< bool > atomic_bool
布尔原子类型
atomic< ptrdiff_t > atomic_ptrdiff_t
指针差值类型原子类型
atomic< unsigned char > atomic_uchar
无符号字符原子类型
atomic< char16_t > atomic_char16_t
UTF-16字符原子类型
atomic< intptr_t > atomic_intptr_t
有符号指针整数原子类型
atomic< uint64_t > atomic_uint64_t
64位无符号整数原子类型
atomic< short > atomic_short
短整型原子类型
atomic< uint16_t > atomic_uint16_t
16位无符号整数原子类型
atomic< unsigned short > atomic_ushort
无符号短整型原子类型
atomic< uint32_t > atomic_uint32_t
32位无符号整数原子类型
atomic< float32_t > atomic_float32
32位浮点数原子类型
atomic< float > atomic_float
单精度浮点数原子类型
MSTL_ALWAYS_INLINE_INLINE remove_volatile_t< T > atomic_exchange_any(T *ptr, remove_volatile_t< T > desired, memory_order mo) noexcept
通用原子交换操作
atomic< uintmax_t > atomic_uintmax_t
最大无符号整数原子类型
MSTL_ALWAYS_INLINE_INLINE remove_volatile_t< T > atomic_load_any(const T *ptr, memory_order mo) noexcept
通用原子加载操作
atomic< intmax_t > atomic_intmax_t
最大有符号整数原子类型
atomic< size_t > atomic_size_t
大小类型原子类型
atomic< long double > atomic_ldouble
扩展精度浮点数原子类型
atomic< decimal_t > atomic_decimal
十进制浮点数原子类型
atomic< float64_t > atomic_float64
64位浮点数原子类型
atomic< int16_t > atomic_int16_t
16位有符号整数原子类型
atomic< long long > atomic_llong
长长整型原子类型
atomic< int64_t > atomic_int64_t
64位有符号整数原子类型
atomic< int > atomic_int
整型原子类型
atomic< unsigned long > atomic_ulong
无符号长整型原子类型
atomic< char32_t > atomic_char32_t
UTF-32字符原子类型
atomic< signed char > atomic_schar
有符号字符原子类型
atomic< unsigned int > atomic_uint
无符号整型原子类型
atomic< double > atomic_double
双精度浮点数原子类型
atomic< uint8_t > atomic_uint8_t
8位无符号整数原子类型
MSTL_ALWAYS_INLINE_INLINE void atomic_store_any(T *ptr, remove_volatile_t< T > value, const memory_order mo) noexcept
通用原子存储操作
atomic< long > atomic_long
长整型原子类型
atomic< int32_t > atomic_int32_t
32位有符号整数原子类型
atomic< unsigned long long > atomic_ullong
无符号长长整型原子类型
atomic< int8_t > atomic_int8_t
8位有符号整数原子类型
MSTL_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
通用弱比较交换操作
MSTL_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
通用强比较交换操作
atomic< uintptr_t > atomic_uintptr_t
无符号指针整数原子类型
atomic< wchar_t > atomic_wchar_t
宽字符原子类型
atomic< char > atomic_char
字符原子类型
constexpr bool is_valid_cmpexch_failure_order(const memory_order mo) noexcept
检查比较交换失败内存顺序是否有效
memory_order
内存顺序
MSTL_INLINE17 constexpr auto memory_order_seq_cst
顺序一致性内存顺序常量
constexpr memory_order cmpexch_failure_order(const memory_order mo) noexcept
获取原子比较交换操作失败时的内存顺序
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
static constexpr bool is_always_lock_free
是否总是无锁
bool is_lock_free() const noexcept
检查是否支持无锁操作
bool compare_exchange_strong(bool &value1, const bool value2, const memory_order mo=memory_order_seq_cst) noexcept
简化版强比较交换操作
void store(const bool value, const memory_order mo=memory_order_seq_cst) 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
强比较交换操作
constexpr atomic(const bool value) 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
原子加载操作
static constexpr bool is_always_lock_free
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版本的原子存储操作
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
原子交换操作
constexpr atomic(T value) noexcept
构造函数
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版本的简化版强比较交换操作