ADTF  3.18.3
semaphore_decl.h
Go to the documentation of this file.
1 
15 #ifndef A_UTIL_UTIL_CONCURRENCY_DETAIL_SEMAPHORE_DECL_HEADER_INCLUDED
16 #define A_UTIL_UTIL_CONCURRENCY_DETAIL_SEMAPHORE_DECL_HEADER_INCLUDED
17 
18 #include <chrono>
19 
20 namespace a_util {
21 namespace concurrency {
22 namespace detail {
30 template <typename Mutex, typename CondVar>
32  basic_semaphore(const basic_semaphore&); // = delete;
33  basic_semaphore& operator=(const basic_semaphore&); // = delete;
34 
35 public:
40  explicit basic_semaphore(int count = 0);
41 
43  void notify();
44 
46  void wait();
47 
52  bool try_wait();
53 
62  template <typename Rep, typename Period>
63  bool wait_for(const std::chrono::duration<Rep, Period>& timeout);
64 
66  void reset();
67 
72  bool is_set();
73 
74 protected:
75  Mutex _mutex;
76  CondVar _cv;
78 };
79 
80 } // namespace detail
81 } // namespace concurrency
82 } // namespace a_util
83 
88 #endif // A_UTIL_UTIL_CONCURRENCY_DETAIL_SEMAPHORE_DECL_HEADER_INCLUDED
Semaphore implementation, combining a mutex and a condition variable to manage a counter.
void notify()
Increment the counter and notify any waiters.
bool is_set()
Check whether the counter is set.
void wait()
Decrement the counter, blocks until the count becomes non-zero (if neccessary)
void reset()
Reset the counter to 0.
CondVar _cv
The condition variable used to handle the notifications.
bool try_wait()
Try decrementing the counter.
bool wait_for(const std::chrono::duration< Rep, Period > &timeout)
Wait for a specified duration of time and decrement the counter afterwards.
Serves as the root component, with common functionality documented in core functionality.
Definition: base.h:24
Semapore implementation file.