From 79e5bd94cf586332914eebb2fe0f09d5a5efe77e Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Fri, 28 Feb 2020 18:28:51 +0000 Subject: [PATCH] remove timers from priority queue for which run() or stop() was called. --- lib/include/srslte/common/timers.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/include/srslte/common/timers.h b/lib/include/srslte/common/timers.h index 4720d723b..fe401ea9a 100644 --- a/lib/include/srslte/common/timers.h +++ b/lib/include/srslte/common/timers.h @@ -225,8 +225,17 @@ public: { std::unique_lock lock(mutex); cur_time++; - while (not running_timers.empty() and cur_time >= running_timers.top().timeout) { - timer_impl* ptr = &timer_list[running_timers.top().timer_id]; + while (not running_timers.empty()) { + uint32_t next_timeout = running_timers.top().timeout; + timer_impl* ptr = &timer_list[running_timers.top().timer_id]; + if (not ptr->is_running() or next_timeout != ptr->timeout) { + // remove timers that were explicitly stopped, or re-run, to avoid unnecessary priority_queue growth + running_timers.pop(); + continue; + } + if (cur_time < next_timeout) { + break; + } // if the timer_run and timer_impl timeouts do not match, it means that timer_impl::timeout was overwritten. // in such case, do not trigger uint32_t timeout = running_timers.top().timeout;