From 9ae5563331187da61987a8be2f37a97db0507438 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Tue, 22 Oct 2019 16:56:28 +0100 Subject: [PATCH] fixed timer issue with setting the duration. Setting the duration cannot reset the on-going timer run --- lib/include/srslte/common/timers.h | 5 ++++- lib/test/common/timer_test.cc | 32 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/include/srslte/common/timers.h b/lib/include/srslte/common/timers.h index d7d4d111b..c199bcbd6 100644 --- a/lib/include/srslte/common/timers.h +++ b/lib/include/srslte/common/timers.h @@ -225,8 +225,11 @@ class timer_handler ERROR("Error: setting inactive timer id=%d\n", id()); return false; } - stop(); // invalidates any on-going run duration = duration_; + if (is_running()) { + // if already running, just extends timer lifetime + run(); + } return true; } diff --git a/lib/test/common/timer_test.cc b/lib/test/common/timer_test.cc index 2ad4288e1..cbbdb14fe 100644 --- a/lib/test/common/timer_test.cc +++ b/lib/test/common/timer_test.cc @@ -162,10 +162,42 @@ int timers2_test2() return SRSLTE_SUCCESS; } +int timers2_test3() +{ + /** + * Description: + * - setting a new duration while the timer is already running should not stop timer, and should extend timeout + */ + timer_handler timers; + uint32_t duration = 5; + + auto utimer = timers.get_unique_timer(); + utimer.set(duration); + utimer.run(); + + for (uint32_t i = 0; i < 2 * duration + 1; ++i) { + timers.step_all(); + if ((i % 2) == 0) { + // extends lifetime + utimer.set(duration); + } + TESTASSERT(utimer.is_running()); + } + for (uint32_t i = 0; i < duration - 1; ++i) { + timers.step_all(); + TESTASSERT(utimer.is_running()); + } + timers.step_all(); + TESTASSERT(not utimer.is_running()); + + return SRSLTE_SUCCESS; +} + int main() { TESTASSERT(timers2_test() == SRSLTE_SUCCESS); TESTASSERT(timers2_test2() == SRSLTE_SUCCESS); + TESTASSERT(timers2_test3() == SRSLTE_SUCCESS); printf("Success\n"); return 0;