15#ifndef A_UTIL_UTIL_CONCURRENCY_DETAIL_SEMAPHORE_IMPL_HEADER_INCLUDED
16#define A_UTIL_UTIL_CONCURRENCY_DETAIL_SEMAPHORE_IMPL_HEADER_INCLUDED
22#include <condition_variable>
33template <
typename Mutex,
typename CondVar>
34inline basic_semaphore<Mutex, CondVar>::basic_semaphore(
int count)
39template <
typename Mutex,
typename CondVar>
42 std::unique_lock<Mutex> lock(
_mutex);
47template <
typename Mutex,
typename CondVar>
50 std::unique_lock<Mutex> lock(
_mutex);
57template <
typename Mutex,
typename CondVar>
60 std::unique_lock<Mutex> lock(
_mutex);
71template <
typename Mutex,
typename CondVar>
74 std::unique_lock<Mutex> lock(
_mutex);
78template <
typename Mutex,
typename CondVar>
81 std::unique_lock<Mutex> lock(
_mutex);
85template <
typename Mutex,
typename CondVar>
86template <
typename Rep,
typename Period>
88 const std::chrono::duration<Rep, Period>& timeout)
90 if (timeout.count() < 0) {
91 throw std::invalid_argument(
"timeout.count() < 0");
94 std::unique_lock<Mutex> lock(
_mutex);
95 if (!
_cv.wait_for(lock, timeout, [&]() { return _lock_count > 0; })) {
void wait()
Decrement the counter, blocks until the count becomes non-zero (if neccessary)
Definition semaphore_impl.h:48
void notify()
Increment the counter and notify any waiters.
Definition semaphore_impl.h:40
bool is_set()
Definition semaphore_impl.h:79
Mutex _mutex
The mutex to handle.
Definition semaphore_decl.h:75
void reset()
Reset the counter to 0.
Definition semaphore_impl.h:72
bool try_wait()
Definition semaphore_impl.h:58
int _lock_count
The lock count.
Definition semaphore_decl.h:77
CondVar _cv
The condition variable used to handle the notifications.
Definition semaphore_decl.h:76
bool wait_for(const std::chrono::duration< Rep, Period > &timeout)
Definition semaphore_impl.h:87
Serves as namespace for concurrency implementation details.
Definition concurrency.h:33
Definition concurrency.h:24
Serves as the root component, with common functionality documented in core functionality.
Definition base.h:24