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... | |
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). | |
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 10 of file mutex.cpp.
Mutex::~Mutex | ( | ) |
析构函数,销毁互斥锁 (Destructor to destroy the mutex).
Definition at line 12 of file mutex.cpp.
ErrorCode Mutex::Lock | ( | ) |
|
nodiscard |
尝试加锁,如果锁已被占用,则立即返回失败 (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 21 of file mutex.cpp.
void Mutex::Unlock | ( | ) |
解锁互斥锁 (Unlock the mutex).
Definition at line 28 of file mutex.cpp.
|
private |