1#ifndef MSTL_CORE_ASYNC_SEMAPHORE_HPP__
2#define MSTL_CORE_ASYNC_SEMAPHORE_HPP__
30template <platform_wait_t LeastMaxValue = numeric_traits<platform_wait_t>::max()>
32 static_assert(LeastMaxValue >= 0,
"LeastMaxValue should be upper than zero.");
43 MSTL_ALWAYS_INLINE
bool do_try_acquire()
noexcept {
49 &counter_, &old_value, old_value - 1,
62 MSTL_CONSTEXPR_ASSERT(desired >= 0);
97 auto const pred = [
this] {
98 return this->do_try_acquire();
110 auto const pred = [
this] {
111 return this->do_try_acquire();
125 template <
typename Rep,
typename Period>
127 auto const pred = [
this] {
128 return this->do_try_acquire();
142 template <
typename Clock,
typename Dur>
144 auto const pred = [
this] {
145 return this->do_try_acquire();
void release(const platform_wait_t update=1) noexcept
释放信号量
bool try_acquire_for(const duration< Rep, Period > &relative) noexcept
在指定时间内尝试获取信号量
bool try_acquire_until(const time_point< Clock, Dur > &timeout) noexcept
在指定时间点前尝试获取信号量
counting_semaphore(const platform_wait_t desired) noexcept
构造函数
void acquire() noexcept
获取信号量
~counting_semaphore()=default
析构函数
static constexpr platform_wait_t max() noexcept
获取信号量的最大可能值
bool try_acquire() noexcept
尝试获取信号量
void atomic_wait_address(const T *addr, Pred pred) noexcept
基于谓词的原子等待
MSTL_ALWAYS_INLINE_INLINE remove_volatile_t< T > atomic_load(const volatile T *ptr, const memory_order mo) noexcept
原子加载操作
bool atomic_spin(Pred &pred, Spin spin=Spin{}) noexcept
原子自旋等待
MSTL_ALWAYS_INLINE_INLINE bool atomic_cmpexch_strong(volatile T *ptr, remove_volatile_t< T > *expected, remove_volatile_t< T > desired, const memory_order success, const memory_order failure) noexcept
强比较交换操作
void atomic_notify_address(const T *addr, const bool all) noexcept
原子通知
bool atomic_wait_address_until(const T *addr, Pred pred, const time_point< Clock, Dur > &timeout) noexcept
基于谓词的原子定时等待(绝对时间)
MSTL_ALWAYS_INLINE_INLINE remove_volatile_t< T > atomic_fetch_add(volatile T *ptr, atomic_diff_t< T > value, const memory_order mo) noexcept
原子获取并添加操作
bool atomic_wait_address_for(const T *addr, Pred pred, const duration< Rep, Period > &rt) noexcept
基于谓词的原子定时等待(相对时间)
int platform_wait_t
平台等待类型别名
MSTL_INLINE17 constexpr auto memory_order_release
释放内存顺序常量
MSTL_INLINE17 constexpr auto memory_order_relaxed
宽松内存顺序常量
MSTL_INLINE17 constexpr auto memory_order_acquire
获取内存顺序常量
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
counting_semaphore< 1 > binary_semaphore
二元信号量