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 // NOTE we can't use CancellableTaskFactory here, because the destructor of |
| 82 // CancellableTaskFactory::CancellableTask does some memory access (causes v
arious tests to crash on shutdown). |
| 83 // Normally that's fine but some of the unit tests leave don't shutdown clea
nly, leaving dangling tasks |
| 84 // pointing to deleted memory, which cause CancellableTaskFactory::Cancellab
leTask's destructor to segfault. |
| 85 class CancellableTimerTask : public WebThread::Task { |
| 86 WTF_MAKE_NONCOPYABLE(CancellableTimerTask); |
83 | 87 |
84 bool hasValidHeapPosition() const; | 88 public: |
85 void updateHeapIfNeeded(double oldTime); | 89 explicit CancellableTimerTask(TimerBase* timer) : m_timer(timer) { } |
86 | 90 |
87 void heapDecreaseKey(); | 91 virtual ~CancellableTimerTask() { } |
88 void heapDelete(); | |
89 void heapDeleteMin(); | |
90 void heapIncreaseKey(); | |
91 void heapInsert(); | |
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 // This raw pointer is safe as long as Timer<X> is held by the X itself (Tha
t's the case | 155 // This raw pointer is safe as long as Timer<X> is held by the X itself (Tha
t's the case |
150 // in the current code base). | 156 // in the current code base). |
151 GC_PLUGIN_IGNORE("363031") | 157 GC_PLUGIN_IGNORE("363031") |
152 TimerFiredClass* m_object; | 158 TimerFiredClass* m_object; |
153 TimerFiredFunction m_function; | 159 TimerFiredFunction m_function; |
154 }; | 160 }; |
155 | 161 |
156 inline bool TimerBase::isActive() const | 162 inline bool TimerBase::isActive() const |
157 { | 163 { |
158 ASSERT(m_thread == currentThread()); | 164 ASSERT(m_thread == currentThread()); |
159 return m_nextFireTime; | 165 return m_cancellableTimerTask; |
160 } | 166 } |
161 | 167 |
162 } | 168 } |
163 | 169 |
164 #endif | 170 #endif |
OLD | NEW |