Chromium Code Reviews| Index: Source/platform/Timer.h |
| diff --git a/Source/platform/Timer.h b/Source/platform/Timer.h |
| index 1c402406c2c2001465545fee611004974dfe69ae..4483e2ded0f8c07cda5926d2fa36ba11a73b7bc0 100644 |
| --- a/Source/platform/Timer.h |
| +++ b/Source/platform/Timer.h |
| @@ -63,11 +63,11 @@ public: |
| double repeatInterval() const { return m_repeatInterval; } |
| void augmentRepeatInterval(double delta) { |
| - setNextFireTime(m_nextFireTime + delta); |
| m_repeatInterval += delta; |
| + setNextFireTime(monotonicallyIncreasingTime(), m_repeatInterval); |
| } |
| - void didChangeAlignmentInterval(); |
| + void didChangeAlignmentInterval(double now); |
| static void fireTimersInNestedEventLoop(); |
| @@ -76,33 +76,38 @@ private: |
| virtual double alignedFireTime(double fireTime) const { return fireTime; } |
| - void checkConsistency() const; |
| - void checkHeapIndex() const; |
| + void setNextFireTime(double now, double delay); |
| - void setNextFireTime(double); |
| + void runInternal(); |
| - bool inHeap() const { return m_heapIndex != -1; } |
| + // 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
|
| + // CancellableTaskFactory::CancellableTask does some memory access. Normally that's fine |
| + // but some of the unit tests leave don't shutdown cleanly, leaving dangling tasks pointing |
| + // to deleted memory, which cause CancellableTaskFactory::CancellableTask's destructor to segfault. |
| + class CancellableTimerTask : public WebThread::Task { |
| + WTF_MAKE_NONCOPYABLE(CancellableTimerTask); |
| - bool hasValidHeapPosition() const; |
| - void updateHeapIfNeeded(double oldTime); |
| + public: |
| + explicit CancellableTimerTask(TimerBase* timer) : m_timer(timer) { } |
| - void heapDecreaseKey(); |
| - void heapDelete(); |
| - void heapDeleteMin(); |
| - void heapIncreaseKey(); |
| - void heapInsert(); |
| - void heapPop(); |
| - void heapPopMin(); |
| + virtual ~CancellableTimerTask() { } |
| - Vector<TimerBase*>& timerHeap() const { ASSERT(m_cachedThreadGlobalTimerHeap); return *m_cachedThreadGlobalTimerHeap; } |
| + void run() override; |
| + |
| + void cancel() |
| + { |
| + m_timer = nullptr; |
| + } |
| + |
| + private: |
| + TimerBase* m_timer; // NOT OWNED |
| + }; |
| double m_nextFireTime; // 0 if inactive |
| double m_unalignedNextFireTime; // m_nextFireTime not considering alignment interval |
| double m_repeatInterval; // 0 if not repeating |
| - int m_heapIndex; // -1 if not in heap |
| - unsigned m_heapInsertionOrder; // Used to keep order among equal-fire-time timers |
| - Vector<TimerBase*>* m_cachedThreadGlobalTimerHeap; |
| WebTraceLocation m_location; |
| + CancellableTimerTask* m_cancellableTimerTask; // NOT OWNED |
| #if ENABLE(ASSERT) |
| ThreadIdentifier m_thread; |
| @@ -158,7 +163,7 @@ private: |
| inline bool TimerBase::isActive() const |
| { |
| ASSERT(m_thread == currentThread()); |
| - return m_nextFireTime; |
| + return m_cancellableTimerTask; |
| } |
| } |