libxr 1.0
Want to be the best embedded framework
|
互斥锁类,提供线程同步机制 (Mutex class providing thread synchronization mechanisms). More...
#include <mutex.hpp>
Data Structures | |
class | LockGuard |
互斥锁的 RAII 机制封装 (RAII-style mechanism for automatic mutex management). More... | |
class | LockGuardInCallback |
回调(ISR)上下文中的互斥锁管理类 (Lock management class for ISR context). More... | |
Public Member Functions | |
Mutex () | |
构造函数,初始化互斥锁 (Constructor to initialize the mutex). | |
~Mutex () | |
析构函数,销毁互斥锁 (Destructor to destroy the mutex). | |
ErrorCode | Lock () |
加锁,如果锁已被占用,则阻塞等待 (Lock the mutex, blocking if it is already locked). | |
ErrorCode | TryLock () |
尝试加锁,如果锁已被占用,则立即返回失败 (Attempt to lock the mutex, returning immediately if already locked). | |
void | Unlock () |
解锁互斥锁 (Unlock the mutex). | |
ErrorCode | TryLockInCallback (bool in_isr) |
在回调(ISR)中尝试加锁 (Attempt to lock the mutex inside an interrupt service routine (ISR)). | |
void | UnlockFromCallback (bool in_isr) |
在回调(ISR)中解锁 (Unlock the mutex inside an interrupt service routine (ISR)). | |
Private Attributes | |
libxr_mutex_handle | mutex_handle_ |
互斥锁句柄 (Handle for the mutex). | |
互斥锁类,提供线程同步机制 (Mutex class providing thread synchronization mechanisms).
This class implements a mutex for thread-safe operations, supporting locking, unlocking, and special handling for interrupt service routines (ISR). 该类实现了一个互斥锁,用于确保多线程环境下的线程安全,支持加锁、解锁,并对中断服务程序(ISR)进行特殊处理。
Mutex::Mutex | ( | ) |
构造函数,初始化互斥锁 (Constructor to initialize the mutex).
Definition at line 9 of file mutex.cpp.
Mutex::~Mutex | ( | ) |
ErrorCode Mutex::Lock | ( | ) |
ErrorCode Mutex::TryLock | ( | ) |
尝试加锁,如果锁已被占用,则立即返回失败 (Attempt to lock the mutex, returning immediately if already locked).
ErrorCode::OK
表示成功 (ErrorCode::OK
on success).ErrorCode::BUSY
表示锁已被占用 (ErrorCode::BUSY
if the mutex is already locked). Definition at line 20 of file mutex.cpp.
ErrorCode Mutex::TryLockInCallback | ( | bool | in_isr | ) |
在回调(ISR)中尝试加锁 (Attempt to lock the mutex inside an interrupt service routine (ISR)).
in_isr | 指示当前是否处于中断上下文 (Indicates whether the function is called inside an ISR). |
ErrorCode::OK
表示成功 (ErrorCode::OK
on success).ErrorCode::BUSY
表示锁已被占用 (ErrorCode::BUSY
if the mutex is already locked). Definition at line 29 of file mutex.cpp.
|
private |