VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
vlink::Semaphore类 参考final

In-process counting semaphore with optional acquire timeout. 更多...

#include <semaphore.h>

vlink::Semaphore 的协作图:

Public 成员函数

 Semaphore (size_t count=0) noexcept
 Constructs a Semaphore with an initial counter value.
 ~Semaphore () noexcept
 Destructor. Wakes all blocked acquirers before destruction.
bool acquire (size_t n=1, int timeout_ms=kInfinite) noexcept
 Decrements the semaphore counter by n, blocking until permits are available.
void release (size_t n=1) noexcept
 Increments the semaphore counter by n, waking blocked acquirers.
void reset (bool interrupt_waiters=false) noexcept
 Resets the semaphore counter to zero.
size_t get_count () const noexcept
 Returns the current value of the semaphore counter.

静态 Public 属性

static constexpr int kInfinite {-1}
 Sentinel value for acquire() meaning "wait indefinitely".

详细描述

In-process counting semaphore with optional acquire timeout.

The internal counter is initialised via the constructor and can be atomically decremented (acquire) or incremented (release).

构造及析构函数说明

◆ Semaphore()

vlink::Semaphore::Semaphore ( size_t count = 0)
explicitnoexcept

Constructs a Semaphore with an initial counter value.

参数
countInitial number of available permits (default: 0).
这是这个函数的调用关系图:

◆ ~Semaphore()

vlink::Semaphore::~Semaphore ( )
noexcept

Destructor. Wakes all blocked acquirers before destruction.

函数调用图:

成员函数说明

◆ acquire()

bool vlink::Semaphore::acquire ( size_t n = 1,
int timeout_ms = kInfinite )
noexcept

Decrements the semaphore counter by n, blocking until permits are available.

If the counter is less than n, the caller is blocked until enough release() calls bring the counter up. A timeout causes the function to return false without decrementing the counter.

参数
nNumber of permits to acquire (default: 1).
timeout_msMaximum time to wait in milliseconds. Use kInfinite (-1) to wait indefinitely (default).
返回
true if the permits were acquired, false on timeout or if the semaphore was reset with interrupt_waiters == true.
函数调用图:
这是这个函数的调用关系图:

◆ get_count()

size_t vlink::Semaphore::get_count ( ) const
nodiscardnoexcept

Returns the current value of the semaphore counter.

The returned value is a snapshot; it may change before the caller can use it. Intended for diagnostic and logging purposes only.

返回
Current counter value.
函数调用图:
这是这个函数的调用关系图:

◆ release()

void vlink::Semaphore::release ( size_t n = 1)
noexcept

Increments the semaphore counter by n, waking blocked acquirers.

If threads are blocked in acquire(), they are notified. The notification is delivered to at most n waiting threads.

参数
nNumber of permits to release (default: 1).
函数调用图:
这是这个函数的调用关系图:

◆ reset()

void vlink::Semaphore::reset ( bool interrupt_waiters = false)
noexcept

Resets the semaphore counter to zero.

If interrupt_waiters is true, all threads blocked in acquire() are woken and their calls return false. Use this during shutdown to unblock consumers cleanly.

参数
interrupt_waitersIf true, wake all blocked acquirers (default: false).
函数调用图:
这是这个函数的调用关系图:

类成员变量说明

◆ kInfinite

int vlink::Semaphore::kInfinite {-1}
staticconstexpr

Sentinel value for acquire() meaning "wait indefinitely".


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