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

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

Issue 1204333002: Revert of Lazily constructed bespoke cancellable timer task. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
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
« 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 23 matching lines...) Expand all
64 double repeatInterval() const { return m_repeatInterval; } 65 double repeatInterval() const { return m_repeatInterval; }
65 66
66 void augmentRepeatInterval(double delta) { 67 void augmentRepeatInterval(double delta) {
67 double now = monotonicallyIncreasingTime(); 68 double now = monotonicallyIncreasingTime();
68 setNextFireTime(now, m_nextFireTime - now + delta); 69 setNextFireTime(now, m_nextFireTime - now + delta);
69 m_repeatInterval += delta; 70 m_repeatInterval += delta;
70 } 71 }
71 72
72 void didChangeAlignmentInterval(double now); 73 void didChangeAlignmentInterval(double now);
73 74
75 #if defined(ADDRESS_SANITIZER)
76 protected:
77 CancellableTaskFactory& cancellableTaskFactory() { return m_cancellableTaskF actory; }
78 #endif
79
74 private: 80 private:
75 virtual void fired() = 0; 81 virtual void fired() = 0;
76 82
77 NO_LAZY_SWEEP_SANITIZE_ADDRESS 83 NO_LAZY_SWEEP_SANITIZE_ADDRESS
78 virtual bool canFire() const { return true; } 84 virtual bool canFire() const { return true; }
79 85
80 virtual double alignedFireTime(double fireTime) const { return fireTime; } 86 virtual double alignedFireTime(double fireTime) const { return fireTime; }
81 87
82 void setNextFireTime(double now, double delay); 88 void setNextFireTime(double now, double delay);
83 89
84 void runInternal(); 90 void run();
85
86 class CancellableTimerTask final : public WebThread::Task {
87 WTF_MAKE_NONCOPYABLE(CancellableTimerTask);
88 public:
89 explicit CancellableTimerTask(TimerBase* timer) : m_timer(timer) { }
90
91 ~CancellableTimerTask() override { }
92
93 void run() override
94 {
95 if (m_timer) {
96 m_timer->m_cancellableTimerTask = nullptr;
97 m_timer->runInternal();
98 }
99 }
100
101 void cancel()
102 {
103 m_timer = nullptr;
104 }
105
106 private:
107 TimerBase* m_timer; // NOT OWNED
108 };
109 91
110 double m_nextFireTime; // 0 if inactive 92 double m_nextFireTime; // 0 if inactive
111 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment interval 93 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment interval
112 double m_repeatInterval; // 0 if not repeating 94 double m_repeatInterval; // 0 if not repeating
113 WebTraceLocation m_location; 95 WebTraceLocation m_location;
114 CancellableTimerTask* m_cancellableTimerTask; // NOT OWNED 96 CancellableTaskFactory m_cancellableTaskFactory;
115 WebScheduler* m_webScheduler; // Not owned. 97 WebScheduler* m_webScheduler; // Not owned.
116 98
117 #if ENABLE(ASSERT) 99 #if ENABLE(ASSERT)
118 ThreadIdentifier m_thread; 100 ThreadIdentifier m_thread;
119 #endif 101 #endif
120 102
121 friend class ThreadTimers; 103 friend class ThreadTimers;
122 friend class TimerHeapLessThanFunction; 104 friend class TimerHeapLessThanFunction;
123 friend class TimerHeapReference; 105 friend class TimerHeapReference;
124 }; 106 };
(...skipping 14 matching lines...) Expand all
139 }; 121 };
140 122
141 template <typename TimerFiredClass> 123 template <typename TimerFiredClass>
142 class Timer : public TimerBase { 124 class Timer : public TimerBase {
143 public: 125 public:
144 typedef void (TimerFiredClass::*TimerFiredFunction)(Timer*); 126 typedef void (TimerFiredClass::*TimerFiredFunction)(Timer*);
145 127
146 Timer(TimerFiredClass* o, TimerFiredFunction f) 128 Timer(TimerFiredClass* o, TimerFiredFunction f)
147 : m_object(o), m_function(f) 129 : m_object(o), m_function(f)
148 { 130 {
131 #if ENABLE(LAZY_SWEEPING) && defined(ADDRESS_SANITIZER)
132 if (IsGarbageCollectedType<TimerFiredClass>::value)
133 cancellableTaskFactory().setUnpoisonBeforeUpdate();
134 #endif
149 } 135 }
150 136
151 protected: 137 protected:
152 virtual void fired() override 138 virtual void fired() override
153 { 139 {
154 (m_object->*m_function)(this); 140 (m_object->*m_function)(this);
155 } 141 }
156 142
157 NO_LAZY_SWEEP_SANITIZE_ADDRESS 143 NO_LAZY_SWEEP_SANITIZE_ADDRESS
158 virtual bool canFire() const override 144 virtual bool canFire() const override
(...skipping 10 matching lines...) Expand all
169 // in the current code base). 155 // in the current code base).
170 GC_PLUGIN_IGNORE("363031") 156 GC_PLUGIN_IGNORE("363031")
171 TimerFiredClass* m_object; 157 TimerFiredClass* m_object;
172 TimerFiredFunction m_function; 158 TimerFiredFunction m_function;
173 }; 159 };
174 160
175 NO_LAZY_SWEEP_SANITIZE_ADDRESS 161 NO_LAZY_SWEEP_SANITIZE_ADDRESS
176 inline bool TimerBase::isActive() const 162 inline bool TimerBase::isActive() const
177 { 163 {
178 ASSERT(m_thread == currentThread()); 164 ASSERT(m_thread == currentThread());
179 return m_cancellableTimerTask; 165 return m_cancellableTaskFactory.isPending();
180 } 166 }
181 167
182 } // namespace blink 168 } // namespace blink
183 169
184 #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