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

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

Issue 1211543004: Revert "Lazily constructed bespoke cancellable timer task. This is" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 | « no previous file | 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
(...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/AddressSanitizer.h" 33 #include "wtf/AddressSanitizer.h"
33 #include "wtf/Noncopyable.h" 34 #include "wtf/Noncopyable.h"
34 #include "wtf/Threading.h" 35 #include "wtf/Threading.h"
35 #include "wtf/Vector.h" 36 #include "wtf/Vector.h"
36 37
37 namespace blink { 38 namespace blink {
38 39
39 // Time intervals are all in seconds. 40 // Time intervals are all in seconds.
40 41
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 private: 80 private:
80 virtual void fired() = 0; 81 virtual void fired() = 0;
81 82
82 NO_LAZY_SWEEP_SANITIZE_ADDRESS 83 NO_LAZY_SWEEP_SANITIZE_ADDRESS
83 virtual bool canFire() const { return true; } 84 virtual bool canFire() const { return true; }
84 85
85 virtual double alignedFireTime(double fireTime) const { return fireTime; } 86 virtual double alignedFireTime(double fireTime) const { return fireTime; }
86 87
87 void setNextFireTime(double now, double delay); 88 void setNextFireTime(double now, double delay);
88 89
89 void runInternal(); 90 void run();
90
91 class CancellableTimerTask final : public WebThread::Task {
92 WTF_MAKE_NONCOPYABLE(CancellableTimerTask);
93 public:
94 explicit CancellableTimerTask(TimerBase* timer) : m_timer(timer) { }
95
96 ~CancellableTimerTask() override { }
97
98 void run() override
99 {
100 if (m_timer) {
101 m_timer->m_cancellableTimerTask = nullptr;
102 m_timer->runInternal();
103 }
104 }
105
106 void cancel()
107 {
108 m_timer = nullptr;
109 }
110
111 private:
112 TimerBase* m_timer; // NOT OWNED
113 };
114 91
115 double m_nextFireTime; // 0 if inactive 92 double m_nextFireTime; // 0 if inactive
116 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment interval 93 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment interval
117 double m_repeatInterval; // 0 if not repeating 94 double m_repeatInterval; // 0 if not repeating
118 WebTraceLocation m_location; 95 WebTraceLocation m_location;
119 CancellableTimerTask* m_cancellableTimerTask; // NOT OWNED 96 CancellableTaskFactory m_cancellableTaskFactory;
120 WebScheduler* m_webScheduler; // Not owned. 97 WebScheduler* m_webScheduler; // Not owned.
121 98
122 #if ENABLE(ASSERT) 99 #if ENABLE(ASSERT)
123 ThreadIdentifier m_thread; 100 ThreadIdentifier m_thread;
124 #endif 101 #endif
125 102
126 friend class ThreadTimers; 103 friend class ThreadTimers;
127 friend class TimerHeapLessThanFunction; 104 friend class TimerHeapLessThanFunction;
128 friend class TimerHeapReference; 105 friend class TimerHeapReference;
129 }; 106 };
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // in the current code base). 155 // in the current code base).
179 GC_PLUGIN_IGNORE("363031") 156 GC_PLUGIN_IGNORE("363031")
180 TimerFiredClass* m_object; 157 TimerFiredClass* m_object;
181 TimerFiredFunction m_function; 158 TimerFiredFunction m_function;
182 }; 159 };
183 160
184 NO_LAZY_SWEEP_SANITIZE_ADDRESS 161 NO_LAZY_SWEEP_SANITIZE_ADDRESS
185 inline bool TimerBase::isActive() const 162 inline bool TimerBase::isActive() const
186 { 163 {
187 ASSERT(m_thread == currentThread()); 164 ASSERT(m_thread == currentThread());
188 return m_cancellableTimerTask; 165 return m_cancellableTaskFactory.isPending();
189 } 166 }
190 167
191 } // namespace blink 168 } // namespace blink
192 169
193 #endif // Timer_h 170 #endif // Timer_h
OLDNEW
« no previous file with comments | « no previous file | Source/platform/Timer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698