void TimerBase::setNextFireTime(double newUnalignedTime) { ASSERT(m_thread == currentThread()); if (m_unalignedNextFireTime != newUnalignedTime) m_unalignedNextFireTime = newUnalignedTime; // Accessing thread global data is slow. Cache the heap pointer. if (!m_cachedThreadGlobalTimerHeap) m_cachedThreadGlobalTimerHeap = &threadGlobalTimerHeap(); // Keep heap valid while changing the next-fire time. double oldTime = m_nextFireTime; double newTime = alignedFireTime(newUnalignedTime); if (oldTime != newTime) { m_nextFireTime = newTime; static unsigned currentHeapInsertionOrder; m_heapInsertionOrder = currentHeapInsertionOrder++; bool wasFirstTimerInHeap = m_heapIndex == 0; updateHeapIfNeeded(oldTime); bool isFirstTimerInHeap = m_heapIndex == 0; if (wasFirstTimerInHeap || isFirstTimerInHeap) PlatformThreadData::current().threadTimers().updateSharedTimer(); } checkConsistency(); }
void TimerBase::setNextFireTime(double newTime) { ASSERT(canAccessThreadLocalDataForThread(m_thread)); ASSERT(!m_wasDeleted); if (m_unalignedNextFireTime != newTime) m_unalignedNextFireTime = newTime; // Accessing thread global data is slow. Cache the heap pointer. if (!m_cachedThreadGlobalTimerHeap) m_cachedThreadGlobalTimerHeap = &threadGlobalTimerHeap(); // Keep heap valid while changing the next-fire time. double oldTime = m_nextFireTime; // Don't realign zero-delay timers. if (newTime) { if (auto newAlignedTime = alignedFireTime(secondsToMS(newTime))) newTime = msToSeconds(newAlignedTime.value()); } if (oldTime != newTime) { m_nextFireTime = newTime; // FIXME: This should be part of ThreadTimers, or another per-thread structure. static std::atomic<unsigned> currentHeapInsertionOrder; m_heapInsertionOrder = currentHeapInsertionOrder++; bool wasFirstTimerInHeap = m_heapIndex == 0; updateHeapIfNeeded(oldTime); bool isFirstTimerInHeap = m_heapIndex == 0; if (wasFirstTimerInHeap || isFirstTimerInHeap) threadGlobalData().threadTimers().updateSharedTimer(); } checkConsistency(); }