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

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

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