@@ -70,8 +70,16 @@ TreeNode::~TreeNode()
70
70
71
71
NodeStatus TreeNode::executeTick ()
72
72
{
73
- std::unique_lock lk (_p->callback_injection_mutex );
74
73
auto new_status = _p->status ;
74
+ PreTickCallback pre_tick;
75
+ PostTickCallback post_tick;
76
+ TickMonitorCallback monitor_tick;
77
+ {
78
+ std::scoped_lock lk (_p->callback_injection_mutex );
79
+ pre_tick = _p->pre_tick_callback ;
80
+ post_tick = _p->post_tick_callback ;
81
+ monitor_tick = _p->tick_monitor_callback ;
82
+ }
75
83
76
84
// a pre-condition may return the new status.
77
85
// In this case it override the actual tick()
@@ -83,9 +91,9 @@ NodeStatus TreeNode::executeTick()
83
91
{
84
92
// injected pre-callback
85
93
bool substituted = false ;
86
- if (_p-> pre_tick_callback && !isStatusCompleted (_p->status ))
94
+ if (pre_tick && !isStatusCompleted (_p->status ))
87
95
{
88
- auto override_status = _p-> pre_tick_callback (*this );
96
+ auto override_status = pre_tick (*this );
89
97
if (isStatusCompleted (override_status))
90
98
{
91
99
// don't execute the actual tick()
@@ -97,18 +105,13 @@ NodeStatus TreeNode::executeTick()
97
105
// Call the ACTUAL tick
98
106
if (!substituted)
99
107
{
100
- if (_p->tick_monitor_callback )
101
- {
102
- using namespace std ::chrono;
103
- auto t1 = steady_clock::now ();
104
- new_status = tick ();
105
- auto t2 = steady_clock::now ();
106
- _p->tick_monitor_callback (*this , new_status,
107
- duration_cast<microseconds>(t2 - t1));
108
- }
109
- else
108
+ using namespace std ::chrono;
109
+ auto t1 = steady_clock::now ();
110
+ new_status = tick ();
111
+ auto t2 = steady_clock::now ();
112
+ if (monitor_tick)
110
113
{
111
- new_status = tick ( );
114
+ monitor_tick (* this , new_status, duration_cast<microseconds>(t2 - t1) );
112
115
}
113
116
}
114
117
}
@@ -119,9 +122,9 @@ NodeStatus TreeNode::executeTick()
119
122
checkPostConditions (new_status);
120
123
}
121
124
122
- if (_p-> post_tick_callback )
125
+ if (post_tick )
123
126
{
124
- auto override_status = _p-> post_tick_callback (*this , new_status);
127
+ auto override_status = post_tick (*this , new_status);
125
128
if (isStatusCompleted (override_status))
126
129
{
127
130
new_status = override_status;
0 commit comments