ADTF
3.18.2
|
Semaphore implementation, combining a mutex and a condition variable to manage a counter. More...
Public Member Functions | |
basic_semaphore (int count=0) | |
CTOR. More... | |
void | notify () |
Increment the counter and notify any waiters. | |
void | wait () |
Decrement the counter, blocks until the count becomes non-zero (if neccessary) | |
bool | try_wait () |
Try decrementing the counter. More... | |
template<typename Rep , typename Period > | |
bool | wait_for (const std::chrono::duration< Rep, Period > &timeout) |
Wait for a specified duration of time and decrement the counter afterwards. More... | |
void | reset () |
Reset the counter to 0. | |
bool | is_set () |
Check whether the counter is set. More... | |
Protected Attributes | |
Mutex | _mutex |
The mutex to handle. | |
CondVar | _cv |
The condition variable used to handle the notifications. | |
int | _lock_count |
The lock count. | |
Private Member Functions | |
basic_semaphore (const basic_semaphore &) | |
basic_semaphore & | operator= (const basic_semaphore &) |
Semaphore implementation, combining a mutex and a condition variable to manage a counter.
For the default semaphore type to use, check a_util::concurrency::semaphore.
Mutex | The mutex type |
CondVar | The condition variable type |
Definition at line 31 of file semaphore_decl.h.
|
inlineexplicit |
CTOR.
[in] | count | Initial value of the counter |
Definition at line 34 of file semaphore_impl.h.
|
inline |
Check whether the counter is set.
true
if the counter is greater than zero, false
otherwise. Definition at line 78 of file semaphore_impl.h.
|
inline |
Try decrementing the counter.
true
if the counter is greater than zero, false
otherwise Definition at line 59 of file semaphore_impl.h.
|
inline |
Wait for a specified duration of time and decrement the counter afterwards.
Rep | An arithmetic type representing the number of ticks |
std::ratio | representing the tick period (i.e. the number of seconds per tick) |
[in] | timeout | The duration to wait. |
std::invalid_argument | If timeout.count < 0 |
true
if the counter could be decreased after the waiting time, false
otherwise Definition at line 86 of file semaphore_impl.h.
References a_util::system::getCurrentMicroseconds().