libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::Mutex::LockGuard Class Reference

互斥锁的 RAII 机制封装 RAII-style mechanism for automatic mutex management. More...

#include <mutex.hpp>

Public Member Functions

 LockGuard (Mutex &mutex)
 构造函数,自动加锁 Constructor automatically locking the mutex.
 
 ~LockGuard ()
 析构函数,自动解锁 Destructor automatically unlocking the mutex.
 

Detailed Description

互斥锁的 RAII 机制封装 RAII-style mechanism for automatic mutex management.

该类确保在构造时自动加锁,并在析构时自动释放锁。 This class ensures that a mutex is locked upon construction and automatically released upon destruction.

Definition at line 64 of file mutex.hpp.

Constructor & Destructor Documentation

◆ LockGuard()

LibXR::Mutex::LockGuard::LockGuard ( Mutex & mutex)
inline

构造函数,自动加锁 Constructor automatically locking the mutex.

Parameters
mutex需要管理的互斥锁 / Reference to the mutex to manage.

Definition at line 72 of file mutex.hpp.

72: mutex_(mutex) { mutex_.Lock(); }
ErrorCode Lock()
加锁,如果锁已被占用,则阻塞等待 Lock the mutex, blocking if it is already locked.
Definition mutex.cpp:16

◆ ~LockGuard()

LibXR::Mutex::LockGuard::~LockGuard ( )
inline

析构函数,自动解锁 Destructor automatically unlocking the mutex.

Definition at line 78 of file mutex.hpp.

78{ mutex_.Unlock(); }
void Unlock()
解锁互斥锁 Unlock the mutex.
Definition mutex.cpp:40

The documentation for this class was generated from the following file: