Thrill  0.1
Semaphore Class Reference

Detailed Description

A simple semaphore implementation using C++11 synchronization methods.

Definition at line 26 of file semaphore.hpp.

#include <semaphore.hpp>

Public Member Functions

 Semaphore (size_t initial_value=0)
 construct semaphore More...
 
 Semaphore (const Semaphore &)=delete
 non-copyable: delete copy-constructor More...
 
 Semaphore (Semaphore &&s)
 move-constructor: just move the value More...
 
Semaphoreoperator= (const Semaphore &)=delete
 non-copyable: delete assignment operator More...
 
Semaphoreoperator= (Semaphore &&s)
 move-assignment: just move the value More...
 
size_t signal ()
 
size_t signal (size_t delta)
 
bool try_acquire (size_t delta=1, size_t slack=0)
 
size_t value () const
 return the current value – should only be used for debugging. More...
 
size_t wait (size_t delta=1, size_t slack=0)
 

Private Attributes

std::condition_variable cv_
 condition variable More...
 
std::mutex mutex_
 mutex for condition variable More...
 
size_t value_
 value of the semaphore More...
 

Constructor & Destructor Documentation

◆ Semaphore() [1/3]

Semaphore ( size_t  initial_value = 0)
inlineexplicit

construct semaphore

Definition at line 30 of file semaphore.hpp.

References Semaphore::operator=().

◆ Semaphore() [2/3]

Semaphore ( const Semaphore )
delete

non-copyable: delete copy-constructor

◆ Semaphore() [3/3]

Semaphore ( Semaphore &&  s)
inline

move-constructor: just move the value

Definition at line 38 of file semaphore.hpp.

Member Function Documentation

◆ operator=() [1/2]

Semaphore& operator= ( const Semaphore )
delete

non-copyable: delete assignment operator

Referenced by Semaphore::Semaphore().

◆ operator=() [2/2]

Semaphore& operator= ( Semaphore &&  s)
inline

move-assignment: just move the value

Definition at line 40 of file semaphore.hpp.

References Semaphore::value_.

◆ signal() [1/2]

size_t signal ( )
inline

function increments the semaphore and signals any threads that are blocked waiting a change in the semaphore

Definition at line 44 of file semaphore.hpp.

References Semaphore::cv_, Semaphore::mutex_, and Semaphore::value_.

Referenced by request_queue_impl_1q::add_request(), request_queue_impl_qwqr::add_request(), MixStreamData::OnStreamBlockOrdered(), CatStreamData::OnStreamBlockOrdered(), and request_queue_impl_worker::stop_thread().

◆ signal() [2/2]

size_t signal ( size_t  delta)
inline

function increments the semaphore and signals any threads that are blocked waiting a change in the semaphore

Definition at line 52 of file semaphore.hpp.

References Semaphore::cv_, examples::select::delta, Semaphore::mutex_, and Semaphore::value_.

◆ try_acquire()

bool try_acquire ( size_t  delta = 1,
size_t  slack = 0 
)
inline

function decrements the semaphore by delta if (delta + slack) tokens are available as a batch. the function will not block and returns true if delta was acquired otherwise false.

Definition at line 70 of file semaphore.hpp.

References examples::select::delta, Semaphore::mutex_, and Semaphore::value_.

◆ value()

size_t value ( ) const
inline

return the current value – should only be used for debugging.

Definition at line 79 of file semaphore.hpp.

References Semaphore::value_.

Referenced by MixStreamData::Close().

◆ wait()

size_t wait ( size_t  delta = 1,
size_t  slack = 0 
)
inline

function decrements the semaphore by delta and blocks if the semaphore is < (delta + slack) until another thread signals a change

Definition at line 60 of file semaphore.hpp.

References Semaphore::cv_, examples::select::delta, Semaphore::mutex_, and Semaphore::value_.

Referenced by request_queue_impl_1q::cancel_request(), request_queue_impl_qwqr::cancel_request(), MixStreamData::Close(), CatStreamData::Close(), request_queue_impl_1q::worker(), and request_queue_impl_qwqr::worker().

Member Data Documentation

◆ cv_

std::condition_variable cv_
private

condition variable

Definition at line 89 of file semaphore.hpp.

Referenced by Semaphore::signal(), and Semaphore::wait().

◆ mutex_

std::mutex mutex_
private

mutex for condition variable

Definition at line 86 of file semaphore.hpp.

Referenced by Semaphore::signal(), Semaphore::try_acquire(), and Semaphore::wait().

◆ value_

size_t value_
private

value of the semaphore

Definition at line 83 of file semaphore.hpp.

Referenced by Semaphore::operator=(), Semaphore::signal(), Semaphore::try_acquire(), Semaphore::value(), and Semaphore::wait().


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