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

计数信号量类模板 更多...

#include <semaphore.hpp>

Public 成员函数

 counting_semaphore (const platform_wait_t desired) noexcept
 构造函数
 ~counting_semaphore ()=default
 析构函数
void release (const platform_wait_t update=1) noexcept
 释放信号量
void acquire () noexcept
 获取信号量
bool try_acquire () noexcept
 尝试获取信号量
template<typename Rep, typename Period>
bool try_acquire_for (const duration< Rep, Period > &relative) noexcept
 在指定时间内尝试获取信号量
template<typename Clock, typename Dur>
bool try_acquire_until (const time_point< Clock, Dur > &timeout) noexcept
 在指定时间点前尝试获取信号量

静态 Public 成员函数

static constexpr platform_wait_t max () noexcept
 获取信号量的最大可能值

详细描述

template<platform_wait_t LeastMaxValue = numeric_traits<platform_wait_t>::max()>
class counting_semaphore< LeastMaxValue >

计数信号量类模板

模板参数
LeastMaxValue信号量的最小最大值

计数信号量是一个轻量级的同步原语,用于控制对共享资源的访问。

LeastMaxValue指定了信号量计数器的最小最大值,实际值可以小于此值。 这个模板参数主要用于静态检查,确保信号量的合理使用。

在文件 semaphore.hpp31 行定义.

构造及析构函数说明

◆ counting_semaphore()

template<platform_wait_t LeastMaxValue = numeric_traits<platform_wait_t>::max()>
counting_semaphore< LeastMaxValue >::counting_semaphore ( const platform_wait_t desired)
inlineexplicitnoexcept

构造函数

参数
desired信号量的初始计数值

创建计数信号量并设置初始计数值。

在文件 semaphore.hpp60 行定义.

成员函数说明

◆ acquire()

template<platform_wait_t LeastMaxValue = numeric_traits<platform_wait_t>::max()>
void counting_semaphore< LeastMaxValue >::acquire ( )
inlinenoexcept

获取信号量

阻塞当前线程,直到成功获取信号量。

在文件 semaphore.hpp96 行定义.

◆ max()

template<platform_wait_t LeastMaxValue = numeric_traits<platform_wait_t>::max()>
constexpr platform_wait_t counting_semaphore< LeastMaxValue >::max ( )
inlinestaticconstexprnoexcept

获取信号量的最大可能值

返回
信号量的最大计数值

在文件 semaphore.hpp74 行定义.

◆ release()

template<platform_wait_t LeastMaxValue = numeric_traits<platform_wait_t>::max()>
void counting_semaphore< LeastMaxValue >::release ( const platform_wait_t update = 1)
inlinenoexcept

释放信号量

参数
update释放的数量,默认为1

增加信号量的计数值,并通知等待的线程。

在文件 semaphore.hpp84 行定义.

◆ try_acquire()

template<platform_wait_t LeastMaxValue = numeric_traits<platform_wait_t>::max()>
bool counting_semaphore< LeastMaxValue >::try_acquire ( )
inlinenoexcept

尝试获取信号量

返回
是否成功获取

非阻塞地尝试获取信号量。

在文件 semaphore.hpp109 行定义.

◆ try_acquire_for()

template<platform_wait_t LeastMaxValue = numeric_traits<platform_wait_t>::max()>
template<typename Rep, typename Period>
bool counting_semaphore< LeastMaxValue >::try_acquire_for ( const duration< Rep, Period > & relative)
inlinenoexcept

在指定时间内尝试获取信号量

模板参数
Rep时间表示类型
Period时间单位比例
参数
relative相对超时时间
返回
是否在超时前成功获取

阻塞当前线程,直到成功获取信号量或超时。

在文件 semaphore.hpp126 行定义.

◆ try_acquire_until()

template<platform_wait_t LeastMaxValue = numeric_traits<platform_wait_t>::max()>
template<typename Clock, typename Dur>
bool counting_semaphore< LeastMaxValue >::try_acquire_until ( const time_point< Clock, Dur > & timeout)
inlinenoexcept

在指定时间点前尝试获取信号量

模板参数
Clock时钟类型
Dur持续时间类型
参数
timeout绝对超时时间点
返回
是否在超时前成功获取

阻塞当前线程,直到成功获取信号量或到达指定时间点。

在文件 semaphore.hpp143 行定义.


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