#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() [1/2]
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.
◆ ~USemaphore()
virtual USemaphore::~USemaphore |
( |
| ) |
|
|
inlinevirtual |
◆ USemaphore() [2/2]
◆ acquire()
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.
◆ acquireTry()
int USemaphore::acquireTry |
( |
int |
n | ) |
|
|
inline |
◆ operator=()
◆ release()
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.
◆ value()
int USemaphore::value |
( |
| ) |
|
|
inline |
Get the USempahore's value.
- Returns
- the semaphore's value
Definition at line 187 of file USemaphore.h.
◆ _available
int USemaphore::_available |
|
private |
◆ _cond
pthread_cond_t USemaphore::_cond |
|
private |
◆ _waitMutex
pthread_mutex_t USemaphore::_waitMutex |
|
private |
The documentation for this class was generated from the following file: