#include <USemaphore.h>
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:
- See also
- UMutex
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.
- Parameters
-
Definition at line 61 of file USemaphore.h.
virtual USemaphore::~USemaphore |
( |
| ) |
|
|
inlinevirtual |
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.
- See also
- release()
- Parameters
-
n | number to acquire |
t | time to wait (ms), a value <=0 means infinite |
- Returns
- true on success, false on error/timeout
Definition at line 101 of file USemaphore.h.
int USemaphore::acquireTry |
( |
int |
n | ) |
|
|
inline |
void USemaphore::operator= |
( |
const USemaphore & |
S | ) |
|
|
inlineprivate |
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 168 of file USemaphore.h.
int USemaphore::value |
( |
| ) |
|
|
inline |
Get the USempahore's value.
- Returns
- the semaphore's value
Definition at line 187 of file USemaphore.h.
int USemaphore::_available |
|
private |
pthread_cond_t USemaphore::_cond |
|
private |
pthread_mutex_t USemaphore::_waitMutex |
|
private |
The documentation for this class was generated from the following file: