librf
Public 成员函数 | 静态 Public 成员函数 | 所有成员列表
resumef::mutex_t结构体 参考

支持递归的锁。 更多...

Public 成员函数

awaiter lock () const noexcept
 在协程中加锁,如果不能立即获得锁,则阻塞当前协程。但不会阻塞当前线程。 更多...
 
awaiter operator co_await () const noexcept
 在协程中加锁。 更多...
 
manual_awaiter lock (adopt_manual_unlock_t manual_unlock_tag) const noexcept
 在协程中加锁,如果不能立即获得锁,则阻塞当前协程。但不会阻塞当前线程。 更多...
 
try_awaiter try_lock () const noexcept
 尝试在协程中加锁。此操作无论成功与否都会立即返回,不会有协程切换。 更多...
 
unlock_awaiter unlock () const noexcept
 在协程中解锁。此操作立即返回,不会有协程切换。 更多...
 
template<class _Rep , class _Period >
timeout_awaiter try_lock_for (const std::chrono::duration< _Rep, _Period > &dt) const noexcept
 在协程中尝试加锁,直到超时。如果不能立即获得锁,则阻塞当前协程。但不会阻塞当前线程。 更多...
 
template<class _Rep , class _Period >
timeout_awaiter try_lock_until (const std::chrono::time_point< _Rep, _Period > &tp) const noexcept
 在协程中尝试加锁,直到超时。如果不能立即获得锁,则阻塞当前协程。但不会阻塞当前线程。 更多...
 
void lock (void *unique_address) const
 在非协程中加锁。如果不能立即获得锁,则反复尝试,直到获得锁。故会阻塞当前协程 更多...
 
bool try_lock (void *unique_address) const
 尝试在非协程中加锁。此操作无论成功与否都会立即返回。 更多...
 
template<class _Rep , class _Period >
bool try_lock_for (const std::chrono::duration< _Rep, _Period > &dt, void *unique_address)
 尝试在非协程中加锁,直到超时。如果不能立即获得锁,则反复尝试,直到获得锁或超时。故会阻塞当前协程 更多...
 
template<class _Rep , class _Period >
bool try_lock_until (const std::chrono::time_point< _Rep, _Period > &tp, void *unique_address)
 尝试在非协程中加锁,直到超时。如果不能立即获得锁,则反复尝试,直到获得锁或超时。故会阻塞当前协程 更多...
 
void unlock (void *unique_address) const
 在非协程中解锁。立即返回。由于立即返回,也可在协程中如此使用:mtx.unlock(root_state()) 更多...
 
 mutex_t (std::adopt_lock_t) noexcept
 构造一个无效的mutex_t。
 

静态 Public 成员函数

template<class... _Mtxs>
static future_t< batch_unlock_t< _Mtxs... > > lock (_Mtxs &... mtxs)
 在协程中,无死锁的批量加锁。不会阻塞当前线程。直到获得所有锁之前,会阻塞当前协程。 更多...
 
template<class... _Mtxs>
static future_t lock (adopt_manual_unlock_t manual_unlock_tag, _Mtxs &... mtxs)
 在协程中,无死锁的批量加锁。不会阻塞当前线程。直到获得所有锁之前,会阻塞当前协程。 更多...
 
template<class... _Mtxs>
static future_t unlock (_Mtxs &... mtxs)
 在协程中批量解锁。如果可能,使用unlock(root_state(), mtxs...)来替代。 更多...
 
template<class... _Mtxs>
static batch_unlock_t< _Mtxs... > lock (void *unique_address, _Mtxs &... mtxs)
 在非协程中,无死锁的批量加锁。会阻塞当前线程,直到获得所有锁为止。 更多...
 
template<class... _Mtxs>
static void lock (adopt_manual_unlock_t manual_unlock_tag, void *unique_address, _Mtxs &... mtxs)
 在非协程中,无死锁的批量加锁。会阻塞当前线程,直到获得所有锁为止。 更多...
 
template<class... _Mtxs>
static void unlock (void *unique_address, _Mtxs &... mtxs)
 在非协程中批量解锁。立即返回。由于立即返回,也可在协程中如此使用:unlock(root_state(), mtxs...) 更多...
 

详细描述

支持递归的锁。

锁被本协程所在的跟协程所拥有。支持在跟协程下的所有协程里递归加锁。

成员函数说明

◆ lock() [1/7]

awaiter resumef::mutex_t::lock ( ) const
noexcept

在协程中加锁,如果不能立即获得锁,则阻塞当前协程。但不会阻塞当前线程。

返回
[co_await] batch_unlock_t

◆ lock() [2/7]

template<class... _Mtxs>
static future_t<batch_unlock_t<_Mtxs...> > resumef::mutex_t::lock ( _Mtxs &...  mtxs)
static

在协程中,无死锁的批量加锁。不会阻塞当前线程。直到获得所有锁之前,会阻塞当前协程。

参数
mtxs...需要获得的锁列表。
返回
[co_await] batch_unlock_t

◆ lock() [3/7]

manual_awaiter resumef::mutex_t::lock ( adopt_manual_unlock_t  manual_unlock_tag) const
noexcept

在协程中加锁,如果不能立即获得锁,则阻塞当前协程。但不会阻塞当前线程。

需要随后调用unlock()函数解锁。lock()/unlock()调用必须在同一个跟协程下配对调用。

参数
manual_unlock_tag提示手工解锁
返回
[co_await] void

◆ lock() [4/7]

