1#ifndef MSTL_CORE_ASYNC_MUTEX_HPP__
2#define MSTL_CORE_ASYNC_MUTEX_HPP__
12#ifdef MSTL_PLATFORM_WINDOWS__
21#ifdef MSTL_PLATFORM_LINUX__
42#ifdef MSTL_PLATFORM_WINDOWS__
112#ifdef MSTL_PLATFORM_WINDOWS__
180template <typename Mutex,
bool WithDefer = false>
209 lock& operator =(
const lock&) =
delete;
219struct defer_lock_tag {
220 constexpr defer_lock_tag()
noexcept =
default;
234 constexpr try_lock_tag()
noexcept =
default;
249template <
typename Mutex>
256 bool owns_lock_ =
false;
273 : mutex_(&m), owns_lock_(true) {
295 : mutex_(&m), owns_lock_(m.try_lock()) {}
298 lock& operator =(
const lock&) =
delete;
307 : mutex_(other.mutex_), owns_lock_(other.owns_lock_) {
308 other.mutex_ =
nullptr;
309 other.owns_lock_ =
false;
321 if (owns_lock_) mutex_->unlock();
322 mutex_ = other.mutex_;
323 owns_lock_ = other.owns_lock_;
324 other.mutex_ =
nullptr;
325 other.owns_lock_ =
false;
335 if (owns_lock_) mutex_->unlock();
342 MSTL_NODISCARD
explicit operator bool() const noexcept {
369 if (owns_lock_)
return;
381 if (!owns_lock_)
return;
393 if (!mutex_)
return false;
394 if (owns_lock_)
return true;
395 owns_lock_ = mutex_->try_lock();
417template <
typename Mutex>
lock(mutex_type &m, try_lock_tag tag) noexcept
尝试锁定构造函数
bool try_lock() noexcept
尝试锁定互斥锁
lock(lock &&other) noexcept
移动构造函数
lock(mutex_type &m)
从互斥锁构造
lock(mutex_type &m, defer_lock_tag tag) noexcept
延迟锁定构造函数
mutex_type * release() noexcept
释放所有权
MSTL_NODISCARD mutex_type * mutex() const noexcept
获取管理的互斥锁指针
MSTL_NODISCARD bool owns_lock() const noexcept
检查是否拥有锁
bool try_lock() noexcept
尝试锁定互斥锁
::pthread_mutex_t native_handle_type
互斥锁的系统句柄类型
const native_handle_type * native_handle() const noexcept
获取常量原生句柄
native_handle_type * native_handle() noexcept
获取原生句柄
bool try_lock() noexcept
尝试锁定递归互斥锁
::pthread_mutex_t native_handle_type
递归互斥锁的系统句柄类型
const native_handle_type * native_handle() const noexcept
获取常量原生句柄
native_handle_type * native_handle() noexcept
获取原生句柄
MSTL_NODISCARD constexpr T * addressof(T &x) noexcept
获取对象的地址
MSTL_INLINE17 constexpr try_lock_tag try_lock
尝试锁定标签实例
lock< Mutex, true > smart_lock
智能锁管理器的便捷类型别名
MSTL_INLINE17 constexpr defer_lock_tag defer_lock
延迟锁定标签实例
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL