Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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" | |
| 32 #include "public/platform/WebTraceLocation.h" | 31 #include "public/platform/WebTraceLocation.h" |
| 33 #include "wtf/AddressSanitizer.h" | 32 #include "wtf/AddressSanitizer.h" |
| 34 #include "wtf/Noncopyable.h" | 33 #include "wtf/Noncopyable.h" |
| 35 #include "wtf/Threading.h" | 34 #include "wtf/Threading.h" |
| 36 #include "wtf/Vector.h" | 35 #include "wtf/Vector.h" |
| 37 | 36 |
| 38 namespace blink { | 37 namespace blink { |
| 39 | 38 |
| 40 // Time intervals are all in seconds. | 39 // Time intervals are all in seconds. |
| 41 | 40 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 65 double repeatInterval() const { return m_repeatInterval; } | 64 double repeatInterval() const { return m_repeatInterval; } |
| 66 | 65 |
| 67 void augmentRepeatInterval(double delta) { | 66 void augmentRepeatInterval(double delta) { |
| 68 double now = monotonicallyIncreasingTime(); | 67 double now = monotonicallyIncreasingTime(); |
| 69 setNextFireTime(now, m_nextFireTime - now + delta); | 68 setNextFireTime(now, m_nextFireTime - now + delta); |
| 70 m_repeatInterval += delta; | 69 m_repeatInterval += delta; |
| 71 } | 70 } |
| 72 | 71 |
| 73 void didChangeAlignmentInterval(double now); | 72 void didChangeAlignmentInterval(double now); |
| 74 | 73 |
| 75 #if defined(ADDRESS_SANITIZER) | |
| 76 protected: | |
| 77 CancellableTaskFactory& cancellableTaskFactory() { return m_cancellableTaskF actory; } | |
| 78 #endif | |
| 79 | |
| 80 private: | 74 private: |
| 81 virtual void fired() = 0; | 75 virtual void fired() = 0; |
| 82 | 76 |
| 83 NO_LAZY_SWEEP_SANITIZE_ADDRESS | 77 NO_LAZY_SWEEP_SANITIZE_ADDRESS |
| 84 virtual bool canFire() const { return true; } | 78 virtual bool canFire() const { return true; } |
| 85 | 79 |
| 86 virtual double alignedFireTime(double fireTime) const { return fireTime; } | 80 virtual double alignedFireTime(double fireTime) const { return fireTime; } |
| 87 | 81 |
| 88 void setNextFireTime(double now, double delay); | 82 void setNextFireTime(double now, double delay); |
| 89 | 83 |
| 90 void run(); | 84 void runInternal(); |
| 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 { } | |
|
sof
2015/06/26 06:45:06
I guess this needs to clear out m_timer's back ref
| |
| 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 }; | |
| 91 | 109 |
| 92 double m_nextFireTime; // 0 if inactive | 110 double m_nextFireTime; // 0 if inactive |
| 93 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment interval | 111 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment interval |
| 94 double m_repeatInterval; // 0 if not repeating | 112 double m_repeatInterval; // 0 if not repeating |
| 95 WebTraceLocation m_location; | 113 WebTraceLocation m_location; |
| 96 CancellableTaskFactory m_cancellableTaskFactory; | 114 CancellableTimerTask* m_cancellableTimerTask; // NOT OWNED |
| 97 WebScheduler* m_webScheduler; // Not owned. | 115 WebScheduler* m_webScheduler; // Not owned. |
| 98 | 116 |
| 99 #if ENABLE(ASSERT) | 117 #if ENABLE(ASSERT) |
| 100 ThreadIdentifier m_thread; | 118 ThreadIdentifier m_thread; |
| 101 #endif | 119 #endif |
| 102 | 120 |
| 103 friend class ThreadTimers; | 121 friend class ThreadTimers; |
| 104 friend class TimerHeapLessThanFunction; | 122 friend class TimerHeapLessThanFunction; |
| 105 friend class TimerHeapReference; | 123 friend class TimerHeapReference; |
| 106 }; | 124 }; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 121 }; | 139 }; |
| 122 | 140 |
| 123 template <typename TimerFiredClass> | 141 template <typename TimerFiredClass> |
| 124 class Timer : public TimerBase { | 142 class Timer : public TimerBase { |
| 125 public: | 143 public: |
| 126 typedef void (TimerFiredClass::*TimerFiredFunction)(Timer*); | 144 typedef void (TimerFiredClass::*TimerFiredFunction)(Timer*); |
| 127 | 145 |
| 128 Timer(TimerFiredClass* o, TimerFiredFunction f) | 146 Timer(TimerFiredClass* o, TimerFiredFunction f) |
| 129 : m_object(o), m_function(f) | 147 : m_object(o), m_function(f) |
| 130 { | 148 { |
| 131 #if ENABLE(LAZY_SWEEPING) && defined(ADDRESS_SANITIZER) | |
|
sof
2015/06/25 14:03:42
Looks like not replacing this with an alternative
| |
| 132 if (IsGarbageCollectedType<TimerFiredClass>::value) | |
| 133 cancellableTaskFactory().setUnpoisonBeforeUpdate(); | |
| 134 #endif | |
| 135 } | 149 } |
| 136 | 150 |
| 137 protected: | 151 protected: |
| 138 virtual void fired() override | 152 virtual void fired() override |
| 139 { | 153 { |
| 140 (m_object->*m_function)(this); | 154 (m_object->*m_function)(this); |
| 141 } | 155 } |
| 142 | 156 |
| 143 NO_LAZY_SWEEP_SANITIZE_ADDRESS | 157 NO_LAZY_SWEEP_SANITIZE_ADDRESS |
| 144 virtual bool canFire() const override | 158 virtual bool canFire() const override |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 155 // in the current code base). | 169 // in the current code base). |
| 156 GC_PLUGIN_IGNORE("363031") | 170 GC_PLUGIN_IGNORE("363031") |
| 157 TimerFiredClass* m_object; | 171 TimerFiredClass* m_object; |
| 158 TimerFiredFunction m_function; | 172 TimerFiredFunction m_function; |
| 159 }; | 173 }; |
| 160 | 174 |
| 161 NO_LAZY_SWEEP_SANITIZE_ADDRESS | 175 NO_LAZY_SWEEP_SANITIZE_ADDRESS |
| 162 inline bool TimerBase::isActive() const | 176 inline bool TimerBase::isActive() const |
| 163 { | 177 { |
| 164 ASSERT(m_thread == currentThread()); | 178 ASSERT(m_thread == currentThread()); |
| 165 return m_cancellableTaskFactory.isPending(); | 179 return m_cancellableTimerTask; |
| 166 } | 180 } |
| 167 | 181 |
| 168 } // namespace blink | 182 } // namespace blink |
| 169 | 183 |
| 170 #endif // Timer_h | 184 #endif // Timer_h |
| OLD | NEW |