1#ifndef MSTL_CORE_ASYNC_ATOMIC_FUTEX_HPP__
2#define MSTL_CORE_ASYNC_ATOMIC_FUTEX_HPP__
30template <u
int32_t WaiterBit = 0x80000000>
52 &data_, assumed | WaiterBit, has_timeout, sec, ns,
false);
54 if (!ret || ((operand == assumed) ==
equal)) {
78 &data_, assumed | WaiterBit, has_timeout, sec, ns,
true);
80 if (!ret || ((operand == assumed) ==
equal)) {
96 return load_and_test_until(
97 assumed, operand,
equal, mo,
false, 0, 0);
110 template <
typename Dur>
115 auto sec = atime.to_sec();
117 return this->load_and_test_until(
118 assumed, operand,
equal, mo,
119 true, sec.since_epoch().count(), ns);
132 template <
typename Dur>
137 auto sec = atime.to_sec();
139 return this->load_and_test_until_steady(
140 assumed, operand,
equal, mo,
141 true, sec.since_epoch().count(), ns);
159 MSTL_NODISCARD MSTL_ALWAYS_INLINE
uint32_t
161 return data_.load(mo) & ~WaiterBit;
175 if ((old & ~WaiterBit) != value) {
176 return (old & ~WaiterBit);
178 return load_and_test(old, value,
false, mo);
188 MSTL_ALWAYS_INLINE
void
191 if ((old & ~WaiterBit) == value) {
194 load_and_test(old, value,
true, mo);
206 template <
typename Rep,
typename Period>
207 MSTL_ALWAYS_INLINE
bool
225 template <
typename Clock,
typename Dur>
226 MSTL_ALWAYS_INLINE
bool
229 auto now = Clock::now();
236 }
while (now < atime);
248 template <
typename Dur>
249 MSTL_ALWAYS_INLINE
bool
253 if ((old & ~WaiterBit) == value) {
256 old = this->load_and_test_until_impl(old, value,
true, mo, atime);
257 return (old & ~WaiterBit) == value;
268 template <
typename Dur>
269 MSTL_ALWAYS_INLINE
bool
273 if ((old & ~WaiterBit) == value) {
276 old = this->load_and_test_until_impl(old, value,
true, mo, atime);
277 return (old & ~WaiterBit) == value;
288 const auto futex =
static_cast<uint32_t*
>(
static_cast<void*
>(&data_));
289 if (data_.exchange(value, mo) & WaiterBit) {
MSTL_ALWAYS_INLINE bool load_when_equal_until(const uint32_t value, const memory_order mo, const time_point< steady_clock, Dur > &atime)
在指定时间点前等待值等于指定值(单调时钟)
MSTL_ALWAYS_INLINE bool load_when_equal_for(const uint32_t value, const memory_order mo, const duration< Rep, Period > &rtime)
在指定时间内等待值等于指定值
MSTL_ALWAYS_INLINE void store_notify_all(const uint32_t value, const memory_order mo)
存储新值并通知所有等待线程
atomic_futex(const uint32_t data)
构造函数
MSTL_ALWAYS_INLINE void load_when_equal(const uint32_t value, const memory_order mo)
等待直到值等于指定值
MSTL_ALWAYS_INLINE bool load_when_equal_until(const uint32_t value, const memory_order mo, const time_point< system_clock, Dur > &atime)
在指定时间点前等待值等于指定值(系统时钟)
MSTL_ALWAYS_INLINE uint32_t load_when_not_equal(const uint32_t value, const memory_order mo)
等待直到值不等于指定值
MSTL_ALWAYS_INLINE bool load_when_equal_until(const uint32_t value, const memory_order mo, const time_point< Clock, Dur > &atime)
在指定时间点前等待值等于指定值(通用时钟)
MSTL_NODISCARD MSTL_ALWAYS_INLINE uint32_t load(const memory_order mo) const
原子加载数据
MSTL_NODISCARD constexpr bool equal(Iterator1 first1, Iterator1 last1, Iterator2 first2, BinaryPredicate binary_pred) noexcept(noexcept(++first1) &&noexcept(++first2) &&noexcept(binary_pred(*first1, *first2)))
比较两个范围是否相等
unsigned int uint32_t
32位无符号整数类型
long long int64_t
64位有符号整数类型
duration< int64_t, nano > nanoseconds
纳秒持续时间
void MSTL_API futex_notify(void *addr, bool all) noexcept
通知等待的线程
bool futex_wait_until(const platform_wait_t *addr, platform_wait_t old, const time_point< Clock, Dur > &timeout)
FUTEX定时等待函数
MSTL_CONST_FUNCTION MSTL_CONSTEXPR14 decimal_t ceil(const decimal_t x) noexcept
向上取整
MSTL_INLINE17 constexpr auto memory_order_relaxed
宽松内存顺序常量
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) data(Container &cont) noexcept(noexcept(cont.data()))
获取容器的底层数据指针
constexpr rep count() const noexcept
获取计数值
static time_point now() noexcept
获取当前时间点