42 void Set() noexcept {
value_.store(1u, std::memory_order_release); }
47 void Clear() noexcept {
value_.store(0u, std::memory_order_release); }
55 [[nodiscard]]
bool IsSet() const noexcept
57 return value_.load(std::memory_order_acquire) != 0u;
68 return value_.exchange(1u, std::memory_order_acq_rel) != 0u;
79 return value_.exchange(0u, std::memory_order_acq_rel) != 0u;
90 [[nodiscard]]
bool Exchange(
bool set_value)
noexcept
92 return value_.exchange(set_value ? 1u : 0u, std::memory_order_acq_rel) != 0u;
174 [[nodiscard]]
bool Exchange(
bool set_value)
noexcept
197template <
typename FlagT>
void Set() noexcept
置位标志 / Set the flag
Atomic(const Atomic &)=delete
禁用拷贝构造与拷贝赋值 / Copy construction and copy assignment are disabled
bool TestAndClear() noexcept
测试并清除:清除并返回旧状态 / Test-and-clear: clear and return previous state
Atomic()=default
构造函数,默认未置位 / Constructor, default cleared
bool TestAndSet() noexcept
测试并置位:置位并返回旧状态 / Test-and-set: set and return previous state
bool IsSet() const noexcept
判断是否已置位 / Check whether the flag is set
bool Exchange(bool set_value) noexcept
交换:写入指定值并返回旧状态 / Exchange: set to desired value and return previous state
void Clear() noexcept
清除标志 / Clear the flag
std::atomic< uint8_t > value_
标志值(0=clear, 1=set)/ Flag value (0=clear, 1=set)
普通标志位(非原子)/ Non-atomic flag
Plain()=default
构造函数,默认未置位 / Constructor, default cleared
void Set() noexcept
置位标志 / Set the flag
bool TestAndSet() noexcept
测试并置位:置位并返回旧状态 / Test-and-set: set and return previous state
bool TestAndClear() noexcept
测试并清除:清除并返回旧状态 / Test-and-clear: clear and return previous state
bool IsSet() const noexcept
判断是否已置位 / Check whether the flag is set
void Clear() noexcept
清除标志 / Clear the flag
bool Exchange(bool set_value) noexcept
交换:写入指定值并返回旧状态 / Exchange: set to desired value and return previous state
bool value_
标志值(false=clear, true=set)/ Flag value (false=clear, true=set)
作用域标志管理器:构造时写入指定值,析构时恢复原值 / Scoped flag restorer: set on entry, restore on exit
bool prev_
进入作用域前的旧值 / Previous value before entering scope
~ScopedRestore()
析构函数:恢复旧值 / Destructor: restore previous value
ScopedRestore(const ScopedRestore &)=delete
禁用拷贝构造与拷贝赋值 / Copy construction and copy assignment are disabled
FlagT & flag_
被管理的标志对象 / Managed flag instance
ScopedRestore(FlagT &flag, bool set_value=true)
构造函数:写入 set_value 并保存旧值 / Constructor: set set_value and store previous value