libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
mutex.hpp
1#pragma once
2
3#include "libxr_def.hpp"
4#include "libxr_system.hpp"
5
6namespace LibXR
7{
8
17class Mutex
18{
19 public:
24 Mutex();
25
30 ~Mutex();
31
38 ErrorCode Lock();
39
48 [[nodiscard]] ErrorCode TryLock();
49
54 void Unlock();
55
65 {
66 public:
72 LockGuard(Mutex &mutex) : mutex_(mutex) { mutex_.Lock(); }
73
79
80 private:
82 };
83
84 private:
85 libxr_mutex_handle mutex_handle_;
86};
87
88} // namespace LibXR
互斥锁的 RAII 机制封装 (RAII-style mechanism for automatic mutex management).
Definition mutex.hpp:65
Mutex & mutex_
被管理的互斥锁 (Reference to the managed mutex).
Definition mutex.hpp:81
LockGuard(Mutex &mutex)
构造函数,自动加锁 (Constructor automatically locking the mutex).
Definition mutex.hpp:72
~LockGuard()
析构函数,自动解锁 (Destructor automatically unlocking the mutex).
Definition mutex.hpp:78
互斥锁类,提供线程同步机制 (Mutex class providing thread synchronization mechanisms).
Definition mutex.hpp:18
libxr_mutex_handle mutex_handle_
互斥锁句柄 (Handle for the mutex).
Definition mutex.hpp:85
Mutex()
构造函数,初始化互斥锁 (Constructor to initialize the mutex).
Definition mutex.cpp:10
ErrorCode Lock()
加锁,如果锁已被占用,则阻塞等待 (Lock the mutex, blocking if it is already locked).
Definition mutex.cpp:14
ErrorCode TryLock()
尝试加锁,如果锁已被占用,则立即返回失败 (Attempt to lock the mutex, returning immediately if already locked).
Definition mutex.cpp:21
~Mutex()
析构函数,销毁互斥锁 (Destructor to destroy the mutex).
Definition mutex.cpp:12
void Unlock()
解锁互斥锁 (Unlock the mutex).
Definition mutex.cpp:28
LibXR 命名空间
Definition ch32_gpio.hpp:9