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 static void fireTimersInNestedEventLoop(); | 72 static void fireTimersInNestedEventLoop(); |
73 | 73 |
74 private: | 74 private: |
75 virtual void fired() = 0; | 75 virtual void fired() = 0; |
76 | 76 |
77 virtual double alignedFireTime(double fireTime) const { return fireTime; } | 77 virtual double alignedFireTime(double fireTime) const { return fireTime; } |
78 | 78 |
79 void checkConsistency() const; | 79 void setNextFireTime(double now, double delay); |
80 void checkHeapIndex() const; | |
81 | 80 |
82 void setNextFireTime(double); | 81 void runInternal(); |
83 | 82 |
84 bool inHeap() const { return m_heapIndex != -1; } | 83 // NOTE we can't use CancellableTaskFactory here, because the destructor of |
Sami
2015/04/09 10:52:29
"Some memory access" sounds a little vague. IIRC o
alex clarke (OOO till 29th)
2015/04/10 15:29:40
It was with the unit tests. Clarified the comment
| |
84 // CancellableTaskFactory::CancellableTask does some memory access. Normall y that's fine | |
85 // but some of the unit tests leave don't shutdown cleanly, leaving dangling tasks pointing | |
86 // to deleted memory, which cause CancellableTaskFactory::CancellableTask's destructor to segfault. | |
87 class CancellableTimerTask : public WebThread::Task { | |
88 WTF_MAKE_NONCOPYABLE(CancellableTimerTask); | |
85 | 89 |
86 bool hasValidHeapPosition() const; | 90 public: |
87 void updateHeapIfNeeded(double oldTime); | 91 explicit CancellableTimerTask(TimerBase* timer) : m_timer(timer) { } |
88 | 92 |
89 void heapDecreaseKey(); | 93 virtual ~CancellableTimerTask() { } |
90 void heapDelete(); | |
91 void heapDeleteMin(); | |
92 void heapIncreaseKey(); | |
93 void heapInsert(); | |
94 void heapPop(); | |
95 void heapPopMin(); | |
96 | 94 |
97 Vector<TimerBase*>& timerHeap() const { ASSERT(m_cachedThreadGlobalTimerHeap ); return *m_cachedThreadGlobalTimerHeap; } | 95 void run() override; |
96 | |
97 void cancel() | |
98 { | |
99 m_timer = nullptr; | |
100 } | |
101 | |
102 private: | |
103 TimerBase* m_timer; // NOT OWNED | |
104 }; | |
98 | 105 |
99 double m_nextFireTime; // 0 if inactive | 106 double m_nextFireTime; // 0 if inactive |
100 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment interval | 107 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment interval |
101 double m_repeatInterval; // 0 if not repeating | 108 double m_repeatInterval; // 0 if not repeating |
102 int m_heapIndex; // -1 if not in heap | |
103 unsigned m_heapInsertionOrder; // Used to keep order among equal-fire-time t imers | |
104 Vector<TimerBase*>* m_cachedThreadGlobalTimerHeap; | |
105 WebTraceLocation m_location; | 109 WebTraceLocation m_location; |
110 CancellableTimerTask* m_cancellableTimerTask; // NOT OWNED | |
106 | 111 |
107 #if ENABLE(ASSERT) | 112 #if ENABLE(ASSERT) |
108 ThreadIdentifier m_thread; | 113 ThreadIdentifier m_thread; |
109 #endif | 114 #endif |
110 | 115 |
111 friend class ThreadTimers; | 116 friend class ThreadTimers; |
112 friend class TimerHeapLessThanFunction; | 117 friend class TimerHeapLessThanFunction; |
113 friend class TimerHeapReference; | 118 friend class TimerHeapReference; |
114 }; | 119 }; |
115 | 120 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 // 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 |
152 // in the current code base). | 157 // in the current code base). |
153 GC_PLUGIN_IGNORE("363031") | 158 GC_PLUGIN_IGNORE("363031") |
154 TimerFiredClass* m_object; | 159 TimerFiredClass* m_object; |
155 TimerFiredFunction m_function; | 160 TimerFiredFunction m_function; |
156 }; | 161 }; |
157 | 162 |
158 inline bool TimerBase::isActive() const | 163 inline bool TimerBase::isActive() const |
159 { | 164 { |
160 ASSERT(m_thread == currentThread()); | 165 ASSERT(m_thread == currentThread()); |
161 return m_nextFireTime; | 166 return m_cancellableTimerTask; |
162 } | 167 } |
163 | 168 |
164 } | 169 } |
165 | 170 |
166 #endif | 171 #endif |
OLD | NEW |