libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
semaphore.cpp
1#include "semaphore.hpp"
2
3#include "libxr.hpp"
4#include "libxr_def.hpp"
5#include "timer.hpp"
6
7using namespace LibXR;
8
10
12
14
15ErrorCode Semaphore::Wait(uint32_t timeout) {
16 if (semaphore_handle_ > 0) {
18 return ErrorCode::OK;
19 } else if (timeout == 0) {
20 return ErrorCode::TIMEOUT;
21 }
22
24
25 while (Timebase::GetMilliseconds() - now < timeout) {
26 if (semaphore_handle_ > 0) {
28 return ErrorCode::OK;
29 }
31 }
32 return ErrorCode::TIMEOUT;
33}
34
36 UNUSED(in_isr);
37 Post();
38}
39
40size_t Semaphore::Value() { return semaphore_handle_; }
void Post()
释放(增加)信号量 Releases (increments) the semaphore
Definition semaphore.cpp:13
void PostFromCallback(bool in_isr)
从中断回调中释放(增加)信号量 Releases (increments) the semaphore from an ISR (Interrupt Service Routine)
Definition semaphore.cpp:23
~Semaphore()
析构信号量对象,释放资源 Destroys the semaphore object and releases resources
Definition semaphore.cpp:11
libxr_semaphore_handle semaphore_handle_
信号量句柄 Semaphore handle
Semaphore(uint32_t init_count=0)
构造一个信号量对象 Constructs a semaphore object
Definition semaphore.cpp:8
size_t Value()
获取当前信号量的值 Gets the current value of the semaphore
Definition semaphore.cpp:35
ErrorCode Wait(uint32_t timeout=UINT32_MAX)
等待(减少)信号量 Waits (decrements) the semaphore
Definition semaphore.cpp:15
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
计算两个数的最小值