1#ifndef NEFORCE_CORE_ASYNC_SHARED_MUTEX_HPP__
2#define NEFORCE_CORE_ASYNC_SHARED_MUTEX_HPP__
12NEFORCE_BEGIN_NAMESPACE__
26class shared_mutex_base :
public mutex_base {};
42#ifdef NEFORCE_PLATFORM_WINDOWS
134template <typename SharedMutex>
137 "SharedMutex type must be derived from shared_mutex_base");
144 bool owns_lock_ =
false;
163 mutex_->lock_shared();
185 owns_lock_(m.try_lock_shared()) {}
197 mutex_(other.mutex_),
198 owns_lock_(other.owns_lock_) {
199 other.mutex_ =
nullptr;
200 other.owns_lock_ =
false;
215 mutex_->unlock_shared();
217 mutex_ = other.mutex_;
218 owns_lock_ = other.owns_lock_;
219 other.mutex_ =
nullptr;
220 other.owns_lock_ =
false;
231 mutex_->unlock_shared();
239 NEFORCE_NODISCARD
explicit operator bool() const noexcept {
return owns_lock_; }
245 NEFORCE_NODISCARD
bool owns_lock() const noexcept {
return owns_lock_; }
259 if (mutex_ ==
nullptr) {
265 mutex_->lock_shared();
275 if (mutex_ ==
nullptr) {
281 mutex_->unlock_shared();
292 if (mutex_ ==
nullptr) {
298 owns_lock_ = mutex_->try_lock_shared();
320NEFORCE_END_NAMESPACE__
shared_lock & operator=(shared_lock &&other) noexcept
移动赋值运算符
shared_lock(mutex_type &m, lock_defer_tag tag) noexcept
延迟锁定构造函数
shared_lock(mutex_type &m)
从共享互斥锁构造
mutex_type * release() noexcept
释放所有权
bool try_lock() noexcept
尝试获取读锁
shared_lock()=default
默认构造函数
SharedMutex mutex_type
共享互斥锁类型
shared_lock(shared_lock &&other) noexcept
移动构造函数
mutex_type * mutex() const noexcept
获取管理的共享互斥锁指针
bool owns_lock() const noexcept
检查是否拥有共享锁
shared_lock(mutex_type &m, lock_quiet_tag tag) noexcept
尝试锁定构造函数
bool try_lock_shared() noexcept
尝试获取读锁
bool try_lock() noexcept
尝试获取写锁
::SRWLOCK native_handle_type
共享互斥锁的系统句柄类型
const native_handle_type * native_handle() const noexcept
获取常量原生句柄
native_handle_type * native_handle() noexcept
获取原生句柄
constexpr T * addressof(T &x) noexcept
获取对象的地址
constexpr bool is_base_of_v
is_base_of的便捷变量模板