#include <USemaphore.h>
Public Member Functions | |
bool | acquire (int n=1, int ms=0) |
int | acquireTry (int n) |
void | release (int n=1) |
USemaphore (int initValue=0) | |
int | value () |
virtual | ~USemaphore () |
Private Member Functions | |
void | operator= (const USemaphore &S) |
USemaphore (const USemaphore &S) | |
Private Attributes | |
int | _available |
pthread_cond_t | _cond |
pthread_mutex_t | _waitMutex |
A semaphore class.
On an acquire() call, the calling thread is blocked if the USemaphore's value is <= 0. It is unblocked when release() is called. The function acquire() decreases by 1 (default) the semaphore's value and release() increases it by 1 (default).
Example:
USemaphore s; s.acquire(); // Will wait until s.release() is called by another thread.
Definition at line 54 of file USemaphore.h.
USemaphore::USemaphore | ( | int | initValue = 0 | ) | [inline] |
The constructor. The semaphore waits on acquire() when its value is <= 0.
n | number to initialize |
Definition at line 61 of file USemaphore.h.
virtual USemaphore::~USemaphore | ( | ) | [inline, virtual] |
Definition at line 72 of file USemaphore.h.
USemaphore::USemaphore | ( | const USemaphore & | S | ) | [inline, private] |
Definition at line 212 of file USemaphore.h.
bool USemaphore::acquire | ( | int | n = 1 , |
int | ms = 0 |
||
) | [inline] |
Acquire the semaphore. If semaphore's value is <=0, the calling thread will wait until the count acquired is released.
n | number to acquire |
t | time to wait (ms), a value <=0 means infinite |
Definition at line 101 of file USemaphore.h.
int USemaphore::acquireTry | ( | int | n | ) | [inline] |
Definition at line 140 of file USemaphore.h.
void USemaphore::operator= | ( | const USemaphore & | S | ) | [inline, private] |
Definition at line 207 of file USemaphore.h.
void USemaphore::release | ( | int | n = 1 | ) | [inline] |
Release the semaphore, increasing its value by 1 and signaling waiting threads (which called acquire()).
Definition at line 164 of file USemaphore.h.
int USemaphore::value | ( | ) | [inline] |
Get the USempahore's value.
Definition at line 183 of file USemaphore.h.
int USemaphore::_available [private] |
Definition at line 215 of file USemaphore.h.
pthread_cond_t USemaphore::_cond [private] |
Definition at line 214 of file USemaphore.h.
pthread_mutex_t USemaphore::_waitMutex [private] |
Definition at line 213 of file USemaphore.h.