Skip to content

Commit feef4e2

Browse files
author
Mauro Passerino
committed
Use timer_was_ready_at_tp
1 parent d0e8e43 commit feef4e2

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

rclcpp/include/rclcpp/executors/timers_manager.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ class TimersManager
106106
* @return true if head timer was ready at tp
107107
*/
108108
bool execute_head_timer(
109-
std::chrono::time_point<std::chrono::steady_clock> tp = TimePoint::max());
109+
std::chrono::time_point<std::chrono::steady_clock> tp =
110+
std::chrono::time_point<std::chrono::steady_clock>::max());
110111

111112
/**
112113
* @brief Get the amount of time before the next timer expires.
@@ -133,8 +134,6 @@ class TimersManager
133134
// See https://en.cppreference.com/w/cpp/thread/condition_variable/wait_for
134135
static constexpr std::chrono::nanoseconds MAX_TIME = std::chrono::hours(90);
135136

136-
using TimePoint = std::chrono::time_point<std::chrono::steady_clock>;
137-
138137
private:
139138
RCLCPP_DISABLE_COPY(TimersManager)
140139

rclcpp/src/rclcpp/executors/timers_manager.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,10 @@ bool TimersManager::execute_head_timer(
138138

139139
bool timer_ready = false;
140140

141-
if (timepoint != TimePoint::max()) {
142-
// A ready timer will return a negative duration when calling time_until_trigger
143-
auto timepoint_timer_ready = std::chrono::steady_clock::now() + head->time_until_trigger();
141+
auto max_time = std::chrono::time_point<std::chrono::steady_clock>::max();
144142

145-
// Here we check if the timer was already ready at timepoint
146-
timer_ready = timepoint_timer_ready < timepoint;
143+
if (timepoint != max_time) {
144+
timer_ready = timer_was_ready_at_tp(head, timepoint);
147145
} else {
148146
timer_ready = head->is_ready();
149147
}

0 commit comments

Comments
 (0)