tlx
|
A simple semaphore implementation using C++11 synchronization methods. More...
#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 & | operator= (const Semaphore &)=delete |
non-copyable: delete assignment operator More... | |
Semaphore (Semaphore &&s) | |
move-constructor: just move the value More... | |
Semaphore & | operator= (Semaphore &&s) |
move-assignment: just move the value More... | |
size_t | signal () |
function increments the semaphore and signals any threads that are blocked waiting a change in the semaphore More... | |
size_t | signal (size_t delta) |
function increments the semaphore and signals any threads that are blocked waiting a change in the semaphore More... | |
size_t | wait (size_t delta=1, size_t slack=0) |
function decrements the semaphore by delta and blocks if the semaphore is < (delta + slack) until another thread signals a change More... | |
bool | try_acquire (size_t delta=1, size_t slack=0) |
function decrements the semaphore by delta if (delta + slack) tokens are available as a batch. More... | |
size_t | value () const |
return the current value – should only be used for debugging. More... | |
Private Attributes | |
size_t | value_ |
value of the semaphore More... | |
std::mutex | mutex_ |
mutex for condition variable More... | |
std::condition_variable | cv_ |
condition variable More... | |
A simple semaphore implementation using C++11 synchronization methods.
Definition at line 26 of file semaphore.hpp.
|
inlineexplicit |
construct semaphore
Definition at line 30 of file semaphore.hpp.
move-constructor: just move the value
Definition at line 38 of file semaphore.hpp.
move-assignment: just move the value
Definition at line 40 of file semaphore.hpp.
|
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.
|
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.
|
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.
|
inline |
return the current value – should only be used for debugging.
Definition at line 79 of file semaphore.hpp.
|
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.
|
private |
condition variable
Definition at line 89 of file semaphore.hpp.
|
private |
mutex for condition variable
Definition at line 86 of file semaphore.hpp.
|
private |
value of the semaphore
Definition at line 83 of file semaphore.hpp.