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

Unified Diff: Source/platform/TimerHeapEntry.h

Issue 959263002: WIP - not ready for review (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Decouple TimerHeap and ThreadTimers. Created 5 years, 10 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
« no previous file with comments | « Source/platform/TimerHeap.cpp ('k') | Source/platform/TimerHeapEntry.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/TimerHeapEntry.h
diff --git a/Source/platform/TimerHeapEntry.h b/Source/platform/TimerHeapEntry.h
new file mode 100644
index 0000000000000000000000000000000000000000..c6366a2554806a5cf5198512edb757277f57618f
--- /dev/null
+++ b/Source/platform/TimerHeapEntry.h
@@ -0,0 +1,70 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TimerHeapEntry_h
+#define TimerHeapEntry_h
+
+#include "wtf/Noncopyable.h"
+#include <stddef.h>
+
+namespace blink {
+
+class TimerBase;
+class TimerHeap;
+
+// TimerHeapEntry is all of the state TimerHeap maintains about a
+// timer. Because even repeating timers are only scheduled once (for
+// the next time they're fired) as a result there's only one entry for
+// a timer. For this reason TimerHeapEntry is stored inline as part of
+// the TimerBase.
+class TimerHeapEntry {
+ WTF_MAKE_NONCOPYABLE(TimerHeapEntry);
+public:
+ explicit TimerHeapEntry(TimerHeap*);
+ virtual ~TimerHeapEntry();
+
+ // FIXME: TimerBase uses setValue(0) to mean "not scheduled" but
+ // it may be simpler to make this explicit.
+ double value() const { return m_value; }
+ void setValue(TimerBase&, double newValue);
+
+ bool inHeap() const { return m_state & TimerHeapEntryInHeap; }
+
+private:
+ friend class TimerHeap;
+ friend class TimerHeapLessThanFunction;
+ friend class TimerHeapReference;
+
+ // The heap this entry is in when the timer is scheduled. There's
+ // one timer heap per thread, and timers don't jump threads, so
+ // this is fixed for the life of the timer.
+ TimerHeap* m_owner;
+
+ enum State {
+ TimerHeapEntryNotInHeap,
+ TimerHeapEntryInHeap,
+ TimerHeapEntryInHeap_ForcedMinimumForPopping = 3
+ };
+ State m_state;
+
+ // The next fire time. The timer heap doesn't particularly care
+ // that this is a time; it's just part of the (m_value,
+ // m_heapInsertionOrder) key in the min-heap.
+ double m_value;
+
+ // This is assigned from an incrementing counter. When comparing
+ // entries which have the same m_value, the comparison falls back
+ // to m_heapInsertionOrder which means timers scheduled for the
+ // same time will always fire in the order that they were
+ // scheduled in.
+ size_t m_heapInsertionOrder;
+
+ // If the timer is in the heap, the position of the timer in the
+ // heap.
+ size_t m_heapIndex;
+};
+
+} // namespace blink
+
+#endif // TimerHeapEntry_h
« no previous file with comments | « Source/platform/TimerHeap.cpp ('k') | Source/platform/TimerHeapEntry.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698