Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Euclid::Semaphore Class Reference

#include <Semaphore.h>

Collaboration diagram for Euclid::Semaphore:
Collaboration graph
[legend]

Public Member Functions

 Semaphore (unsigned int i)
 
 ~Semaphore ()
 
void release ()
 
void acquire ()
 
bool try_acquire ()
 
bool try_acquire_until (const std::chrono::system_clock::time_point &abs_time)
 
template<class Clock , class Duration >
bool try_acquire_until (const std::chrono::time_point< Clock, Duration > &abs_time)
 
template<class Rep , class Ratio >
bool try_acquire_for (const std::chrono::duration< Rep, Ratio > &rel_time)
 

Private Attributes

std::unique_ptr< SemaphoreImpl > m_impl
 

Detailed Description

Counting semaphore, based on the C++20 API, so it can be eventually swapped

Definition at line 31 of file Semaphore.h.

Constructor & Destructor Documentation

◆ Semaphore()

Euclid::Semaphore::Semaphore ( unsigned int  i)
explicit

Constructor

Parameters
iThe internal counter will be initialized to i

Definition at line 28 of file Semaphore.cpp.

◆ ~Semaphore()

Euclid::Semaphore::~Semaphore ( )
default

Destructor

Member Function Documentation

◆ acquire()

void Euclid::Semaphore::acquire ( )

Decrement the counter. Blocks if it was already 0 until some other thread calls release()

Definition at line 36 of file Semaphore.cpp.

References m_impl.

◆ release()

void Euclid::Semaphore::release ( )

Increment the counter. Does not block.

Definition at line 32 of file Semaphore.cpp.

References m_impl.

◆ try_acquire()

bool Euclid::Semaphore::try_acquire ( )

Try decrementing the counter.

Returns
false if the counter can not be decremented (already at 0)

Definition at line 40 of file Semaphore.cpp.

References m_impl.

◆ try_acquire_for()

template<class Rep , class Ratio >
bool Euclid::Semaphore::try_acquire_for ( const std::chrono::duration< Rep, Ratio > &  rel_time)
inline

Try decrementing the counter with a relative timeout

Template Parameters
Rep
Ratio
Parameters
rel_timeIf the counter can not be decremented, the call will block for this duration.
Returns
false if the counter can not be decremented within the time window

Definition at line 94 of file Semaphore.h.

References std::chrono::system_clock::now(), and try_acquire_until().

Here is the call graph for this function:

◆ try_acquire_until() [1/2]

bool Euclid::Semaphore::try_acquire_until ( const std::chrono::system_clock::time_point &  abs_time)

Try decrementing the counter with an absolute timeout

Parameters
abs_timeIf the counter can not be decremented, the call will block until this time point is reached. If it was in the past, it will return immediately.
Returns
false if the counter can not be decremented within the time window

Definition at line 44 of file Semaphore.cpp.

References m_impl.

Referenced by try_acquire_for(), and try_acquire_until().

◆ try_acquire_until() [2/2]

template<class Clock , class Duration >
bool Euclid::Semaphore::try_acquire_until ( const std::chrono::time_point< Clock, Duration > &  abs_time)
inline

Template Parameters
Clock
Duration
Parameters
abs_time
Returns
false if the counter can not be decremented within the time window

Definition at line 80 of file Semaphore.h.

References std::chrono::system_clock::now(), and try_acquire_until().

Here is the call graph for this function:

Member Data Documentation

◆ m_impl

std::unique_ptr<SemaphoreImpl> Euclid::Semaphore::m_impl
private

Definition at line 100 of file Semaphore.h.

Referenced by acquire(), release(), try_acquire(), and try_acquire_until().


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