ADTF  3.18.2
basic_semaphore< Mutex, CondVar >

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_semaphoreoperator= (const basic_semaphore &)
 

Detailed Description

template<typename Mutex, typename CondVar>
class a_util::concurrency::detail::basic_semaphore< Mutex, CondVar >

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.

Template Parameters
MutexThe mutex type
CondVarThe condition variable type

Definition at line 31 of file semaphore_decl.h.

Constructor & Destructor Documentation

◆ basic_semaphore()

basic_semaphore ( int  count = 0)
inlineexplicit

CTOR.

Parameters
[in]countInitial value of the counter

Definition at line 34 of file semaphore_impl.h.

Member Function Documentation

◆ is_set()

bool is_set
inline

Check whether the counter is set.

Returns
true if the counter is greater than zero, false otherwise.

Definition at line 78 of file semaphore_impl.h.

◆ try_wait()

bool try_wait
inline

Try decrementing the counter.

Returns
true if the counter is greater than zero, false otherwise

Definition at line 59 of file semaphore_impl.h.

◆ wait_for()

bool wait_for ( const std::chrono::duration< Rep, Period > &  timeout)
inline

Wait for a specified duration of time and decrement the counter afterwards.

Template Parameters
RepAn arithmetic type representing the number of ticks
std::ratiorepresenting the tick period (i.e. the number of seconds per tick)
Parameters
[in]timeoutThe duration to wait.
Exceptions
std::invalid_argumentIf timeout.count < 0
Returns
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().