mirror of https://github.com/PentHertz/srsLTE.git
fixed timer issue with setting the duration. Setting the duration cannot reset the on-going timer run
This commit is contained in:
parent
ecba994712
commit
9ae5563331
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue