fixed timer issue with setting the duration. Setting the duration cannot reset the on-going timer run

This commit is contained in:
Francisco Paisana 2019-10-22 16:56:28 +01:00
parent ecba994712
commit 9ae5563331
2 changed files with 36 additions and 1 deletions

View File

@ -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;
}

View File

@ -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;