1#ifndef MSTL_CORE_ASYNC_CONDITION_VARIABLE_HPP__
2#define MSTL_CORE_ASYNC_CONDITION_VARIABLE_HPP__
42class MSTL_API condition_variable_base {
44#ifdef MSTL_PLATFORM_WINDOWS__
45 using native_handle_type = ::CONDITION_VARIABLE;
47 using native_handle_type = ::pthread_cond_t;
51 native_handle_type cond_;
54 condition_variable_base();
55 condition_variable_base(
const condition_variable_base&) =
delete;
56 condition_variable_base& operator =(
const condition_variable_base&) =
delete;
57 ~condition_variable_base();
59 native_handle_type* native_handle()
noexcept {
return &cond_; }
69 void wait(mutex& mtx);
100 void notify_one() noexcept;
107 void notify_all() noexcept;
135 template <
typename Dur>
138 auto s = util.to_sec();
140 cond_.wait_until(*
lock.mutex(),
true, s.since_epoch().count(), ns.
count());
153 template <
typename Dur>
156 auto sec = util.to_sec();
158 cond_.wait_until(*
lock.mutex(), sec.since_epoch().count(), nanosec.count());
183 return cond_.native_handle();
207 cond_.wait(*
lock.mutex());
218 template <
typename Pred>
230 template <
typename Dur>
232 return this->__wait_until_impl(
lock, util);
242 template <
typename Dur>
244 return this->__wait_until_impl(
lock, util);
257 template <
typename Clock,
typename Dur>
259 const typename Clock::time_point entry = Clock::now();
265 if (Clock::now() < util) {
283 template <
typename Clock,
typename Dur,
typename Pred>
301 template <
typename Rep,
typename Period>
317 template <
typename Rep,
typename Period,
typename Pred>
cv_status wait_until(smart_lock< mutex > &lock, const time_point< steady_clock, Dur > &util)
等待直到稳定时钟时间点
bool wait_for(smart_lock< mutex > &lock, const duration< Rep, Period > &rest, Pred pred)
带谓词的等待指定持续时间
native_handle_type * native_handle() noexcept
获取原生句柄
cv_status wait_for(smart_lock< mutex > &lock, const duration< Rep, Period > &rest)
等待指定的持续时间
~condition_variable()=default
析构函数
condition_variable()=default
构造函数
void notify_all() noexcept
通知所有等待线程
void notify_one() noexcept
通知一个等待线程
void wait(smart_lock< mutex > &lock, Pred pred)
带谓词的无限期等待
cv_status wait_until(smart_lock< mutex > &lock, const time_point< system_clock, Dur > &util)
等待直到系统时钟时间点
bool wait_until(smart_lock< mutex > &lock, const time_point< Clock, Dur > &util, Pred pred)
带谓词的等待直到时间点
_MSTL steady_clock clock_type
默认时钟类型
base_type::native_handle_type native_handle_type
原生句柄类型
void wait(smart_lock< mutex > &lock)
无限期等待
_INNER condition_variable_base base_type
基类类型
cv_status wait_until(smart_lock< mutex > &lock, const time_point< Clock, Dur > &util)
等待直到任意时钟时间点
long long int64_t
64位有符号整数类型
duration< int64_t, nano > nanoseconds
纳秒持续时间
MSTL_CONST_FUNCTION MSTL_CONSTEXPR14 decimal_t ceil(const decimal_t x) noexcept
向上取整
lock< Mutex, true > smart_lock
智能锁管理器的便捷类型别名
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_INNER__
结束inner命名空间
#define _INNER
inner命名空间前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
#define MSTL_BEGIN_INNER__
开始inner命名空间
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result)
移动范围元素
constexpr rep count() const noexcept
获取计数值
static time_point now() noexcept
获取当前时间点
static time_point now() noexcept
获取当前时间点