|
SimpleKernel 1.17.0
|
互斥锁(Mutex) More...
#include <mutex.hpp>

Public Member Functions | |
| auto | Lock () -> Expected< void > |
| 获取锁(阻塞) | |
| auto | UnLock () -> Expected< void > |
| 释放锁 | |
| auto | TryLock () -> Expected< void > |
| 尝试获取锁(非阻塞) | |
| auto | IsLockedByCurrentTask () const -> bool |
| 检查锁是否被当前线程持有 | |
构造/析构函数 | |
| Mutex (const char *_name) | |
| Mutex ()=default | |
| Mutex (const Mutex &)=delete | |
| Mutex (Mutex &&)=delete | |
| auto | operator= (const Mutex &) -> Mutex &=delete |
| auto | operator= (Mutex &&) -> Mutex &=delete |
| ~Mutex ()=default | |
Public Attributes | |
| const char * | name {"unnamed_mutex"} |
| 锁的名称 | |
Protected Attributes | |
| std::atomic< bool > | locked_ {false} |
| 锁状态 | |
| std::atomic< Pid > | owner_ {std::numeric_limits<Pid>::max()} |
| 持有锁的任务 ID,max() 表示未被持有 | |
| ResourceId | resource_id_ {} |
| 资源 ID,用于任务阻塞队列 | |
互斥锁(Mutex)
实现基于任务调度的互斥锁:
|
inlineexplicit |
|
default |
|
delete |
|
delete |
|
default |
| auto Mutex::IsLockedByCurrentTask | ( | ) | const -> bool |
检查锁是否被当前线程持有
Definition at line 99 of file mutex.cpp.
| auto Mutex::Lock | ( | ) | -> Expected<void> |
获取锁(阻塞)
如果锁已被其他线程持有,当前线程将被阻塞直到锁可用。 如果当前线程已持有锁,返回错误(不支持递归)。
Definition at line 11 of file mutex.cpp.


| auto Mutex::TryLock | ( | ) | -> Expected<void> |
尝试获取锁(非阻塞)
尝试获取锁,如果锁不可用则立即返回。
Definition at line 68 of file mutex.cpp.

| auto Mutex::UnLock | ( | ) | -> Expected<void> |
释放锁
释放锁并唤醒一个等待线程(如果有)。 只能由持有锁的线程调用。
Definition at line 41 of file mutex.cpp.


|
protected |
| const char* Mutex::name {"unnamed_mutex"} |
|
protected |