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

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

Issue 959263002: WIP - not ready for review (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Decouple TimerHeap and ThreadTimers. 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 | Annotate | Revision Log
« no previous file with comments | « Source/platform/ThreadTimers.cpp ('k') | Source/platform/Timer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
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/TimerHeapEntry.h"
30 #include "platform/heap/Handle.h" 31 #include "platform/heap/Handle.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 35
36 namespace blink { 36 namespace blink {
37 37
38 // Time intervals are all in seconds. 38 // Time intervals are all in seconds.
39 39
40 class PLATFORM_EXPORT TimerBase { 40 class PLATFORM_EXPORT TimerBase {
41 WTF_MAKE_NONCOPYABLE(TimerBase); 41 WTF_MAKE_NONCOPYABLE(TimerBase);
42 public: 42 public:
43 TimerBase(); 43 TimerBase();
44 virtual ~TimerBase(); 44 virtual ~TimerBase();
45 45
46 static void fireTimersInNestedEventLoop();
47
46 void start(double nextFireInterval, double repeatInterval, const WebTraceLoc ation&); 48 void start(double nextFireInterval, double repeatInterval, const WebTraceLoc ation&);
47
48 void startRepeating(double repeatInterval, const WebTraceLocation& caller) 49 void startRepeating(double repeatInterval, const WebTraceLocation& caller)
49 { 50 {
50 start(repeatInterval, repeatInterval, caller); 51 start(repeatInterval, repeatInterval, caller);
51 } 52 }
52 void startOneShot(double interval, const WebTraceLocation& caller) 53 void startOneShot(double interval, const WebTraceLocation& caller)
53 { 54 {
54 start(interval, 0, caller); 55 start(interval, 0, caller);
55 } 56 }
57 void stop();
56 58
57 void stop();
58 bool isActive() const; 59 bool isActive() const;
60
61 // FIXME: ThreadTimers dabbles with nextFireTime, but other timers
62 // (eg suspendableTimer) manipulate it too; why is it safe?
63 double nextFireTime() const { return m_heapEntry.value(); }
64 void setNextFireTime(double);
65
66 const TimerHeapEntry& heapEntry() const { return m_heapEntry; }
67 TimerHeapEntry& heapEntry() { return m_heapEntry; }
59 const WebTraceLocation& location() const { return m_location; } 68 const WebTraceLocation& location() const { return m_location; }
60
61 double nextFireInterval() const;
62 double nextUnalignedFireInterval() const;
63 double repeatInterval() const { return m_repeatInterval; } 69 double repeatInterval() const { return m_repeatInterval; }
64 70
71 // FIXME: This is only used by SMILTimeContainer; the API it
72 // really wants is something like "can I get this sooner by
73 // rescheduling it" or something like that.
74 double nextFireInterval() const;
75
76 // FIXME: This is only used by SuspendableTimer. Push it down to
77 // that type.
78 double nextUnalignedFireInterval() const;
79
80 // FIXME: This is only used by DOMTimer. Push it down to that type.
81 void didChangeAlignmentInterval();
82
83 // FIXME: This is only used by DOMTimer. Push it down to that type.
65 void augmentRepeatInterval(double delta) { 84 void augmentRepeatInterval(double delta) {
66 setNextFireTime(m_nextFireTime + delta); 85 setNextFireTime(nextFireTime() + delta);
67 m_repeatInterval += delta; 86 m_repeatInterval += delta;
68 } 87 }
69 88
70 void didChangeAlignmentInterval(); 89 // Used by ThreadTimers
71 90 virtual void fired() = 0;
72 static void fireTimersInNestedEventLoop();
73 91
74 private: 92 private:
75 virtual void fired() = 0;
76
77 virtual double alignedFireTime(double fireTime) const { return fireTime; } 93 virtual double alignedFireTime(double fireTime) const { return fireTime; }
78 94
79 void checkConsistency() const;
80 void checkHeapIndex() const;
81
82 void setNextFireTime(double);
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
100 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment interval 95 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment interval
101 double m_repeatInterval; // 0 if not repeating 96 double m_repeatInterval; // 0 if not repeating
102 int m_heapIndex; // -1 if not in heap 97 TimerHeapEntry m_heapEntry;
103 unsigned m_heapInsertionOrder; // Used to keep order among equal-fire-time t imers
104 Vector<TimerBase*>* m_cachedThreadGlobalTimerHeap;
105 WebTraceLocation m_location; 98 WebTraceLocation m_location;
106 99
107 #if ENABLE(ASSERT) 100 #if ENABLE(ASSERT)
108 ThreadIdentifier m_thread; 101 ThreadIdentifier m_thread;
109 #endif 102 #endif
110
111 friend class ThreadTimers;
112 friend class TimerHeapLessThanFunction;
113 friend class TimerHeapReference;
114 }; 103 };
115 104
116 template<typename T, bool = IsGarbageCollectedType<T>::value> 105 template<typename T, bool = IsGarbageCollectedType<T>::value>
117 class TimerIsObjectAliveTrait { 106 class TimerIsObjectAliveTrait {
118 public: 107 public:
119 static bool isAlive(T*) { return true; } 108 static bool isAlive(T*) { return true; }
120 }; 109 };
121 110
122 template<typename T> 111 template<typename T>
123 class TimerIsObjectAliveTrait<T, true> { 112 class TimerIsObjectAliveTrait<T, true> {
(...skipping 27 matching lines...) Expand all
151 // This raw pointer is safe as long as Timer<X> is held by the X itself (Tha t's the case 140 // 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). 141 // in the current code base).
153 GC_PLUGIN_IGNORE("363031") 142 GC_PLUGIN_IGNORE("363031")
154 TimerFiredClass* m_object; 143 TimerFiredClass* m_object;
155 TimerFiredFunction m_function; 144 TimerFiredFunction m_function;
156 }; 145 };
157 146
158 inline bool TimerBase::isActive() const 147 inline bool TimerBase::isActive() const
159 { 148 {
160 ASSERT(m_thread == currentThread()); 149 ASSERT(m_thread == currentThread());
161 return m_nextFireTime; 150 return nextFireTime();
162 } 151 }
163 152
164 } 153 }
165 154
166 #endif 155 #endif
OLDNEW
« no previous file with comments | « Source/platform/ThreadTimers.cpp ('k') | Source/platform/Timer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698