#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:
bool acquire(int n=1, int ms=0)
- See also
- UMutex
Definition at line 55 of file USemaphore.h.
◆ USemaphore()
| USemaphore::USemaphore |
( |
int |
initValue = 0 | ) |
|
|
inline |
The constructor. The semaphore waits on acquire() when its value is <= 0.
- Parameters
-
Definition at line 62 of file USemaphore.h.
◆ ~USemaphore()
| virtual USemaphore::~USemaphore |
( |
| ) |
|
|
inlinevirtual |
◆ 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 108 of file USemaphore.h.
◆ acquireTry()
| int USemaphore::acquireTry |
( |
int |
n | ) |
|
|
inline |
◆ release()
| int USemaphore::release |
( |
int |
n = 1 | ) |
|
|
inline |
Release the semaphore, increasing its value by n and signaling waiting threads (which called acquire()).
- Parameters
-
- Returns
- 0 on success, ERANGE if the release would push the semaphore over SEM_VALUE_MAX (the count is then left unchanged). The Unix implementation cannot fail and always returns 0.
Definition at line 197 of file USemaphore.h.
◆ value()
| int USemaphore::value |
( |
| ) |
|
|
inline |
Get the USempahore's value.
- Returns
- the semaphore's value
Definition at line 221 of file USemaphore.h.
The documentation for this class was generated from the following file: