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(); }
inline void TimerBase::checkHeapIndex() const { ASSERT(timerHeap() == threadGlobalTimerHeap()); ASSERT(!timerHeap().isEmpty()); ASSERT(m_heapIndex >= 0); ASSERT(m_heapIndex < static_cast<int>(timerHeap().size())); ASSERT(timerHeap()[m_heapIndex] == this); }
void checkConsistency(ptrdiff_t offset = 0) const { ASSERT(m_pointer >= threadGlobalTimerHeap().data()); ASSERT(m_pointer <= threadGlobalTimerHeap().data() + threadGlobalTimerHeap().size()); ASSERT_UNUSED(offset, m_pointer + offset >= threadGlobalTimerHeap().data()); ASSERT_UNUSED(offset, m_pointer + offset <= threadGlobalTimerHeap().data() + threadGlobalTimerHeap().size()); }
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(); }