File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed
include/behaviortree_cpp/decorators Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -27,18 +27,19 @@ class TimeoutNode : public DecoratorNode
27
27
28
28
TimeoutNode (const std::string& name, const NodeConfiguration& config);
29
29
30
+ ~TimeoutNode () override
31
+ {
32
+ timer_.cancelAll ();
33
+ }
34
+
30
35
static PortsList providedPorts ()
31
36
{
32
37
return { InputPort<unsigned >(" msec" , " After a certain amount of time, "
33
38
" halt() the child if it is still running." ) };
34
39
}
35
40
36
41
private:
37
- static TimerQueue& timer ()
38
- {
39
- static TimerQueue timer_queue;
40
- return timer_queue;
41
- }
42
+ TimerQueue timer_ ;
42
43
43
44
virtual BT::NodeStatus tick () override ;
44
45
@@ -48,6 +49,7 @@ class TimeoutNode : public DecoratorNode
48
49
unsigned msec_;
49
50
bool read_parameter_from_ports_;
50
51
bool timeout_started_;
52
+ std::mutex timeout_mutex_;
51
53
};
52
54
}
53
55
Original file line number Diff line number Diff line change @@ -54,9 +54,10 @@ NodeStatus TimeoutNode::tick()
54
54
55
55
if (msec_ > 0 )
56
56
{
57
- timer_id_ = timer () .add (std::chrono::milliseconds (msec_),
57
+ timer_id_ = timer_ .add (std::chrono::milliseconds (msec_),
58
58
[this ](bool aborted)
59
59
{
60
+ std::unique_lock<std::mutex> lk ( timeout_mutex_ );
60
61
if (!aborted && child ()->status () == NodeStatus::RUNNING)
61
62
{
62
63
child_halted_ = true ;
@@ -67,6 +68,8 @@ NodeStatus TimeoutNode::tick()
67
68
}
68
69
}
69
70
71
+ std::unique_lock<std::mutex> lk ( timeout_mutex_ );
72
+
70
73
if (child_halted_)
71
74
{
72
75
timeout_started_ = false ;
@@ -77,8 +80,10 @@ NodeStatus TimeoutNode::tick()
77
80
auto child_status = child ()->executeTick ();
78
81
if (child_status != NodeStatus::RUNNING)
79
82
{
80
- timer ().cancel (timer_id_);
81
83
timeout_started_ = false ;
84
+ timeout_mutex_.unlock ();
85
+ timer_.cancel (timer_id_);
86
+ timeout_mutex_.lock ();
82
87
}
83
88
return child_status;
84
89
}
You can’t perform that action at this time.
0 commit comments