void ThreadTimers::sharedTimerFiredInternal() { // Do a re-entrancy check. if (m_firingTimers) return; m_firingTimers = true; m_pendingSharedTimerFireTime = 0; double fireTime = monotonicallyIncreasingTime(); double timeToQuit = fireTime + maxDurationOfFiringTimers; while (!m_timerHeap.isEmpty() && m_timerHeap.first()->m_nextFireTime <= fireTime) { TimerBase* timer = m_timerHeap.first(); timer->m_nextFireTime = 0; timer->m_unalignedNextFireTime = 0; timer->heapDeleteMin(); double interval = timer->repeatInterval(); timer->setNextFireTime(interval ? fireTime + interval : 0); // Once the timer has been fired, it may be deleted, so do nothing else with it after this point. timer->fired(); // Catch the case where the timer asked timers to fire in a nested event loop, or we are over time limit. if (!m_firingTimers || timeToQuit < monotonicallyIncreasingTime()) break; } m_firingTimers = false; updateSharedTimer(); }
void TimerBase::fireTimers(double fireTime, const Vector<TimerBase*>& firingTimers) { int size = firingTimers.size(); for (int i = 0; i != size; ++i) { TimerBase* timer = firingTimers[i]; // If not in the set, this timer has been deleted or re-scheduled in another timer's fired function. // So either we don't want to fire it at all or we will fire it next time the shared timer goes off. // It might even have been deleted; that's OK because we won't do anything else with the pointer. if (!timersReadyToFire->contains(timer)) continue; // Setting the next fire time has a side effect of removing the timer from the firing timers set. double interval = timer->repeatInterval(); timer->setNextFireTime(interval ? fireTime + interval : 0); // Once the timer has been fired, it may be deleted, so do nothing else with it after this point. timer->fired(); // Catch the case where the timer asked timers to fire in a nested event loop. if (!timersReadyToFire) break; } }