libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
mutex.cpp
1#include "mutex.hpp"
2
3#include <pthread.h>
4
5#include "libxr_system.hpp"
6
7using namespace LibXR;
8
9Mutex::Mutex() : mutex_handle_(xSemaphoreCreateBinary()) { Unlock(); }
10
12
13ErrorCode Mutex::Lock() {
15 return ErrorCode::BUSY;
16 }
17 return ErrorCode::OK;
18}
19
20ErrorCode Mutex::TryLock() {
22 return ErrorCode::BUSY;
23 }
24 return ErrorCode::OK;
25}
26
28
30 if (in_isr) {
34
35 if (ans == pdPASS) {
37 portYIELD(); // NOLINT
38 }
39
40 return ErrorCode::OK;
41 } else {
42 return ErrorCode::BUSY;
43 }
44 } else {
45 return TryLock();
46 }
47}
48
ErrorCode TryLockInCallback(bool in_isr)
在回调(ISR)中尝试加锁 (Attempt to lock the mutex inside an interrupt service routine (ISR)).
Definition mutex.cpp:29
libxr_mutex_handle mutex_handle_
互斥锁句柄 (Handle for the mutex).
Definition mutex.hpp:164
Mutex()
构造函数,初始化互斥锁 (Constructor to initialize the mutex).
Definition mutex.cpp:9
ErrorCode Lock()
加锁,如果锁已被占用,则阻塞等待 (Lock the mutex, blocking if it is already locked).
Definition mutex.cpp:13
ErrorCode TryLock()
尝试加锁,如果锁已被占用,则立即返回失败 (Attempt to lock the mutex, returning immediately if already locked).
Definition mutex.cpp:20
~Mutex()
析构函数,销毁互斥锁 (Destructor to destroy the mutex).
Definition mutex.cpp:11
void UnlockFromCallback(bool in_isr)
在回调(ISR)中解锁 (Unlock the mutex inside an interrupt service routine (ISR)).
Definition mutex.cpp:49
void Unlock()
解锁互斥锁 (Unlock the mutex).
Definition mutex.cpp:27
LibXR Color Control Library / LibXR终端颜色控制库
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值