|
VLink 2.0.0
A high-performance communication middleware
|
In-process counting semaphore with optional acquire timeout. 更多...
#include <semaphore.h>
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).
|
explicitnoexcept |
Constructs a Semaphore with an initial counter value.
| count | Initial number of available permits (default: 0). |
|
noexcept |
Destructor. Wakes all blocked acquirers before destruction.
|
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.
| n | Number of permits to acquire (default: 1). |
| timeout_ms | Maximum 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.
|
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.
|
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.
| n | Number of permits to release (default: 1). |
|
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_waiters | If true, wake all blocked acquirers (default: false). |
|
staticconstexpr |
Sentinel value for acquire() meaning "wait indefinitely".