semaphore.h
Go to the documentation of this file.
1 
23 #ifndef MY_SEMAPHORE_H_
24 #define MY_SEMAPHORE_H_
25 
26 #include <iostream>
27 #include <boost/thread.hpp>
28 
29 namespace micros_swarm{
30  class Semaphore{
31  public:
32  Semaphore(int value): value_(value){}
33  Semaphore(const Semaphore&) = delete;
34 
35  void P()
36  {
37  boost::unique_lock<boost::mutex> lock(mutex_);
38  while(value_ == 0) {
39  condition_.wait(lock);
40  }
41 
42  value_--;
43  }
44 
45  void V()
46  {
47  boost::unique_lock<boost::mutex> lock(mutex_);
48  value_++;
49 
51  }
52  private:
53  int value_;
54  boost::mutex mutex_;
56  };
57 };
58 
59 #endif
void wait(unique_lock< mutex > &m)
boost::mutex mutex_
Definition: semaphore.h:54
Semaphore(int value)
Definition: semaphore.h:32
void notify_one() BOOST_NOEXCEPT
boost::condition_variable condition_
Definition: semaphore.h:55


micros_swarm
Author(s):
autogenerated on Mon Jun 10 2019 14:02:06