Console Library 8.0.0
A header-only library that makes C++ simple
Loading...
Searching...
No Matches
console::Event Class Reference

线程同步事件类,用于线程间通信。 More...

#include <event.h>

Public Member Functions

 Event ()
 默认构造函数,初始化事件标志为 false。
void set ()
 设置事件标志为 true,并通知所有等待的线程。
void clear ()
 清除事件标志为 false。
void wait () const
 等待事件标志变为 true。
template<class Rep, class Period>
bool wait (const std::chrono::duration< Rep, Period > &duration) const
 等待事件标志变为 true,带有超时机制。
bool wait (Time timeout) const
 等待事件标志变为 true,带有超时机制。
bool wait (double seconds) const
 等待事件标志变为 true,带有超时机制。
bool is_set () const
 检查事件标志是否为 true。
 Event (const Event &)=delete
 禁止拷贝构造。
Event & operator= (const Event &)=delete
 禁止拷贝赋值。
 Event (Event &&other)=delete
 禁止移动构造。
Event & operator= (Event &&other)=delete
 禁止移动赋值。

Private Attributes

bool flag_
 事件标志,用于线程间通信
std::mutex mutex_
 互斥锁,保护事件标志
std::condition_variable cv_
 条件变量,用于线程间同步

Detailed Description

线程同步事件类,用于线程间通信。

Constructor & Destructor Documentation

◆ Event() [1/3]

console::Event::Event ( )
inline

默认构造函数,初始化事件标志为 false。

◆ Event() [2/3]

console::Event::Event ( const Event & )
delete

禁止拷贝构造。

◆ Event() [3/3]

console::Event::Event ( Event && other)
delete

禁止移动构造。

Member Function Documentation

◆ clear()

void console::Event::clear ( )
inline

清除事件标志为 false。

◆ is_set()

bool console::Event::is_set ( ) const
inline

检查事件标志是否为 true。

Returns
如果事件标志为 true,则返回 true;否则返回 false。

◆ operator=() [1/2]

Event & console::Event::operator= ( const Event & )
delete

禁止拷贝赋值。

◆ operator=() [2/2]

Event & console::Event::operator= ( Event && other)
delete

禁止移动赋值。

◆ set()

void console::Event::set ( )
inline

设置事件标志为 true,并通知所有等待的线程。

◆ wait() [1/4]

void console::Event::wait ( ) const
inline

等待事件标志变为 true。

◆ wait() [2/4]

template<class Rep, class Period>
bool console::Event::wait ( const std::chrono::duration< Rep, Period > & duration) const
inline

等待事件标志变为 true,带有超时机制。

Parameters
duration等待的时间。
Returns
如果在指定时间内事件标志变为 true,则返回 true;否则返回 false。

◆ wait() [3/4]

bool console::Event::wait ( double seconds) const
inline

等待事件标志变为 true,带有超时机制。

Parameters
seconds等待的时间(秒)。
Returns
如果在指定时间内事件标志变为 true,则返回 true;否则返回 false。

◆ wait() [4/4]

bool console::Event::wait ( Time timeout) const
inline

等待事件标志变为 true,带有超时机制。

Parameters
timeout等待的时间。
Returns
如果在指定时间内事件标志变为 true,则返回 true;否则返回 false。

Member Data Documentation

◆ cv_

std::condition_variable console::Event::cv_
mutableprivate

条件变量,用于线程间同步

◆ flag_

bool console::Event::flag_
private

事件标志,用于线程间通信

◆ mutex_

std::mutex console::Event::mutex_
mutableprivate

互斥锁,保护事件标志


The documentation for this class was generated from the following file: