shemaphore.hpp
Go to the documentation of this file.
1 #ifndef RAM_PATH_PLANNING_SEMAPHORE_HPP
2 #define RAM_PATH_PLANNING_SEMAPHORE_HPP
3 
4 #include <mutex>
5 
6 namespace ram_path_planning
7 {
8 class Semaphore
9 {
10 private:
11  unsigned int counter_;
12  std::mutex mutex_;
13  std::condition_variable condition_;
14 
15 public:
16  inline Semaphore(unsigned int counter) :
17  counter_(counter)
18  {
19  }
20 
21  inline void wait()
22  {
23  std::unique_lock<std::mutex> lock(mutex_);
24  condition_.wait(lock, [&]()->bool
25  { return counter_>0;});
26  --counter_;
27  }
28 
29  inline void signal()
30  {
31  std::unique_lock<std::mutex> lock(mutex_);
32  ++counter_;
33  condition_.notify_one();
34  }
35 };
36 
37 }
38 
39 #endif
std::condition_variable condition_
Definition: shemaphore.hpp:13
Semaphore(unsigned int counter)
Definition: shemaphore.hpp:16


ram_path_planning
Author(s): Andres Campos - Institut Maupertuis
autogenerated on Mon Jun 10 2019 14:50:03