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

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: Fix a bunch of stuff Created 5 years, 9 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 10 matching lines...) Expand all
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #ifndef Timer_h 26 #ifndef Timer_h
27 #define Timer_h 27 #define Timer_h
28 28
29 #include "platform/PlatformExport.h" 29 #include "platform/PlatformExport.h"
30 #include "platform/heap/Handle.h" 30 #include "platform/heap/Handle.h"
31 #include "platform/scheduler/CancellableTaskFactory.h"
31 #include "public/platform/WebTraceLocation.h" 32 #include "public/platform/WebTraceLocation.h"
32 #include "wtf/Noncopyable.h" 33 #include "wtf/Noncopyable.h"
33 #include "wtf/Threading.h" 34 #include "wtf/Threading.h"
34 #include "wtf/Vector.h" 35 #include "wtf/Vector.h"
35 36
36 namespace blink { 37 namespace blink {
37 38
38 // Time intervals are all in seconds. 39 // Time intervals are all in seconds.
39 40
40 class PLATFORM_EXPORT TimerBase { 41 class PLATFORM_EXPORT TimerBase {
(...skipping 15 matching lines...) Expand all
56 57
57 void stop(); 58 void stop();
58 bool isActive() const; 59 bool isActive() const;
59 const WebTraceLocation& location() const { return m_location; } 60 const WebTraceLocation& location() const { return m_location; }
60 61
61 double nextFireInterval() const; 62 double nextFireInterval() const;
62 double nextUnalignedFireInterval() const; 63 double nextUnalignedFireInterval() const;
63 double repeatInterval() const { return m_repeatInterval; } 64 double repeatInterval() const { return m_repeatInterval; }
64 65
65 void augmentRepeatInterval(double delta) { 66 void augmentRepeatInterval(double delta) {
66 setNextFireTime(m_nextFireTime + delta);
67 m_repeatInterval += delta; 67 m_repeatInterval += delta;
68 setNextFireTime(monotonicallyIncreasingTime(), m_repeatInterval);
68 } 69 }
69 70
70 void didChangeAlignmentInterval(); 71 void didChangeAlignmentInterval(double now);
71 72
72 static void fireTimersInNestedEventLoop(); 73 static void fireTimersInNestedEventLoop();
73 74
74 private: 75 private:
75 virtual void fired() = 0; 76 virtual void fired() = 0;
76 77
78 void firedInternal();
79
77 virtual double alignedFireTime(double fireTime) const { return fireTime; } 80 virtual double alignedFireTime(double fireTime) const { return fireTime; }
78 81
79 void checkConsistency() const; 82 void setNextFireTime(double now, double delay);
80 void checkHeapIndex() const;
81 83
82 void setNextFireTime(double); 84 CancellableTaskFactory m_taskFactory;
83
84 bool inHeap() const { return m_heapIndex != -1; }
85
86 bool hasValidHeapPosition() const;
87 void updateHeapIfNeeded(double oldTime);
88
89 void heapDecreaseKey();
90 void heapDelete();
91 void heapDeleteMin();
92 void heapIncreaseKey();
93 void heapInsert();
94 void heapPop();
95 void heapPopMin();
96
97 Vector<TimerBase*>& timerHeap() const { ASSERT(m_cachedThreadGlobalTimerHeap ); return *m_cachedThreadGlobalTimerHeap; }
98
99 double m_nextFireTime; // 0 if inactive 85 double m_nextFireTime; // 0 if inactive
100 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment interval 86 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment interval
101 double m_repeatInterval; // 0 if not repeating 87 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; 88 WebTraceLocation m_location;
106 89
107 #if ENABLE(ASSERT) 90 #if ENABLE(ASSERT)
108 ThreadIdentifier m_thread; 91 ThreadIdentifier m_thread;
109 #endif 92 #endif
110 93
111 friend class ThreadTimers; 94 friend class ThreadTimers;
112 friend class TimerHeapLessThanFunction; 95 friend class TimerHeapLessThanFunction;
113 friend class TimerHeapReference; 96 friend class TimerHeapReference;
114 }; 97 };
(...skipping 36 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 134 // 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). 135 // in the current code base).
153 GC_PLUGIN_IGNORE("363031") 136 GC_PLUGIN_IGNORE("363031")
154 TimerFiredClass* m_object; 137 TimerFiredClass* m_object;
155 TimerFiredFunction m_function; 138 TimerFiredFunction m_function;
156 }; 139 };
157 140
158 inline bool TimerBase::isActive() const 141 inline bool TimerBase::isActive() const
159 { 142 {
160 ASSERT(m_thread == currentThread()); 143 ASSERT(m_thread == currentThread());
161 return m_nextFireTime; 144 return m_taskFactory.isPending();
162 } 145 }
163 146
164 } 147 }
165 148
166 #endif 149 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698