ORIGINAL
|
Counting semaphore with maximum count constraint. More...
#include <semaphores.h>
Public Member Functions | |
semaphore () | |
Constructs a semaphore with maximum count. | |
semaphore (u_integer init_count) | |
Constructs a semaphore with specified initial count. | |
void | acquire () |
Acquires one resource (decrements count) | |
bool | tryAcquire () |
Attempts to acquire one resource without blocking. | |
bool | acquireFor (time::duration timeout) |
Attempts to acquire one resource with timeout. | |
void | release (u_integer increase=1) |
Releases resources (increments count) | |
bool | tryRelease (u_integer increase=1) |
Attempts to release resources without blocking. | |
bool | releaseFor (u_integer increase, time::duration timeout) |
Attempts to release resources with timeout. | |
bool | releaseFor (const time::duration &timeout) |
Attempts to release one resource with timeout. | |
Counting semaphore with maximum count constraint.
Specialization for unbounded semaphore (no maximum count)
MAX_CNT | Maximum allowed semaphore count (default: 1, binary semaphore) |
A counting semaphore that controls access to a shared resource pool. The semaphore count represents the number of available resources. acquire() waits for an available resource, while release() returns a resource to the pool.
For MAX_CNT = 1, behaves as a binary semaphore/mutex. For MAX_CNT > 1, implements a counting semaphore for resource pools. For MAX_CNT = 0, see specialization below for unbounded semaphore.
A semaphore with no upper limit on the count. release() operations never block, as there's no constraint on the maximum semaphore value.
original::semaphore< MAX_CNT >::semaphore | ( | ) |
Constructs a semaphore with maximum count.
Initializes the semaphore with MAX_CNT available resources
|
explicit |
Constructs a semaphore with specified initial count.
init_count | Initial semaphore count |
valueError | if init_count exceeds MAX_CNT |
void original::semaphore< MAX_CNT >::acquire | ( | ) |
Acquires one resource (decrements count)
Blocks the calling thread until a resource becomes available (count > 0). Decrements the semaphore count by 1 upon successful acquisition.
bool original::semaphore< MAX_CNT >::acquireFor | ( | time::duration | timeout | ) |
Attempts to acquire one resource with timeout.
timeout | Maximum duration to wait for resource availability |
void original::semaphore< MAX_CNT >::release | ( | u_integer | increase = 1 | ) |
Releases resources (increments count)
increase | Number of resources to release (default: 1) |
valueError | if increase would exceed MAX_CNT |
Blocks if releasing would exceed MAX_CNT, waiting until space becomes available. Notifies waiting threads after successful release.
bool original::semaphore< MAX_CNT >::releaseFor | ( | const time::duration & | timeout | ) |
Attempts to release one resource with timeout.
timeout | Maximum duration to wait for release condition |
bool original::semaphore< MAX_CNT >::releaseFor | ( | u_integer | increase, |
time::duration | timeout | ||
) |
Attempts to release resources with timeout.
increase | Number of resources to release |
timeout | Maximum duration to wait for release condition |
bool original::semaphore< MAX_CNT >::tryAcquire | ( | ) |
Attempts to acquire one resource without blocking.
bool original::semaphore< MAX_CNT >::tryRelease | ( | u_integer | increase = 1 | ) |
Attempts to release resources without blocking.
increase | Number of resources to release (default: 1) |