libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
condition_var.cpp
1#include "condition_var.hpp"
2
3#include "libxr_def.hpp"
4#include "libxr_system.hpp"
5#include "timebase.hpp"
6#include "timer.hpp"
7
8using namespace LibXR;
9
10ConditionVar::ConditionVar() : handle_(0) {}
11
13
14ErrorCode ConditionVar::Wait(uint32_t timeout) {
15 if (handle_) {
16 handle_ = 0;
17 return ErrorCode::OK;
18 } else if (timeout == 0) {
19 return ErrorCode::TIMEOUT;
20 }
21
23
24 while (Timebase::GetMilliseconds() - now < timeout) {
25 if (handle_) {
26 return ErrorCode::OK;
27 }
29 }
30
31 return ErrorCode::TIMEOUT;
32}
33
34void ConditionVar::Signal() { handle_ = 1; }
35
36void ConditionVar::Broadcast() { handle_ = 1; }
condition_var_handle handle_
底层条件变量句柄 / Underlying condition variable handle
ErrorCode Wait(uint32_t timeout)
等待条件变量 / Waits for the condition variable
void Broadcast()
广播信号唤醒所有等待线程 / Broadcasts a signal to wake up all waiting threads
~ConditionVar()
析构函数 / Destructor
ConditionVar()
默认构造函数 / Default constructor
void Signal()
发送信号唤醒一个等待线程 / Signals one waiting thread
static TimestampMS GetMilliseconds()
获取当前时间的毫秒级时间戳。 Gets the current timestamp in milliseconds.
Definition timebase.hpp:63
static void RefreshTimerInIdle()
在空闲时刷新定时器 Refreshes the timer during idle time
LibXR Color Control Library / LibXR终端颜色控制库
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值