PIP 5.5.3
Platform-Independent Primitives
Public Member Functions | List of all members
PISemaphore Class Reference

Basic semaphore. 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)
 Acquire "cnt" resources. If no available resources, than blocks until they freed.
 
bool tryAcquire (int cnt=1)
 Try to acquire "cnt" resources. Returns if operation was successfull.
 
bool tryAcquire (int cnt, PISystemTime timeout)
 Try to acquire "cnt" resources for "timeout". Returns if operation was successfull (timeout has not expired).
 
void release (int cnt=1)
 Release "cnt" resources.
 
int available () const
 Returns available resources count.
 

Detailed Description

Basic semaphore.

Synopsis

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.

Usage