wakeup_signal.hpp
Go to the documentation of this file.
1 #ifndef BEHAVIORTREECORE_WAKEUP_SIGNAL_HPP
2 #define BEHAVIORTREECORE_WAKEUP_SIGNAL_HPP
3 
4 #include <chrono>
5 #include <mutex>
6 #include <condition_variable>
7 
8 namespace BT
9 {
10 
12 {
13 public:
15  bool waitFor(std::chrono::system_clock::duration tm)
16  {
17  std::unique_lock<std::mutex> lk(mutex_);
18  auto res = cv_.wait_for(lk, tm, [this]{
19  return ready_;
20  });
21  ready_ = false;
22  return res;
23  }
24 
25  void emitSignal()
26  {
27  {
28  std::lock_guard<std::mutex> lk(mutex_);
29  ready_ = true;
30  }
31  cv_.notify_all();
32  }
33 
34 private:
35 
37  std::condition_variable cv_;
38  bool ready_ = false;
39 };
40 
41 }
42 
43 #endif // BEHAVIORTREECORE_WAKEUP_SIGNAL_HPP
bool waitFor(std::chrono::system_clock::duration tm)
Return true if the.
static pthread_mutex_t mutex
Definition: minitrace.cpp:61
std::condition_variable cv_


behaviortree_cpp_v3
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Mon Jul 3 2023 02:50:14