Dev Essential
Loading...
Searching...
No Matches
a_util::concurrency::detail::basic_semaphore< Mutex, CondVar > Class Template Reference

#include <semaphore_decl.h>

Public Member Functions

 basic_semaphore (int count=0)
 
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 ()
 
template<typename Rep, typename Period>
bool wait_for (const std::chrono::duration< Rep, Period > &timeout)
 
void reset ()
 Reset the counter to 0.
 
bool is_set ()
 

Protected Attributes

Mutex _mutex
 The mutex to handle.
 
CondVar _cv
 The condition variable used to handle the notifications.
 
int _lock_count
 The lock count.
 

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

Constructor & Destructor Documentation

◆ basic_semaphore()

template<typename Mutex, typename CondVar>
a_util::concurrency::detail::basic_semaphore< Mutex, CondVar >::basic_semaphore ( int count = 0)
inlineexplicit

CTOR

Parameters
[in]countInitial value of the counter

Member Function Documentation

◆ is_set()

template<typename Mutex, typename CondVar>
bool a_util::concurrency::detail::basic_semaphore< Mutex, CondVar >::is_set ( )
inline

Check whether the counter is set.

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

◆ try_wait()

template<typename Mutex, typename CondVar>
bool a_util::concurrency::detail::basic_semaphore< Mutex, CondVar >::try_wait ( )
inline

Try decrementing the counter

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

◆ wait_for()

template<typename Mutex, typename CondVar>
template<typename Rep, typename Period>
bool a_util::concurrency::detail::basic_semaphore< Mutex, CondVar >::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

The documentation for this class was generated from the following files: