1#ifndef NEFORCE_CORE_ASYNC_MUTEX_HPP__
2#define NEFORCE_CORE_ASYNC_MUTEX_HPP__
12#ifdef NEFORCE_PLATFORM_WINDOWS
22#ifdef NEFORCE_PLATFORM_LINUX
25NEFORCE_BEGIN_NAMESPACE__
49#ifdef NEFORCE_PLATFORM_WINDOWS
121#ifdef NEFORCE_PLATFORM_WINDOWS
188template <typename Mutex>
216 lock& operator=(
const lock&) =
delete;
226struct defer_lock_tag {
227 constexpr defer_lock_tag()
noexcept =
default;
241 constexpr try_lock_tag()
noexcept =
default;
255template <
typename Mutex>
262 bool owns_lock_ =
false;
303 owns_lock_(m.try_lock()) {}
315 mutex_(other.mutex_),
316 owns_lock_(other.owns_lock_) {
317 other.mutex_ =
nullptr;
318 other.owns_lock_ =
false;
335 mutex_ = other.mutex_;
336 owns_lock_ = other.owns_lock_;
337 other.mutex_ =
nullptr;
338 other.owns_lock_ =
false;
357 NEFORCE_NODISCARD
explicit operator bool() const noexcept {
return owns_lock_; }
363 NEFORCE_NODISCARD
bool owns_lock() const noexcept {
return owns_lock_; }
377 if (mutex_ ==
nullptr) {
393 if (mutex_ ==
nullptr) {
410 if (mutex_ ==
nullptr) {
416 owns_lock_ = mutex_->try_lock();
438NEFORCE_END_NAMESPACE__
bool try_lock() noexcept
尝试锁定互斥锁
const native_handle_type * native_handle() const noexcept
获取常量原生句柄
::SRWLOCK native_handle_type
互斥锁的系统句柄类型
native_handle_type * native_handle() noexcept
获取原生句柄
bool try_lock() noexcept
尝试锁定递归互斥锁
::CRITICAL_SECTION native_handle_type
递归互斥锁的系统句柄类型
const native_handle_type * native_handle() const noexcept
获取常量原生句柄
native_handle_type * native_handle() noexcept
获取原生句柄
bool try_lock() noexcept
尝试锁定互斥锁
unique_lock(mutex_type &m, try_lock_tag tag) noexcept
尝试锁定构造函数
unique_lock(mutex_type &m)
从互斥锁构造
mutex_type * release() noexcept
释放所有权
bool owns_lock() const noexcept
检查是否拥有锁
unique_lock(mutex_type &m, defer_lock_tag tag) noexcept
延迟锁定构造函数
unique_lock()=default
默认构造函数
unique_lock & operator=(unique_lock &&other) noexcept
移动赋值运算符
unique_lock(unique_lock &&other) noexcept
移动构造函数
mutex_type * mutex() const noexcept
获取管理的互斥锁指针
constexpr T * addressof(T &x) noexcept
获取对象的地址
constexpr defer_lock_tag defer_lock
延迟锁定标签实例
constexpr try_lock_tag try_lock
尝试锁定标签实例