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
5extern uint64_t _libxr_webots_time_count; // NOLINT
6
7using namespace LibXR;
8
12}
13
17}
18
19ErrorCode ConditionVar::Wait(uint32_t timeout) {
20 uint32_t start_time = _libxr_webots_time_count;
21
22 struct timespec ts;
24
25 uint32_t add = 0;
27 static_cast<__syscall_slong_t>(1U * 1000U * 1000U) + ts.tv_nsec;
28 add = raw_time / (static_cast<int64_t>(1000U * 1000U * 1000U));
29
30 ts.tv_sec += add;
31 ts.tv_nsec = raw_time % (static_cast<int64_t>(1000U * 1000U * 1000U));
32
33 while (_libxr_webots_time_count - start_time < timeout) {
37 if (ans == 0) {
38 return ErrorCode::OK;
39 }
40 }
41
42 return ErrorCode::TIMEOUT;
43}
44
49}
50
55}
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
LibXR Color Control Library / LibXR终端颜色控制库
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值
pthread_mutex_t mutex
互斥锁 Mutex
pthread_cond_t cond
条件变量 Condition variable