Skip to content

Commit 83e0ec5

Browse files
jmachowinskiJanosch Machowinskiahcorde
authored
Event exec timer fix for #2889 (#2890)
Signed-off-by: Janosch Machowinski <[email protected]> Signed-off-by: Janosch Machowinski <[email protected]> Co-authored-by: Janosch Machowinski <[email protected]> Co-authored-by: Alejandro Hernández Cordero <[email protected]>
1 parent 7aab9b6 commit 83e0ec5

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

rclcpp/src/rclcpp/experimental/timers_manager.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,20 +273,22 @@ void TimersManager::run_timers()
273273
if (!time_to_sleep.has_value() || (time_to_sleep.value() == std::chrono::nanoseconds::max()) ) {
274274
// Wait until notification that timers have been updated
275275
timers_cv_.wait(lock, [this]() {return timers_updated_;});
276+
} else if (time_to_sleep.value() != std::chrono::nanoseconds::zero()) {
277+
// If time_to_sleep is zero, we immediately execute. Otherwise, wait
278+
// until timeout or notification that timers have been updated
279+
timers_cv_.wait_for(lock, time_to_sleep.value(), [this]() {return timers_updated_;});
280+
}
276281

282+
if (timers_updated_) {
277283
// Re-heap in case ordering changed due to a cancelled timer
278284
// re-activating.
279285
TimersHeap locked_heap = weak_timers_heap_.validate_and_lock();
280286
locked_heap.heapify();
281287
weak_timers_heap_.store(locked_heap);
282-
} else if (time_to_sleep.value() != std::chrono::nanoseconds::zero()) {
283-
// If time_to_sleep is zero, we immediately execute. Otherwise, wait
284-
// until timeout or notification that timers have been updated
285-
timers_cv_.wait_for(lock, time_to_sleep.value(), [this]() {return timers_updated_;});
286-
}
287288

288-
// Reset timers updated flag
289-
timers_updated_ = false;
289+
// Reset timers updated flag
290+
timers_updated_ = false;
291+
}
290292

291293
// Execute timers
292294
this->execute_ready_timers_unsafe();

0 commit comments

Comments
 (0)