@@ -70,8 +70,16 @@ TreeNode::~TreeNode()
7070
7171NodeStatus TreeNode::executeTick ()
7272{
73- std::unique_lock lk (_p->callback_injection_mutex );
7473 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+ }
7583
7684 // a pre-condition may return the new status.
7785 // In this case it override the actual tick()
@@ -83,9 +91,9 @@ NodeStatus TreeNode::executeTick()
8391 {
8492 // injected pre-callback
8593 bool substituted = false ;
86- if (_p-> pre_tick_callback && !isStatusCompleted (_p->status ))
94+ if (pre_tick && !isStatusCompleted (_p->status ))
8795 {
88- auto override_status = _p-> pre_tick_callback (*this );
96+ auto override_status = pre_tick (*this );
8997 if (isStatusCompleted (override_status))
9098 {
9199 // don't execute the actual tick()
@@ -97,18 +105,13 @@ NodeStatus TreeNode::executeTick()
97105 // Call the ACTUAL tick
98106 if (!substituted)
99107 {
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)
110113 {
111- new_status = tick ( );
114+ monitor_tick (* this , new_status, duration_cast<microseconds>(t2 - t1) );
112115 }
113116 }
114117 }
@@ -119,9 +122,9 @@ NodeStatus TreeNode::executeTick()
119122 checkPostConditions (new_status);
120123 }
121124
122- if (_p-> post_tick_callback )
125+ if (post_tick )
123126 {
124- auto override_status = _p-> post_tick_callback (*this , new_status);
127+ auto override_status = post_tick (*this , new_status);
125128 if (isStatusCompleted (override_status))
126129 {
127130 new_status = override_status;
0 commit comments