Thrill
0.1
|
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... | |
Semaphore & | operator= (const Semaphore &)=delete |
non-copyable: delete assignment operator More... | |
Semaphore & | operator= (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... | |
|
inlineexplicit |
move-constructor: just move the value
Definition at line 38 of file semaphore.hpp.
non-copyable: delete assignment operator
Referenced by Semaphore::Semaphore().
move-assignment: just move the value
Definition at line 40 of file semaphore.hpp.
References Semaphore::value_.
|
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().
|
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_.
|
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_.
|
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().
|
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().
|
private |
condition variable
Definition at line 89 of file semaphore.hpp.
Referenced by Semaphore::signal(), and Semaphore::wait().
|
private |
mutex for condition variable
Definition at line 86 of file semaphore.hpp.
Referenced by Semaphore::signal(), Semaphore::try_acquire(), and Semaphore::wait().
|
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().