OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef TimerHeapEntry_h |
| 6 #define TimerHeapEntry_h |
| 7 |
| 8 #include "wtf/Noncopyable.h" |
| 9 #include <stddef.h> |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 class TimerBase; |
| 14 class TimerHeap; |
| 15 |
| 16 // TimerHeapEntry is all of the state TimerHeap maintains about a |
| 17 // timer. Because even repeating timers are only scheduled once (for |
| 18 // the next time they're fired) as a result there's only one entry for |
| 19 // a timer. For this reason TimerHeapEntry is stored inline as part of |
| 20 // the TimerBase. |
| 21 class TimerHeapEntry { |
| 22 WTF_MAKE_NONCOPYABLE(TimerHeapEntry); |
| 23 public: |
| 24 explicit TimerHeapEntry(TimerHeap*); |
| 25 virtual ~TimerHeapEntry(); |
| 26 |
| 27 // FIXME: TimerBase uses setValue(0) to mean "not scheduled" but |
| 28 // it may be simpler to make this explicit. |
| 29 double value() const { return m_value; } |
| 30 void setValue(TimerBase&, double newValue); |
| 31 |
| 32 bool inHeap() const { return m_state & TimerHeapEntryInHeap; } |
| 33 |
| 34 private: |
| 35 friend class TimerHeap; |
| 36 friend class TimerHeapLessThanFunction; |
| 37 friend class TimerHeapReference; |
| 38 |
| 39 // The heap this entry is in when the timer is scheduled. There's |
| 40 // one timer heap per thread, and timers don't jump threads, so |
| 41 // this is fixed for the life of the timer. |
| 42 TimerHeap* m_owner; |
| 43 |
| 44 enum State { |
| 45 TimerHeapEntryNotInHeap, |
| 46 TimerHeapEntryInHeap, |
| 47 TimerHeapEntryInHeap_ForcedMinimumForPopping = 3 |
| 48 }; |
| 49 State m_state; |
| 50 |
| 51 // The next fire time. The timer heap doesn't particularly care |
| 52 // that this is a time; it's just part of the (m_value, |
| 53 // m_heapInsertionOrder) key in the min-heap. |
| 54 double m_value; |
| 55 |
| 56 // This is assigned from an incrementing counter. When comparing |
| 57 // entries which have the same m_value, the comparison falls back |
| 58 // to m_heapInsertionOrder which means timers scheduled for the |
| 59 // same time will always fire in the order that they were |
| 60 // scheduled in. |
| 61 size_t m_heapInsertionOrder; |
| 62 |
| 63 // If the timer is in the heap, the position of the timer in the |
| 64 // heap. |
| 65 size_t m_heapIndex; |
| 66 }; |
| 67 |
| 68 } // namespace blink |
| 69 |
| 70 #endif // TimerHeapEntry_h |
OLD | NEW |