template<class... _Mtxs>
static future_t resumef::mutex_t::lock ( adopt_manual_unlock_t  manual_unlock_tag,
_Mtxs &...  mtxs 
)
static

在协程中,无死锁的批量加锁。不会阻塞当前线程。直到获得所有锁之前,会阻塞当前协程。

参数
manual_unlock_tag提示手工解锁
mtxs...需要获得的锁列表。
返回
[co_await] void

◆ lock() [5/7]

template<class... _Mtxs>
static void resumef::mutex_t::lock ( adopt_manual_unlock_t  manual_unlock_tag,
void *  unique_address,
_Mtxs &...  mtxs 
)
static

在非协程中,无死锁的批量加锁。会阻塞当前线程,直到获得所有锁为止。

参数
manual_unlock_tag提示手工解锁
unique_address代表获得锁的拥有者。
mtxs...需要获得的锁列表。

◆ lock() [6/7]

void resumef::mutex_t::lock ( void *  unique_address) const

在非协程中加锁。如果不能立即获得锁,则反复尝试,直到获得锁。故会阻塞当前协程

参数
unique_address代表获得锁的拥有者。此地址应当与随后的unlock()的地址一致。
一般做法,是申明一个跟当前线程关联的局部变量,以此局部变量的地址为参数。

◆ lock() [7/7]

template<class... _Mtxs>
static batch_unlock_t<_Mtxs...> resumef::mutex_t::lock ( void *  unique_address,
_Mtxs &...  mtxs 
)
static

在非协程中,无死锁的批量加锁。会阻塞当前线程,直到获得所有锁为止。

参数
unique_address代表获得锁的拥有者。
mtxs...需要获得的锁列表。
返回
batch_unlock_t

◆ operator co_await()

awaiter resumef::mutex_t::operator co_await ( ) const
noexcept

在协程中加锁。

参见
等同调用 co_await lock()
返回
[co_await] batch_unlock_t

◆ try_lock() [1/2]

try_awaiter resumef::mutex_t::try_lock ( ) const
noexcept

尝试在协程中加锁。此操作无论成功与否都会立即返回,不会有协程切换。

如果加锁成功,则需要调用co_await unlock()解锁。或者使用unlock(root_state())解锁。
如果加锁失败,且要循环尝试加锁,则最好调用co_await yield()让出一次调度。否则,可能造成本调度器死循环。

返回
[co_await] bool

◆ try_lock() [2/2]

bool resumef::mutex_t::try_lock ( void *  unique_address) const

尝试在非协程中加锁。此操作无论成功与否都会立即返回。

参数
unique_address代表获得锁的拥有者。

◆ try_lock_for() [1/2]

template<class _Rep , class _Period >
timeout_awaiter resumef::mutex_t::try_lock_for ( const std::chrono::duration< _Rep, _Period > &  dt) const
noexcept

在协程中尝试加锁,直到超时。如果不能立即获得锁,则阻塞当前协程。但不会阻塞当前线程。

参数
dt超时时长
返回
[co_await] bool

◆ try_lock_for() [2/2]

template<class _Rep , class _Period >
bool resumef::mutex_t::try_lock_for ( const std::chrono::duration< _Rep, _Period > &  dt,
void *  unique_address 
)

尝试在非协程中加锁,直到超时。如果不能立即获得锁,则反复尝试,直到获得锁或超时。故会阻塞当前协程

参数
dt超时时长
unique_address代表获得锁的拥有者。

◆ try_lock_until() [1/2]

template<class _Rep , class _Period >
timeout_awaiter resumef::mutex_t::try_lock_until ( const std::chrono::time_point< _Rep, _Period > &  tp) const
noexcept

在协程中尝试加锁,直到超时。如果不能立即获得锁,则阻塞当前协程。但不会阻塞当前线程。

参数
tp超时时刻
返回
[co_await] bool

◆ try_lock_until() [2/2]

template<class _Rep , class _Period >
bool resumef::mutex_t::try_lock_until ( const std::chrono::time_point< _Rep, _Period > &  tp,
void *  unique_address 
)

尝试在非协程中加锁,直到超时。如果不能立即获得锁,则反复尝试,直到获得锁或超时。故会阻塞当前协程

参数
tp超时时刻
unique_address代表获得锁的拥有者。

◆ unlock() [1/4]

unlock_awaiter resumef::mutex_t::unlock ( ) const
noexcept

在协程中解锁。此操作立即返回,不会有协程切换。

返回
[co_await] void

◆ unlock() [2/4]

template<class... _Mtxs>
static future_t resumef::mutex_t::unlock ( _Mtxs &...  mtxs)
static

在协程中批量解锁。如果可能,使用unlock(root_state(), mtxs...)来替代。

参数
mtxs...需要解锁的锁列表。
返回
[co_await] void

◆ unlock() [3/4]

void resumef::mutex_t::unlock ( void *  unique_address) const

在非协程中解锁。立即返回。由于立即返回,也可在协程中如此使用:mtx.unlock(root_state())

参数
unique_address代表获得锁的拥有者。

◆ unlock() [4/4]

template<class... _Mtxs>
static void resumef::mutex_t::unlock ( void *  unique_address,
_Mtxs &...  mtxs 
)
static

在非协程中批量解锁。立即返回。由于立即返回,也可在协程中如此使用:unlock(root_state(), mtxs...)

参数
unique_address代表获得锁的拥有者。
mtxs...需要解锁的锁列表。

该结构体的文档由以下文件生成: