17 #ifndef TLX_SEMAPHORE_HEADER 18 #define TLX_SEMAPHORE_HEADER 20 #include <condition_variable> 31 :
value_(initial_value) { }
45 std::unique_lock<std::mutex> lock(
mutex_);
53 std::unique_lock<std::mutex> lock(
mutex_);
61 std::unique_lock<std::mutex> lock(
mutex_);
71 std::unique_lock<std::mutex> lock(
mutex_);
89 std::condition_variable
cv_;
97 #endif // !TLX_SEMAPHORE_HEADER size_t value() const
return the current value – should only be used for debugging.
A simple semaphore implementation using C++11 synchronization methods.
size_t value_
value of the semaphore
static constexpr double delta
std::condition_variable cv_
condition variable
Semaphore(Semaphore &&s)
move-constructor: just move the value
bool try_acquire(size_t delta=1, size_t slack=0)
size_t wait(size_t delta=1, size_t slack=0)
std::mutex mutex_
mutex for condition variable
Semaphore & operator=(const Semaphore &)=delete
non-copyable: delete assignment operator
Semaphore(size_t initial_value=0)
construct semaphore
size_t signal(size_t delta)