![]() |
PIP 5.6.1
Platform-Independent Primitives
|
Counting semaphore that tracks available resource units. More...
#include <pisemaphore.h>
Public Member Functions | |
| PISemaphore | PISemaphore (int initial=0) |
| Constructs semaphore with "initial" available resources. | |
| ~PISemaphore () | |
| Destroy semaphore. | |
| void | acquire (int cnt=1) |
| Acquires cnt resource units, waiting until enough units become available. | |
| bool | tryAcquire (int cnt=1) |
| Tries to acquire cnt resource units without waiting. | |
| bool | tryAcquire (int cnt, PISystemTime timeout) |
| Tries to acquire cnt resource units within timeout. | |
| void | release (int cnt=1) |
| Releases cnt resource units and wakes waiting threads. | |
| int | available () const |
| Returns the current number of available resource units. | |
Counting semaphore that tracks available resource units.
Basic semaphore.
PISemaphore provides critical code section defence between several threads with resource counting. Semaphore contains logic counter and functions to change it: release(), acquire() and tryAcquire().
For automatic acquire-release use PISemaphoreLocker.