#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 &) |
USemaphore (const USemaphore &) | |
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:
Definition at line 54 of file USemaphore.h.
|
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.
|
inlinevirtual |
Definition at line 72 of file USemaphore.h.
|
inlineprivate |
Definition at line 216 of file USemaphore.h.
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.
Definition at line 144 of file USemaphore.h.
|
inlineprivate |
Definition at line 211 of file USemaphore.h.
|
inline |
Release the semaphore, increasing its value by 1 and signaling waiting threads (which called acquire()).
Definition at line 168 of file USemaphore.h.
|
inline |
Get the USempahore's value.
Definition at line 187 of file USemaphore.h.
|
private |
Definition at line 219 of file USemaphore.h.
|
private |
Definition at line 218 of file USemaphore.h.
|
private |
Definition at line 217 of file USemaphore.h.