include
behaviortree_cpp
utils
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 <atomic>
7
#include <condition_variable>
8
9
namespace
BT
10
{
11
12
class
WakeUpSignal
13
{
14
public
:
17
bool
waitFor
(std::chrono::microseconds usec)
18
{
19
std::unique_lock<std::mutex> lk(
mutex_
);
20
auto
res =
cv_
.wait_for(lk, usec, [
this
] {
return
ready_
.load(); });
21
ready_
=
false
;
22
return
res;
23
}
24
25
void
emitSignal
()
26
{
27
ready_
=
true
;
28
cv_
.notify_all();
29
}
30
31
private
:
32
std::mutex
mutex_
;
33
std::condition_variable
cv_
;
34
std::atomic_bool
ready_
=
false
;
35
};
36
37
}
// namespace BT
38
39
#endif // BEHAVIORTREECORE_WAKEUP_SIGNAL_HPP
BT
Definition:
ex01_wrap_legacy.cpp:29
BT::WakeUpSignal::emitSignal
void emitSignal()
Definition:
wakeup_signal.hpp:25
BT::WakeUpSignal::cv_
std::condition_variable cv_
Definition:
wakeup_signal.hpp:33
mutex
static pthread_mutex_t mutex
Definition:
minitrace.cpp:77
BT::WakeUpSignal::ready_
std::atomic_bool ready_
Definition:
wakeup_signal.hpp:34
BT::WakeUpSignal
Definition:
wakeup_signal.hpp:12
BT::WakeUpSignal::mutex_
std::mutex mutex_
Definition:
wakeup_signal.hpp:32
BT::WakeUpSignal::waitFor
bool waitFor(std::chrono::microseconds usec)
Definition:
wakeup_signal.hpp:17
behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Dec 13 2024 03:19:17