1#ifndef NEFORCE_CORE_ASYNC_SHARED_MUTEX_HPP__
2#define NEFORCE_CORE_ASYNC_SHARED_MUTEX_HPP__
12NEFORCE_BEGIN_NAMESPACE__
39#ifdef NEFORCE_PLATFORM_WINDOWS
131template <typename SharedMutex>
138 bool owns_lock_ =
false;
157 mutex_->lock_shared();
179 owns_lock_(m.try_lock_shared()) {}
191 mutex_(other.mutex_),
192 owns_lock_(other.owns_lock_) {
193 other.mutex_ =
nullptr;
194 other.owns_lock_ =
false;
209 mutex_->unlock_shared();
211 mutex_ = other.mutex_;
212 owns_lock_ = other.owns_lock_;
213 other.mutex_ =
nullptr;
214 other.owns_lock_ =
false;
225 mutex_->unlock_shared();
233 NEFORCE_NODISCARD
explicit operator bool() const noexcept {
return owns_lock_; }
239 NEFORCE_NODISCARD
bool owns_lock() const noexcept {
return owns_lock_; }
259 mutex_->lock_shared();
275 mutex_->unlock_shared();
292 owns_lock_ = mutex_->try_lock_shared();
314NEFORCE_END_NAMESPACE__
SharedMutex mutex_type
共享互斥锁类型
shared_lock(shared_lock &&other) noexcept
移动构造函数
shared_lock & operator=(shared_lock &&other) noexcept
移动赋值运算符
mutex_type * release() noexcept
释放所有权
shared_lock(mutex_type &m, defer_lock_tag tag) noexcept
延迟锁定构造函数
shared_lock()=default
默认构造函数
bool try_lock() noexcept
尝试获取读锁
NEFORCE_NODISCARD bool owns_lock() const noexcept
检查是否拥有共享锁
NEFORCE_NODISCARD mutex_type * mutex() const noexcept
获取管理的共享互斥锁指针
shared_lock(mutex_type &m)
从共享互斥锁构造
shared_lock(mutex_type &m, try_lock_tag tag) noexcept
尝试锁定构造函数
native_handle_type * native_handle() noexcept
获取原生句柄
const native_handle_type * native_handle() const noexcept
获取常量原生句柄
::pthread_rwlock_t native_handle_type
共享互斥锁的系统句柄类型
bool try_lock() noexcept
尝试获取写锁
bool try_lock_shared() noexcept
尝试获取读锁
NEFORCE_NODISCARD constexpr T * addressof(T &x) noexcept
获取对象的地址