libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
mutex.cpp
1#include "mutex.hpp"
2
3#include "libxr_system.hpp"
4#include "thread.hpp"
5#include "timer.hpp"
6
7using namespace LibXR;
8
9Mutex::Mutex() : mutex_handle_(1) {}
10
12
13ErrorCode Mutex::Lock() {
14 while (mutex_handle_ < 1) {
16 }
17 mutex_handle_ = 0;
18 return ErrorCode::OK;
19}
20
21ErrorCode Mutex::TryLock() {
22 if (mutex_handle_ == 0) {
23 return ErrorCode::BUSY;
24 }
25 mutex_handle_ = 0;
26 return ErrorCode::OK;
27}
28
29void Mutex::Unlock() { mutex_handle_ = 1; }
30
31ErrorCode Mutex::TryLockInCallback(bool in_isr) {
32 UNUSED(in_isr);
33 return TryLock();
34}
35
37 UNUSED(in_isr);
38 Unlock();
39}
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
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
计算两个数的最小值