Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: Source/platform/Timer.h

Issue 956333002: Refactor TimeBase to post tasks. Workers to use real Idle tasks. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Simplify now the quiescence is handled in chromium Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
72 static void fireTimersInNestedEventLoop();
73 71
74 private: 72 private:
75 virtual void fired() = 0; 73 virtual void fired() = 0;
76 74
77 virtual double alignedFireTime(double fireTime) const { return fireTime; } 75 virtual double alignedFireTime(double fireTime) const { return fireTime; }
78 76
79 void checkConsistency() const; 77 void setNextFireTime(double now, double delay);
80 void checkHeapIndex() const;
81 78
82 void setNextFireTime(double); 79 void runInternal();
83 80
84 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 shtdown).
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);
85 87
86 bool hasValidHeapPosition() const; 88 public:
87 void updateHeapIfNeeded(double oldTime); 89 explicit CancellableTimerTask(TimerBase* timer) : m_timer(timer) { }
88 90
89 void heapDecreaseKey(); 91 virtual ~CancellableTimerTask() { }
90 void heapDelete();
91 void heapDeleteMin();
92 void heapIncreaseKey();
93 void heapInsert();
94 void heapPop();
95 void heapPopMin();
96 92
97 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 };
98 103
99 double m_nextFireTime; // 0 if inactive 104 double m_nextFireTime; // 0 if inactive
100 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment interval 105 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment interval
101 double m_repeatInterval; // 0 if not repeating 106 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; 107 WebTraceLocation m_location;
108 CancellableTimerTask* m_cancellableTimerTask; // NOT OWNED
106 109
107 #if ENABLE(ASSERT) 110 #if ENABLE(ASSERT)
108 ThreadIdentifier m_thread; 111 ThreadIdentifier m_thread;
109 #endif 112 #endif
110 113
111 friend class ThreadTimers; 114 friend class ThreadTimers;
112 friend class TimerHeapLessThanFunction; 115 friend class TimerHeapLessThanFunction;
113 friend class TimerHeapReference; 116 friend class TimerHeapReference;
114 }; 117 };
115 118
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // This raw pointer is safe as long as Timer<X> is held by the X itself (Tha t's the case 154 // 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). 155 // in the current code base).
153 GC_PLUGIN_IGNORE("363031") 156 GC_PLUGIN_IGNORE("363031")
154 TimerFiredClass* m_object; 157 TimerFiredClass* m_object;
155 TimerFiredFunction m_function; 158 TimerFiredFunction m_function;
156 }; 159 };
157 160
158 inline bool TimerBase::isActive() const 161 inline bool TimerBase::isActive() const
159 { 162 {
160 ASSERT(m_thread == currentThread()); 163 ASSERT(m_thread == currentThread());
161 return m_nextFireTime; 164 return m_cancellableTimerTask;
162 } 165 }
163 166
164 } 167 }
165 168
166 #endif 169 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698