OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 void stop(); | 57 void stop(); |
58 bool isActive() const; | 58 bool isActive() const; |
59 const WebTraceLocation& location() const { return m_location; } | 59 const WebTraceLocation& location() const { return m_location; } |
60 | 60 |
61 double nextFireInterval() const; | 61 double nextFireInterval() const; |
62 double nextUnalignedFireInterval() const; | 62 double nextUnalignedFireInterval() const; |
63 double repeatInterval() const { return m_repeatInterval; } | 63 double repeatInterval() const { return m_repeatInterval; } |
64 | 64 |
65 void augmentRepeatInterval(double delta) { | 65 void augmentRepeatInterval(double delta) { |
66 setNextFireTime(m_nextFireTime + delta); | |
67 m_repeatInterval += delta; | 66 m_repeatInterval += delta; |
| 67 setNextFireTime(monotonicallyIncreasingTime(), m_repeatInterval); |
68 } | 68 } |
69 | 69 |
70 void didChangeAlignmentInterval(); | 70 void didChangeAlignmentInterval(double now); |
71 | 71 |
72 private: | 72 private: |
73 virtual void fired() = 0; | 73 virtual void fired() = 0; |
74 | 74 |
75 virtual double alignedFireTime(double fireTime) const { return fireTime; } | 75 virtual double alignedFireTime(double fireTime) const { return fireTime; } |
76 | 76 |
77 void checkConsistency() const; | 77 void setNextFireTime(double now, double delay); |
78 void checkHeapIndex() const; | |
79 | 78 |
80 void setNextFireTime(double); | 79 void runInternal(); |
81 | 80 |
82 bool inHeap() const { return m_heapIndex != -1; } | 81 class CancellableTimerTask : public WebThread::Task { |
| 82 WTF_MAKE_NONCOPYABLE(CancellableTimerTask); |
83 | 83 |
84 bool hasValidHeapPosition() const; | 84 public: |
85 void updateHeapIfNeeded(double oldTime); | 85 explicit CancellableTimerTask(TimerBase* timer) : m_timer(timer) { } |
86 | 86 |
87 void heapDecreaseKey(); | 87 virtual ~CancellableTimerTask() |
88 void heapDelete(); | 88 { |
89 void heapDeleteMin(); | 89 if (m_timer) |
90 void heapIncreaseKey(); | 90 m_timer->m_cancellableTimerTask = nullptr; |
91 void heapInsert(); | 91 } |
92 void heapPop(); | |
93 void heapPopMin(); | |
94 | 92 |
95 Vector<TimerBase*>& timerHeap() const { ASSERT(m_cachedThreadGlobalTimerHeap
); return *m_cachedThreadGlobalTimerHeap; } | 93 void run() override; |
| 94 |
| 95 void cancel() |
| 96 { |
| 97 m_timer = nullptr; |
| 98 } |
| 99 |
| 100 private: |
| 101 TimerBase* m_timer; // NOT OWNED |
| 102 }; |
96 | 103 |
97 double m_nextFireTime; // 0 if inactive | 104 double m_nextFireTime; // 0 if inactive |
98 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment
interval | 105 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment
interval |
99 double m_repeatInterval; // 0 if not repeating | 106 double m_repeatInterval; // 0 if not repeating |
100 int m_heapIndex; // -1 if not in heap | |
101 unsigned m_heapInsertionOrder; // Used to keep order among equal-fire-time t
imers | |
102 Vector<TimerBase*>* m_cachedThreadGlobalTimerHeap; | |
103 WebTraceLocation m_location; | 107 WebTraceLocation m_location; |
| 108 CancellableTimerTask* m_cancellableTimerTask; // NOT OWNED |
| 109 WebScheduler* m_webScheduler; // NOT OWNED |
104 | 110 |
105 #if ENABLE(ASSERT) | 111 #if ENABLE(ASSERT) |
106 ThreadIdentifier m_thread; | 112 ThreadIdentifier m_thread; |
107 #endif | 113 #endif |
108 | 114 |
109 friend class ThreadTimers; | 115 friend class ThreadTimers; |
110 friend class TimerHeapLessThanFunction; | 116 friend class TimerHeapLessThanFunction; |
111 friend class TimerHeapReference; | 117 friend class TimerHeapReference; |
112 }; | 118 }; |
113 | 119 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // This raw pointer is safe as long as Timer<X> is held by the X itself (Tha
t's the case | 156 // This raw pointer is safe as long as Timer<X> is held by the X itself (Tha
t's the case |
151 // in the current code base). | 157 // in the current code base). |
152 GC_PLUGIN_IGNORE("363031") | 158 GC_PLUGIN_IGNORE("363031") |
153 TimerFiredClass* m_object; | 159 TimerFiredClass* m_object; |
154 TimerFiredFunction m_function; | 160 TimerFiredFunction m_function; |
155 }; | 161 }; |
156 | 162 |
157 inline bool TimerBase::isActive() const | 163 inline bool TimerBase::isActive() const |
158 { | 164 { |
159 ASSERT(m_thread == currentThread()); | 165 ASSERT(m_thread == currentThread()); |
160 return m_nextFireTime; | 166 return m_cancellableTimerTask; |
161 } | 167 } |
162 | 168 |
163 } | 169 } |
164 | 170 |
165 #endif | 171 #endif |
OLD | NEW |