Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Unified Diff: Source/platform/Timer.h

Issue 1134523002: Implement timers by posting delayed tasks (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Gyp tweak. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/platform/Timer.h
diff --git a/Source/platform/Timer.h b/Source/platform/Timer.h
index e8015b6d5ca0cc4461b54fde74fad7fd1251f1a4..605c4ee988db0a68218b88ffe198be74ea1f21d6 100644
--- a/Source/platform/Timer.h
+++ b/Source/platform/Timer.h
@@ -15,7 +15,7 @@
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
@@ -28,6 +28,7 @@
#include "platform/PlatformExport.h"
#include "platform/heap/Handle.h"
+#include "platform/scheduler/CancellableTaskFactory.h"
#include "public/platform/WebTraceLocation.h"
#include "wtf/Noncopyable.h"
#include "wtf/Threading.h"
@@ -63,44 +64,28 @@ public:
double repeatInterval() const { return m_repeatInterval; }
void augmentRepeatInterval(double delta) {
- setNextFireTime(m_nextFireTime + delta);
+ double now = monotonicallyIncreasingTime();
+ setNextFireTime(now, m_nextFireTime - now + delta);
m_repeatInterval += delta;
}
- void didChangeAlignmentInterval();
+ void didChangeAlignmentInterval(double now);
private:
virtual void fired() = 0;
virtual double alignedFireTime(double fireTime) const { return fireTime; }
- void checkConsistency() const;
- void checkHeapIndex() const;
+ void setNextFireTime(double now, double delay);
- void setNextFireTime(double);
-
- bool inHeap() const { return m_heapIndex != -1; }
-
- bool hasValidHeapPosition() const;
- void updateHeapIfNeeded(double oldTime);
-
- void heapDecreaseKey();
- void heapDelete();
- void heapDeleteMin();
- void heapIncreaseKey();
- void heapInsert();
- void heapPop();
- void heapPopMin();
-
- Vector<TimerBase*>& timerHeap() const { ASSERT(m_cachedThreadGlobalTimerHeap); return *m_cachedThreadGlobalTimerHeap; }
+ void run();
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
- unsigned m_heapInsertionOrder; // Used to keep order among equal-fire-time timers
- Vector<TimerBase*>* m_cachedThreadGlobalTimerHeap;
WebTraceLocation m_location;
+ CancellableTaskFactory m_cancellableTaskFactory;
+ WebScheduler* m_webScheduler; // Not owned.
#if ENABLE(ASSERT)
ThreadIdentifier m_thread;
@@ -157,7 +142,7 @@ private:
inline bool TimerBase::isActive() const
{
ASSERT(m_thread == currentThread());
- return m_nextFireTime;
+ return m_cancellableTaskFactory.isPending();
}
}

Powered by Google App Engine
This is Rietveld 408576698