CoreComponents 3.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
Semaphore< T > Class Template Referencefinal

Waiting for a limited resource. More...

#include <cc/Semaphore>

Public Member Functions

 Semaphore (T supply=0)
 Create a new semaphore with initial supply of the limited ressource.
 
void acquire (T amount=1)
 Acquire a certain amount of a limited resource.
 
void release (T amount=1)
 Release a certain amount of a limited resource.
 
acquireAll (T minAmount=1)
 Acquire all items of a limited resource.
 
releaseOnDemand (T maxAmount=std::numeric_limits< T >::max())
 Release items of a limited resource on demand.
 
bool tryAcquire (T amount=1)
 Try to acquire a certain amount of a limited resource.
 
bool acquireBefore (double time, T amount=1)
 Try to acquire a certain amount of a limited resource for a limited time.
 
currentSupply () const
 Current supply of the limited resource.
 

Detailed Description

template<class T>
class cc::Semaphore< T >

Waiting for a limited resource.

See also
Guard
Template Parameters
TValue type

Constructor & Destructor Documentation

◆ Semaphore()

template<class T >
Semaphore ( T supply = 0)

Create a new semaphore with initial supply of the limited ressource.

Member Function Documentation

◆ acquire()

template<class T >
void acquire ( T amount = 1)

Acquire a certain amount of a limited resource.

◆ release()

template<class T >
void release ( T amount = 1)

Release a certain amount of a limited resource.

◆ acquireAll()

template<class T >
T acquireAll ( T minAmount = 1)

Acquire all items of a limited resource.

Parameters
minAmountMinimum number of items to acquire
Returns
Number of items acquired

◆ releaseOnDemand()

template<class T >
T releaseOnDemand ( T maxAmount = std::numeric_limits<T>::max())

Release items of a limited resource on demand.

Parameters
maxAmountMaximum number of items to release
Returns
Number of items released

◆ tryAcquire()

template<class T >
bool tryAcquire ( T amount = 1)

Try to acquire a certain amount of a limited resource.

Parameters
amountNumber of items to acquire
Returns
Number of items acquired

◆ acquireBefore()

template<class T >
bool acquireBefore ( double time,
T amount = 1 )

Try to acquire a certain amount of a limited resource for a limited time.

Parameters
timeSeconds elapsed since the begin of Epoch
amountNumber of items to acquire
See also
System::now()

◆ currentSupply()

template<class T >
T currentSupply ( ) const

Current supply of the limited resource.