libxr 1.0
Want to be the best embedded framework
|
条件变量封装类 / Condition variable wrapper class More...
#include <condition_var.hpp>
Public Member Functions | |
ConditionVar () | |
默认构造函数 / Default constructor | |
~ConditionVar () | |
析构函数 / Destructor | |
ErrorCode | Wait (uint32_t timeout) |
等待条件变量 / Waits for the condition variable | |
void | Signal () |
发送信号唤醒一个等待线程 / Signals one waiting thread | |
void | Broadcast () |
广播信号唤醒所有等待线程 / Broadcasts a signal to wake up all waiting threads | |
Private Attributes | |
condition_var_handle | handle_ |
底层条件变量句柄 / Underlying condition variable handle | |
条件变量封装类 / Condition variable wrapper class
该类提供了条件变量 (Condition Variable
) 的封装,实现了线程间的同步机制, 允许一个线程等待某个条件发生,另一个线程通知该条件已满足。 This class provides a wrapper for condition variables, implementing a synchronization mechanism where one thread waits for a condition to occur while another thread signals the condition.
Definition at line 19 of file condition_var.hpp.
ConditionVar::ConditionVar | ( | ) |
默认构造函数 / Default constructor
初始化条件变量的内部句柄。 Initializes the internal handle of the condition variable.
Definition at line 7 of file condition_var.cpp.
ConditionVar::~ConditionVar | ( | ) |
析构函数 / Destructor
释放条件变量资源。 Releases the condition variable resources.
Definition at line 10 of file condition_var.cpp.
void ConditionVar::Broadcast | ( | ) |
广播信号唤醒所有等待线程 / Broadcasts a signal to wake up all waiting threads
该方法通知所有正在等待条件变量的线程,使它们继续执行。 This method notifies all threads waiting on the condition variable to resume execution.
Definition at line 22 of file condition_var.cpp.
void ConditionVar::Signal | ( | ) |
发送信号唤醒一个等待线程 / Signals one waiting thread
该方法通知一个正在等待条件变量的线程,使其继续执行。 This method notifies a single thread waiting on the condition variable to resume execution.
Definition at line 20 of file condition_var.cpp.
ErrorCode ConditionVar::Wait | ( | uint32_t | timeout | ) |
等待条件变量 / Waits for the condition variable
timeout | 等待的超时时间(毫秒) / Timeout in milliseconds |
ErrorCode::OK
,超时返回 ErrorCode::TIMEOUT
/ Operation result: returns ErrorCode::OK
on success, ErrorCode::TIMEOUT
if timed out该方法会阻塞当前线程,直到收到信号或超时。 This method blocks the current thread until it receives a signal or the timeout occurs.
Definition at line 12 of file condition_var.cpp.
|
private |
底层条件变量句柄 / Underlying condition variable handle
Definition at line 23 of file condition_var.hpp.