From 0aac621bece05ee44269f1c8407bc5d70640e10f Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Thu, 6 Sep 2018 15:20:50 -0700 Subject: [PATCH] fix logic for period zero --- rcl/src/rcl/timer.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/rcl/src/rcl/timer.c b/rcl/src/rcl/timer.c index eea18e8e4..1bd316940 100644 --- a/rcl/src/rcl/timer.c +++ b/rcl/src/rcl/timer.c @@ -148,11 +148,16 @@ rcl_timer_call(rcl_timer_t * timer) next_call_time += period; // in case the timer has missed at least once cycle if (next_call_time < unow) { - // move the next call time forward by as many periods as necessary - uint64_t now_ahead = unow - next_call_time; - // rounding up without overflow - uint64_t periods_ahead = 1 + (now_ahead - 1) / period; - next_call_time += periods_ahead * period; + if (0 == period) { + // a timer with a period of zero is considered always ready + next_call_time = unow; + } else { + // move the next call time forward by as many periods as necessary + uint64_t now_ahead = unow - next_call_time; + // rounding up without overflow + uint64_t periods_ahead = 1 + (now_ahead - 1) / period; + next_call_time += periods_ahead * period; + } } rcl_atomic_store(&timer->impl->next_call_time, next_call_time);