@@ -273,20 +273,22 @@ void TimersManager::run_timers()
273273 if (!time_to_sleep.has_value () || (time_to_sleep.value () == std::chrono::nanoseconds::max ()) ) {
274274 // Wait until notification that timers have been updated
275275 timers_cv_.wait (lock, [this ]() {return timers_updated_;});
276+ } else if (time_to_sleep.value () != std::chrono::nanoseconds::zero ()) {
277+ // If time_to_sleep is zero, we immediately execute. Otherwise, wait
278+ // until timeout or notification that timers have been updated
279+ timers_cv_.wait_for (lock, time_to_sleep.value (), [this ]() {return timers_updated_;});
280+ }
276281
282+ if (timers_updated_) {
277283 // Re-heap in case ordering changed due to a cancelled timer
278284 // re-activating.
279285 TimersHeap locked_heap = weak_timers_heap_.validate_and_lock ();
280286 locked_heap.heapify ();
281287 weak_timers_heap_.store (locked_heap);
282- } else if (time_to_sleep.value () != std::chrono::nanoseconds::zero ()) {
283- // If time_to_sleep is zero, we immediately execute. Otherwise, wait
284- // until timeout or notification that timers have been updated
285- timers_cv_.wait_for (lock, time_to_sleep.value (), [this ]() {return timers_updated_;});
286- }
287288
288- // Reset timers updated flag
289- timers_updated_ = false ;
289+ // Reset timers updated flag
290+ timers_updated_ = false ;
291+ }
290292
291293 // Execute timers
292294 this ->execute_ready_timers_unsafe ();
0 commit comments