libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::Mutex::LockGuard Class Reference

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

#include <mutex.hpp>

Collaboration diagram for LibXR::Mutex::LockGuard:

Public Member Functions

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

Private Attributes

Mutexmutex_
 被管理的互斥锁 (Reference to the managed 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 94 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 102 of file mutex.hpp.

102: mutex_(mutex) { mutex_.Lock(); }
Mutex & mutex_
被管理的互斥锁 (Reference to the managed mutex).
Definition mutex.hpp:111
ErrorCode Lock()
加锁,如果锁已被占用,则阻塞等待 (Lock the mutex, blocking if it is already locked).
Definition mutex.cpp:13

◆ ~LockGuard()

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

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

Definition at line 108 of file mutex.hpp.

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

Field Documentation

◆ mutex_

Mutex& LibXR::Mutex::LockGuard::mutex_
private

被管理的互斥锁 (Reference to the managed mutex).

Definition at line 111 of file mutex.hpp.


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