Diff
Modified: trunk/Source/WTF/ChangeLog (215135 => 215136)
--- trunk/Source/WTF/ChangeLog 2017-04-08 01:15:09 UTC (rev 215135)
+++ trunk/Source/WTF/ChangeLog 2017-04-08 01:33:55 UTC (rev 215136)
@@ -1,3 +1,15 @@
+2017-04-07 Chris Dumez <cdu...@apple.com>
+
+ Start using MonotonicTime / Seconds in Timer class
+ https://bugs.webkit.org/show_bug.cgi?id=170625
+
+ Reviewed by Simon Fraser.
+
+ Add modulo operator to MonotonicTime.
+
+ * wtf/MonotonicTime.h:
+ (WTF::MonotonicTime::operator%):
+
2017-04-07 Keith Miller <keith_mil...@apple.com>
Add a PriorityQueue class
Modified: trunk/Source/WTF/wtf/MonotonicTime.h (215135 => 215136)
--- trunk/Source/WTF/wtf/MonotonicTime.h 2017-04-08 01:15:09 UTC (rev 215135)
+++ trunk/Source/WTF/wtf/MonotonicTime.h 2017-04-08 01:33:55 UTC (rev 215136)
@@ -78,6 +78,11 @@
{
return fromRawSeconds(m_value - other.value());
}
+
+ Seconds operator%(Seconds other) const
+ {
+ return Seconds { fmod(m_value, other.value()) };
+ }
// Time is a scalar and scalars can be negated as this could arise from algebraic
// transformations. So, we allow it.
Modified: trunk/Source/WebCore/ChangeLog (215135 => 215136)
--- trunk/Source/WebCore/ChangeLog 2017-04-08 01:15:09 UTC (rev 215135)
+++ trunk/Source/WebCore/ChangeLog 2017-04-08 01:33:55 UTC (rev 215136)
@@ -1,3 +1,57 @@
+2017-04-07 Chris Dumez <cdu...@apple.com>
+
+ Start using MonotonicTime / Seconds in Timer class
+ https://bugs.webkit.org/show_bug.cgi?id=170625
+
+ Reviewed by Simon Fraser.
+
+ Start using MonotonicTime / Seconds in Timer class. More work will be needed
+ for the transition to be complete. I plan to do this in a follow-up.
+
+ * page/DOMTimer.cpp:
+ (WebCore::DOMTimer::alignedFireTime):
+ * page/DOMTimer.h:
+ * page/SuspendableTimer.cpp:
+ (WebCore::SuspendableTimer::suspend):
+ (WebCore::SuspendableTimer::startRepeating):
+ (WebCore::SuspendableTimer::startOneShot):
+ (WebCore::SuspendableTimer::repeatInterval):
+ (WebCore::SuspendableTimer::augmentFireInterval):
+ (WebCore::SuspendableTimer::augmentRepeatInterval):
+ * page/SuspendableTimer.h:
+ (WebCore::SuspendableTimer::startRepeating):
+ (WebCore::SuspendableTimer::startOneShot):
+ (WebCore::SuspendableTimer::augmentFireInterval):
+ (WebCore::SuspendableTimer::augmentRepeatInterval):
+ * platform/ThreadTimers.cpp:
+ (WebCore::ThreadTimers::ThreadTimers):
+ (WebCore::ThreadTimers::setSharedTimer):
+ (WebCore::ThreadTimers::updateSharedTimer):
+ (WebCore::ThreadTimers::sharedTimerFiredInternal):
+ (WebCore::ThreadTimers::fireTimersInNestedEventLoop):
+ * platform/ThreadTimers.h:
+ * platform/Timer.cpp:
+ (WebCore::TimerHeapLessThanFunction::operator()):
+ (WebCore::TimerBase::TimerBase):
+ (WebCore::TimerBase::start):
+ (WebCore::TimerBase::stop):
+ (WebCore::TimerBase::nextFireInterval):
+ (WebCore::TimerBase::heapPop):
+ (WebCore::TimerBase::updateHeapIfNeeded):
+ (WebCore::TimerBase::setNextFireTime):
+ (WebCore::TimerBase::nextUnalignedFireInterval):
+ * platform/Timer.h:
+ (WebCore::TimerBase::start):
+ (WebCore::TimerBase::startOneShot):
+ (WebCore::TimerBase::repeatInterval):
+ (WebCore::TimerBase::repeatIntervalSeconds):
+ (WebCore::TimerBase::augmentFireInterval):
+ (WebCore::TimerBase::augmentRepeatInterval):
+ (WebCore::TimerBase::alignedFireTime):
+ (WebCore::TimerBase::isActive):
+ * testing/Internals.cpp:
+ (WebCore::Internals::isTimerThrottled):
+
2017-04-07 Yuichiro Kikura <y.kik...@gmail.com>
WebGPU: implement ComputeCommandEncoder and related components
Modified: trunk/Source/WebCore/page/DOMTimer.cpp (215135 => 215136)
--- trunk/Source/WebCore/page/DOMTimer.cpp 2017-04-08 01:15:09 UTC (rev 215135)
+++ trunk/Source/WebCore/page/DOMTimer.cpp 2017-04-08 01:33:55 UTC (rev 215136)
@@ -427,7 +427,7 @@
return interval;
}
-std::optional<Seconds> DOMTimer::alignedFireTime(Seconds fireTime) const
+std::optional<MonotonicTime> DOMTimer::alignedFireTime(MonotonicTime fireTime) const
{
Seconds alignmentInterval = scriptExecutionContext()->domTimerAlignmentInterval(m_nestingLevel >= maxTimerNestingLevel);
if (!alignmentInterval)
@@ -438,7 +438,7 @@
// Force alignment to randomizedAlignment fraction of the way between alignemntIntervals, e.g.
// if alignmentInterval is 10_ms and randomizedAlignment is 0.3 this will align to 3, 13, 23, ...
Seconds randomizedOffset = alignmentInterval * randomizedProportion;
- Seconds adjustedFireTime = fireTime - randomizedOffset;
+ MonotonicTime adjustedFireTime = fireTime - randomizedOffset;
return adjustedFireTime - (adjustedFireTime % alignmentInterval) + alignmentInterval + randomizedOffset;
}
Modified: trunk/Source/WebCore/page/DOMTimer.h (215135 => 215136)
--- trunk/Source/WebCore/page/DOMTimer.h 2017-04-08 01:15:09 UTC (rev 215135)
+++ trunk/Source/WebCore/page/DOMTimer.h 2017-04-08 01:33:55 UTC (rev 215136)
@@ -29,6 +29,7 @@
#include "SuspendableTimer.h"
#include "UserGestureIndicator.h"
#include <memory>
+#include <wtf/MonotonicTime.h>
#include <wtf/RefCounted.h>
#include <wtf/Seconds.h>
@@ -74,7 +75,7 @@
// SuspendableTimer
void fired() override;
void didStop() override;
- WEBCORE_EXPORT std::optional<Seconds> alignedFireTime(Seconds) const override;
+ WEBCORE_EXPORT std::optional<MonotonicTime> alignedFireTime(MonotonicTime) const override;
// ActiveDOMObject API.
const char* activeDOMObjectName() const override;
Modified: trunk/Source/WebCore/page/SuspendableTimer.cpp (215135 => 215136)
--- trunk/Source/WebCore/page/SuspendableTimer.cpp 2017-04-08 01:15:09 UTC (rev 215135)
+++ trunk/Source/WebCore/page/SuspendableTimer.cpp 2017-04-08 01:33:55 UTC (rev 215136)
@@ -66,7 +66,7 @@
m_savedIsActive = TimerBase::isActive();
if (m_savedIsActive) {
m_savedNextFireInterval = TimerBase::nextUnalignedFireInterval();
- m_savedRepeatInterval = TimerBase::repeatInterval();
+ m_savedRepeatInterval = TimerBase::repeatIntervalSeconds();
TimerBase::stop();
}
}
@@ -97,7 +97,7 @@
m_suspended = false;
}
-void SuspendableTimer::startRepeating(double repeatInterval)
+void SuspendableTimer::startRepeating(Seconds repeatInterval)
{
if (!m_suspended)
TimerBase::startRepeating(repeatInterval);
@@ -108,7 +108,7 @@
}
}
-void SuspendableTimer::startOneShot(double interval)
+void SuspendableTimer::startOneShot(Seconds interval)
{
if (!m_suspended)
TimerBase::startOneShot(interval);
@@ -115,7 +115,7 @@
else {
m_savedIsActive = true;
m_savedNextFireInterval = interval;
- m_savedRepeatInterval = 0;
+ m_savedRepeatInterval = 0_s;
}
}
@@ -124,11 +124,11 @@
if (!m_suspended)
return TimerBase::repeatInterval();
if (m_savedIsActive)
- return m_savedRepeatInterval;
+ return m_savedRepeatInterval.value();
return 0;
}
-void SuspendableTimer::augmentFireInterval(double delta)
+void SuspendableTimer::augmentFireInterval(Seconds delta)
{
if (!m_suspended)
TimerBase::augmentFireInterval(delta);
@@ -137,11 +137,11 @@
} else {
m_savedIsActive = true;
m_savedNextFireInterval = delta;
- m_savedRepeatInterval = 0;
+ m_savedRepeatInterval = 0_s;
}
}
-void SuspendableTimer::augmentRepeatInterval(double delta)
+void SuspendableTimer::augmentRepeatInterval(Seconds delta)
{
if (!m_suspended)
TimerBase::augmentRepeatInterval(delta);
Modified: trunk/Source/WebCore/page/SuspendableTimer.h (215135 => 215136)
--- trunk/Source/WebCore/page/SuspendableTimer.h 2017-04-08 01:15:09 UTC (rev 215135)
+++ trunk/Source/WebCore/page/SuspendableTimer.h 2017-04-08 01:33:55 UTC (rev 215136)
@@ -45,14 +45,15 @@
bool isActive() const { return TimerBase::isActive() || (m_suspended && m_savedIsActive); }
bool isSuspended() const { return m_suspended; }
- void startRepeating(double repeatInterval);
- void startOneShot(double interval);
+ void startRepeating(double repeatInterval) { startRepeating(Seconds { repeatInterval }); }
+ void startOneShot(double interval) { startOneShot(Seconds { interval }); }
+
double repeatInterval() const;
- void augmentFireInterval(double delta);
- void augmentRepeatInterval(double delta);
+ void augmentFireInterval(double delta) { augmentFireInterval(Seconds { delta }); }
+ void augmentRepeatInterval(double delta) { augmentRepeatInterval(Seconds { delta }); }
- void startRepeating(Seconds repeatInterval) { startRepeating(repeatInterval.value()); }
- void startOneShot(Seconds interval) { startOneShot(interval.value()); }
+ void startRepeating(Seconds repeatInterval);
+ void startOneShot(Seconds interval);
// FIXME: Use the overloads taking Seconds instead and drop these.
void startRepeating(std::chrono::milliseconds repeatInterval) { startRepeating(msToSeconds(repeatInterval)); }
@@ -61,8 +62,8 @@
std::chrono::milliseconds repeatIntervalMS() const { return secondsToMS(repeatInterval()); }
Seconds repeatIntervalSeconds() const { return Seconds { repeatInterval() }; }
- void augmentFireInterval(Seconds delta) { augmentFireInterval(delta.value()); }
- void augmentRepeatInterval(Seconds delta) { augmentRepeatInterval(delta.value()); }
+ void augmentFireInterval(Seconds delta);
+ void augmentRepeatInterval(Seconds delta);
// FIXME: Use the overloads taking Seconds instead and drop these.
void augmentFireInterval(std::chrono::milliseconds delta) { augmentFireInterval(msToSeconds(delta)); }
@@ -84,8 +85,8 @@
void suspend(ReasonForSuspension) final;
void resume() final;
- double m_savedNextFireInterval { 0 };
- double m_savedRepeatInterval { 0 };
+ Seconds m_savedNextFireInterval;
+ Seconds m_savedRepeatInterval;
bool m_suspended { false };
bool m_savedIsActive { false };
Modified: trunk/Source/WebCore/platform/ThreadTimers.cpp (215135 => 215136)
--- trunk/Source/WebCore/platform/ThreadTimers.cpp 2017-04-08 01:15:09 UTC (rev 215135)
+++ trunk/Source/WebCore/platform/ThreadTimers.cpp 2017-04-08 01:33:55 UTC (rev 215136)
@@ -43,15 +43,12 @@
// Fire timers for this length of time, and then quit to let the run loop process user input events.
// 100ms is about a perceptable delay in UI, so use a half of that as a threshold.
// This is to prevent UI freeze when there are too many timers or machine performance is low.
-static const double maxDurationOfFiringTimers = 0.050;
+static const Seconds maxDurationOfFiringTimers { 50_ms };
// Timers are created, started and fired on the same thread, and each thread has its own ThreadTimers
// copy to keep the heap and a set of currently firing timers.
ThreadTimers::ThreadTimers()
- : m_sharedTimer(0)
- , m_firingTimers(false)
- , m_pendingSharedTimerFireTime(0)
{
if (isUIThread())
setSharedTimer(&MainThreadSharedTimer::singleton());
@@ -64,7 +61,7 @@
if (m_sharedTimer) {
m_sharedTimer->setFiredFunction(nullptr);
m_sharedTimer->stop();
- m_pendingSharedTimerFireTime = 0;
+ m_pendingSharedTimerFireTime = MonotonicTime { };
}
m_sharedTimer = sharedTimer;
@@ -81,11 +78,11 @@
return;
if (m_firingTimers || m_timerHeap.isEmpty()) {
- m_pendingSharedTimerFireTime = 0;
+ m_pendingSharedTimerFireTime = MonotonicTime { };
m_sharedTimer->stop();
} else {
- double nextFireTime = m_timerHeap.first()->m_nextFireTime;
- double currentMonotonicTime = monotonicallyIncreasingTime();
+ MonotonicTime nextFireTime = m_timerHeap.first()->m_nextFireTime;
+ MonotonicTime currentMonotonicTime = MonotonicTime::now();
if (m_pendingSharedTimerFireTime) {
// No need to restart the timer if both the pending fire time and the new fire time are in the past.
if (m_pendingSharedTimerFireTime <= currentMonotonicTime && nextFireTime <= currentMonotonicTime)
@@ -92,7 +89,7 @@
return;
}
m_pendingSharedTimerFireTime = nextFireTime;
- m_sharedTimer->setFireInterval(Seconds(std::max(nextFireTime - currentMonotonicTime, 0.0)));
+ m_sharedTimer->setFireInterval(std::max(nextFireTime - currentMonotonicTime, 0_s));
}
}
@@ -103,25 +100,25 @@
if (m_firingTimers)
return;
m_firingTimers = true;
- m_pendingSharedTimerFireTime = 0;
+ m_pendingSharedTimerFireTime = MonotonicTime { };
- double fireTime = monotonicallyIncreasingTime();
- double timeToQuit = fireTime + maxDurationOfFiringTimers;
+ MonotonicTime fireTime = MonotonicTime::now();
+ MonotonicTime 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->m_nextFireTime = MonotonicTime { };
+ timer->m_unalignedNextFireTime = MonotonicTime { };
timer->heapDeleteMin();
- double interval = timer->repeatInterval();
- timer->setNextFireTime(interval ? fireTime + interval : 0);
+ Seconds interval = timer->repeatIntervalSeconds();
+ timer->setNextFireTime(interval ? fireTime + interval : MonotonicTime { });
// 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())
+ if (!m_firingTimers || timeToQuit < MonotonicTime::now())
break;
}
@@ -137,7 +134,7 @@
if (m_sharedTimer) {
m_sharedTimer->invalidate();
- m_pendingSharedTimerFireTime = 0;
+ m_pendingSharedTimerFireTime = MonotonicTime { };
}
updateSharedTimer();
Modified: trunk/Source/WebCore/platform/ThreadTimers.h (215135 => 215136)
--- trunk/Source/WebCore/platform/ThreadTimers.h 2017-04-08 01:15:09 UTC (rev 215135)
+++ trunk/Source/WebCore/platform/ThreadTimers.h 2017-04-08 01:33:55 UTC (rev 215136)
@@ -27,6 +27,7 @@
#ifndef ThreadTimers_h
#define ThreadTimers_h
+#include <wtf/MonotonicTime.h>
#include <wtf/Noncopyable.h>
#include <wtf/Vector.h>
@@ -54,9 +55,9 @@
void fireTimersInNestedEventLoopInternal();
Vector<TimerBase*> m_timerHeap;
- SharedTimer* m_sharedTimer; // External object, can be a run loop on a worker thread. Normally set/reset by worker thread.
- bool m_firingTimers; // Reentrancy guard.
- double m_pendingSharedTimerFireTime;
+ SharedTimer* m_sharedTimer { nullptr }; // External object, can be a run loop on a worker thread. Normally set/reset by worker thread.
+ bool m_firingTimers { false }; // Reentrancy guard.
+ MonotonicTime m_pendingSharedTimerFireTime;
};
}
Modified: trunk/Source/WebCore/platform/Timer.cpp (215135 => 215136)
--- trunk/Source/WebCore/platform/Timer.cpp 2017-04-08 01:15:09 UTC (rev 215135)
+++ trunk/Source/WebCore/platform/Timer.cpp 2017-04-08 01:33:55 UTC (rev 215136)
@@ -172,8 +172,8 @@
{
// The comparisons below are "backwards" because the heap puts the largest
// element first and we want the lowest time to be the first one in the heap.
- double aFireTime = a->m_nextFireTime;
- double bFireTime = b->m_nextFireTime;
+ MonotonicTime aFireTime = a->m_nextFireTime;
+ MonotonicTime bFireTime = b->m_nextFireTime;
if (bFireTime != aFireTime)
return bFireTime < aFireTime;
@@ -186,14 +186,8 @@
// ----------------
TimerBase::TimerBase()
- : m_nextFireTime(0)
- , m_unalignedNextFireTime(0)
- , m_repeatInterval(0)
- , m_heapIndex(-1)
- , m_cachedThreadGlobalTimerHeap(0)
#ifndef NDEBUG
- , m_thread(currentThread())
- , m_wasDeleted(false)
+ : m_thread(currentThread())
#endif
{
}
@@ -207,12 +201,12 @@
#endif
}
-void TimerBase::start(double nextFireInterval, double repeatInterval)
+void TimerBase::start(Seconds nextFireInterval, Seconds repeatInterval)
{
ASSERT(canAccessThreadLocalDataForThread(m_thread));
m_repeatInterval = repeatInterval;
- setNextFireTime(monotonicallyIncreasingTime() + nextFireInterval);
+ setNextFireTime(MonotonicTime::now() + nextFireInterval);
}
void TimerBase::stop()
@@ -219,11 +213,11 @@
{
ASSERT(canAccessThreadLocalDataForThread(m_thread));
- m_repeatInterval = 0;
- setNextFireTime(0);
+ m_repeatInterval = 0_s;
+ setNextFireTime(MonotonicTime { });
- ASSERT(m_nextFireTime == 0);
- ASSERT(m_repeatInterval == 0);
+ ASSERT(!static_cast<bool>(m_nextFireTime));
+ ASSERT(m_repeatInterval == 0_s);
ASSERT(!inHeap());
}
@@ -230,10 +224,10 @@
double TimerBase::nextFireInterval() const
{
ASSERT(isActive());
- double current = monotonicallyIncreasingTime();
+ MonotonicTime current = MonotonicTime::now();
if (m_nextFireTime < current)
return 0;
- return m_nextFireTime - current;
+ return (m_nextFireTime - current).value();
}
inline void TimerBase::checkHeapIndex() const
@@ -248,7 +242,7 @@
inline void TimerBase::checkConsistency() const
{
// Timers should be in the heap if and only if they have a non-zero next fire time.
- ASSERT(inHeap() == (m_nextFireTime != 0));
+ ASSERT(inHeap() == static_cast<bool>(m_nextFireTime));
if (inHeap())
checkHeapIndex();
}
@@ -255,7 +249,7 @@
void TimerBase::heapDecreaseKey()
{
- ASSERT(m_nextFireTime != 0);
+ ASSERT(static_cast<bool>(m_nextFireTime));
checkHeapIndex();
TimerBase** heapData = timerHeap().data();
push_heap(TimerHeapIterator(heapData), TimerHeapIterator(heapData + m_heapIndex + 1), TimerHeapLessThanFunction());
@@ -264,7 +258,7 @@
inline void TimerBase::heapDelete()
{
- ASSERT(m_nextFireTime == 0);
+ ASSERT(!static_cast<bool>(m_nextFireTime));
heapPop();
timerHeap().removeLast();
m_heapIndex = -1;
@@ -272,7 +266,7 @@
void TimerBase::heapDeleteMin()
{
- ASSERT(m_nextFireTime == 0);
+ ASSERT(!static_cast<bool>(m_nextFireTime));
heapPopMin();
timerHeap().removeLast();
m_heapIndex = -1;
@@ -280,7 +274,7 @@
inline void TimerBase::heapIncreaseKey()
{
- ASSERT(m_nextFireTime != 0);
+ ASSERT(static_cast<bool>(m_nextFireTime));
heapPop();
heapDecreaseKey();
}
@@ -296,8 +290,8 @@
inline void TimerBase::heapPop()
{
// Temporarily force this timer to have the minimum key so we can pop it.
- double fireTime = m_nextFireTime;
- m_nextFireTime = -std::numeric_limits<double>::infinity();
+ MonotonicTime fireTime = m_nextFireTime;
+ m_nextFireTime = -MonotonicTime::infinity();
heapDecreaseKey();
heapPopMin();
m_nextFireTime = fireTime;
@@ -347,7 +341,7 @@
return childHeapPropertyHolds(this, heap, childIndex1) && childHeapPropertyHolds(this, heap, childIndex2);
}
-void TimerBase::updateHeapIfNeeded(double oldTime)
+void TimerBase::updateHeapIfNeeded(MonotonicTime oldTime)
{
if (m_nextFireTime && hasValidHeapPosition())
return;
@@ -366,7 +360,7 @@
ASSERT(!inHeap() || hasValidHeapPosition());
}
-void TimerBase::setNextFireTime(double newTime)
+void TimerBase::setNextFireTime(MonotonicTime newTime)
{
ASSERT(canAccessThreadLocalDataForThread(m_thread));
ASSERT(!m_wasDeleted);
@@ -379,11 +373,11 @@
m_cachedThreadGlobalTimerHeap = &threadGlobalTimerHeap();
// Keep heap valid while changing the next-fire time.
- double oldTime = m_nextFireTime;
+ MonotonicTime oldTime = m_nextFireTime;
// Don't realign zero-delay timers.
if (newTime) {
- if (auto newAlignedTime = alignedFireTime(Seconds { newTime }))
- newTime = newAlignedTime.value().seconds();
+ if (auto newAlignedTime = alignedFireTime(newTime))
+ newTime = newAlignedTime.value();
}
if (oldTime != newTime) {
@@ -416,10 +410,10 @@
setNextFireTime(m_unalignedNextFireTime);
}
-double TimerBase::nextUnalignedFireInterval() const
+Seconds TimerBase::nextUnalignedFireInterval() const
{
ASSERT(isActive());
- return std::max(m_unalignedNextFireTime - monotonicallyIncreasingTime(), 0.0);
+ return std::max(m_unalignedNextFireTime - MonotonicTime::now(), 0_s);
}
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/Timer.h (215135 => 215136)
--- trunk/Source/WebCore/platform/Timer.h 2017-04-08 01:15:09 UTC (rev 215135)
+++ trunk/Source/WebCore/platform/Timer.h 2017-04-08 01:33:55 UTC (rev 215136)
@@ -28,6 +28,7 @@
#include <chrono>
#include <functional>
+#include <wtf/MonotonicTime.h>
#include <wtf/Noncopyable.h>
#include <wtf/Optional.h>
#include <wtf/Seconds.h>
@@ -55,7 +56,8 @@
WEBCORE_EXPORT TimerBase();
WEBCORE_EXPORT virtual ~TimerBase();
- WEBCORE_EXPORT void start(double nextFireInterval, double repeatInterval);
+ WEBCORE_EXPORT void start(Seconds nextFireInterval, Seconds repeatInterval);
+ WEBCORE_EXPORT void start(double nextFireInterval, double repeatInterval) { start(Seconds { nextFireInterval }, Seconds { repeatInterval }); }
void startRepeating(double repeatInterval) { start(repeatInterval, repeatInterval); }
void startRepeating(std::chrono::milliseconds repeatInterval) { startRepeating(msToSeconds(repeatInterval)); }
@@ -63,23 +65,24 @@
void startOneShot(double interval) { start(interval, 0); }
void startOneShot(std::chrono::milliseconds interval) { startOneShot(msToSeconds(interval)); }
- void startOneShot(Seconds interval) { start(interval.value(), 0); }
+ void startOneShot(Seconds interval) { start(interval, 0_s); }
WEBCORE_EXPORT void stop();
bool isActive() const;
- double nextFireInterval() const;
- double nextUnalignedFireInterval() const;
- double repeatInterval() const { return m_repeatInterval; }
+ double nextFireInterval() const; // FIXME: Should return Seconds.
+ Seconds nextUnalignedFireInterval() const;
+ double repeatInterval() const { return m_repeatInterval.value(); } // FIXME: Should return Seconds.
+ Seconds repeatIntervalSeconds() const { return m_repeatInterval; } // FIXME: Remove once repeatInterval() returns Seconds.
std::chrono::milliseconds repeatIntervalMS() const { return secondsToMS(repeatInterval()); }
- void augmentFireInterval(double delta) { setNextFireTime(m_nextFireTime + delta); }
+ void augmentFireInterval(Seconds delta) { setNextFireTime(m_nextFireTime + delta); }
void augmentFireInterval(std::chrono::milliseconds delta) { augmentFireInterval(msToSeconds(delta)); }
- void augmentFireInterval(Seconds delta) { augmentFireInterval(delta.value()); }
+ void augmentFireInterval(double delta) { augmentFireInterval(Seconds { delta }); }
- void augmentRepeatInterval(double delta) { augmentFireInterval(delta); m_repeatInterval += delta; }
+ void augmentRepeatInterval(Seconds delta) { augmentFireInterval(delta); m_repeatInterval += delta; }
void augmentRepeatInterval(std::chrono::milliseconds delta) { augmentRepeatInterval(msToSeconds(delta)); }
- void augmentRepeatInterval(Seconds delta) { augmentRepeatInterval(delta.value()); }
+ void augmentRepeatInterval(double delta) { augmentRepeatInterval(Seconds { delta }); }
void didChangeAlignmentInterval();
@@ -88,17 +91,17 @@
private:
virtual void fired() = 0;
- virtual std::optional<Seconds> alignedFireTime(Seconds) const { return std::nullopt; }
+ virtual std::optional<MonotonicTime> alignedFireTime(MonotonicTime) const { return std::nullopt; }
void checkConsistency() const;
void checkHeapIndex() const;
- void setNextFireTime(double);
+ void setNextFireTime(MonotonicTime);
bool inHeap() const { return m_heapIndex != -1; }
bool hasValidHeapPosition() const;
- void updateHeapIfNeeded(double oldTime);
+ void updateHeapIfNeeded(MonotonicTime oldTime);
void heapDecreaseKey();
void heapDelete();
@@ -110,16 +113,16 @@
Vector<TimerBase*>& timerHeap() const { ASSERT(m_cachedThreadGlobalTimerHeap); return *m_cachedThreadGlobalTimerHeap; }
- double m_nextFireTime; // 0 if inactive
- double m_unalignedNextFireTime; // m_nextFireTime not considering alignment interval
- double m_repeatInterval; // 0 if not repeating
- int m_heapIndex; // -1 if not in heap
+ MonotonicTime m_nextFireTime; // 0 if inactive
+ MonotonicTime m_unalignedNextFireTime; // m_nextFireTime not considering alignment interval
+ Seconds m_repeatInterval; // 0 if not repeating
+ int m_heapIndex { -1 }; // -1 if not in heap
unsigned m_heapInsertionOrder; // Used to keep order among equal-fire-time timers
- Vector<TimerBase*>* m_cachedThreadGlobalTimerHeap;
+ Vector<TimerBase*>* m_cachedThreadGlobalTimerHeap { nullptr };
#ifndef NDEBUG
ThreadIdentifier m_thread;
- bool m_wasDeleted;
+ bool m_wasDeleted { false };
#endif
friend class ThreadTimers;
@@ -159,7 +162,7 @@
#else
ASSERT(WebThreadIsCurrent() || pthread_main_np() || m_thread == currentThread());
#endif // PLATFORM(IOS)
- return m_nextFireTime;
+ return static_cast<bool>(m_nextFireTime);
}
class DeferrableOneShotTimer : protected TimerBase {
Modified: trunk/Source/WebCore/testing/Internals.cpp (215135 => 215136)
--- trunk/Source/WebCore/testing/Internals.cpp 2017-04-08 01:15:09 UTC (rev 215135)
+++ trunk/Source/WebCore/testing/Internals.cpp 2017-04-08 01:33:55 UTC (rev 215136)
@@ -151,6 +151,7 @@
#include <runtime/JSCInlines.h>
#include <runtime/JSCJSValue.h>
#include <wtf/MemoryPressureHandler.h>
+#include <wtf/MonotonicTime.h>
#include <wtf/text/CString.h>
#include <wtf/text/StringBuffer.h>
#include <wtf/text/StringBuilder.h>
@@ -1081,7 +1082,7 @@
if (timer->intervalClampedToMinimum() > timer->m_originalInterval)
return true;
- return !!timer->alignedFireTime(0_s);
+ return !!timer->alignedFireTime(MonotonicTime { });
}
bool Internals::isRequestAnimationFrameThrottled() const