MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
shared_lock< SharedMutex > 模板类 参考

共享锁类模板 更多...

#include <shared_mutex.hpp>

Public 类型

using mutex_type = SharedMutex
 共享互斥锁类型

Public 成员函数

 shared_lock ()=default
 默认构造函数
 shared_lock (mutex_type &m)
 从共享互斥锁构造
 shared_lock (mutex_type &m, defer_lock_tag tag) noexcept
 延迟锁定构造函数
 shared_lock (mutex_type &m, try_lock_tag tag) noexcept
 尝试锁定构造函数
 shared_lock (shared_lock &&other) noexcept
 移动构造函数
shared_lockoperator= (shared_lock &&other) noexcept
 移动赋值运算符
 ~shared_lock ()
 析构函数
MSTL_NODISCARD operator bool () const noexcept
 转换为布尔值
MSTL_NODISCARD bool owns_lock () const noexcept
 检查是否拥有共享锁
MSTL_NODISCARD mutex_typemutex () const noexcept
 获取管理的共享互斥锁指针
void lock ()
 获取读锁
void unlock ()
 释放读锁
bool try_lock () noexcept
 尝试获取读锁
mutex_typerelease () noexcept
 释放所有权

详细描述

template<typename SharedMutex>
class shared_lock< SharedMutex >

共享锁类模板

模板参数
SharedMutex共享互斥锁类型

RAII共享锁管理器,专门用于管理共享互斥锁的读锁。

在文件 shared_mutex.hpp127 行定义.

构造及析构函数说明

◆ shared_lock() [1/5]

template<typename SharedMutex>
shared_lock< SharedMutex >::shared_lock ( )
default

默认构造函数

创建不管理任何共享互斥锁的共享锁。

被这些函数引用 operator=() , 以及 shared_lock().

◆ shared_lock() [2/5]

template<typename SharedMutex>
shared_lock< SharedMutex >::shared_lock ( mutex_type & m)
inlineexplicit

从共享互斥锁构造

参数
m要管理的共享互斥锁引用

构造时立即获取共享互斥锁的读锁。

在文件 shared_mutex.hpp149 行定义.

◆ shared_lock() [3/5]

template<typename SharedMutex>
shared_lock< SharedMutex >::shared_lock ( mutex_type & m,
defer_lock_tag tag )
inlinenoexcept

延迟锁定构造函数

参数
m要管理的共享互斥锁引用
tag延迟锁定标签

构造时不锁定共享互斥锁,稍后可以手动获取读锁。

在文件 shared_mutex.hpp161 行定义.

◆ shared_lock() [4/5]

template<typename SharedMutex>
shared_lock< SharedMutex >::shared_lock ( mutex_type & m,
try_lock_tag tag )
inlinenoexcept

尝试锁定构造函数

参数
m要管理的共享互斥锁引用
tag尝试锁定标签

构造时尝试获取共享互斥锁的读锁,如果失败不会阻塞。

在文件 shared_mutex.hpp171 行定义.

◆ shared_lock() [5/5]

template<typename SharedMutex>
shared_lock< SharedMutex >::shared_lock ( shared_lock< SharedMutex > && other)
inlinenoexcept

移动构造函数

参数
other要移动的共享锁

转移共享互斥锁的所有权和锁定状态。

在文件 shared_mutex.hpp183 行定义.

引用了 shared_lock().

◆ ~shared_lock()

template<typename SharedMutex>
shared_lock< SharedMutex >::~shared_lock ( )
inline

析构函数

如果拥有共享锁的所有权,则释放读锁。

在文件 shared_mutex.hpp211 行定义.

成员函数说明

◆ lock()

template<typename SharedMutex>
void shared_lock< SharedMutex >::lock ( )
inline

获取读锁

如果已拥有锁或未管理共享互斥锁,则不执行任何操作。

在文件 shared_mutex.hpp238 行定义.

◆ mutex()

template<typename SharedMutex>
MSTL_NODISCARD mutex_type * shared_lock< SharedMutex >::mutex ( ) const
inlinenoexcept

获取管理的共享互斥锁指针

返回
指向管理的共享互斥锁的指针,如果没有管理则返回nullptr

在文件 shared_mutex.hpp231 行定义.

◆ operator bool()

template<typename SharedMutex>
MSTL_NODISCARD shared_lock< SharedMutex >::operator bool ( ) const
inlineexplicitnoexcept

转换为布尔值

返回
是否拥有共享锁的所有权

在文件 shared_mutex.hpp219 行定义.

◆ operator=()

template<typename SharedMutex>
shared_lock & shared_lock< SharedMutex >::operator= ( shared_lock< SharedMutex > && other)
inlinenoexcept

移动赋值运算符

参数
other要移动的共享锁
返回
当前对象的引用

释放当前锁,然后转移所有权。

在文件 shared_mutex.hpp196 行定义.

引用了 _MSTL, addressof() , 以及 shared_lock().

◆ owns_lock()

template<typename SharedMutex>
MSTL_NODISCARD bool shared_lock< SharedMutex >::owns_lock ( ) const
inlinenoexcept

检查是否拥有共享锁

返回
是否拥有共享锁的所有权

在文件 shared_mutex.hpp225 行定义.

◆ release()

template<typename SharedMutex>
mutex_type * shared_lock< SharedMutex >::release ( )
inlinenoexcept

释放所有权

返回
之前管理的共享互斥锁指针

放弃对共享互斥锁的管理权,返回互斥锁指针但不释放锁。

在文件 shared_mutex.hpp276 行定义.

◆ try_lock()

template<typename SharedMutex>
bool shared_lock< SharedMutex >::try_lock ( )
inlinenoexcept

尝试获取读锁

返回
如果成功获得读锁则返回true,否则返回false

非阻塞地尝试获取共享互斥锁的读锁。

在文件 shared_mutex.hpp263 行定义.

◆ unlock()

template<typename SharedMutex>
void shared_lock< SharedMutex >::unlock ( )
inline

释放读锁

如果未拥有锁或未管理共享互斥锁,则不执行任何操作。

在文件 shared_mutex.hpp250 行定义.


该类的文档由以下文件生成: