| 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 |
| 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/TraceLocation.h" |
| 30 #include "wtf/Noncopyable.h" | 31 #include "wtf/Noncopyable.h" |
| 31 #include "wtf/Threading.h" | 32 #include "wtf/Threading.h" |
| 32 #include "wtf/Vector.h" | 33 #include "wtf/Vector.h" |
| 33 | 34 |
| 34 namespace WebCore { | 35 namespace WebCore { |
| 35 | 36 |
| 36 // Time intervals are all in seconds. | 37 // Time intervals are all in seconds. |
| 37 | 38 |
| 38 class TimerHeapElement; | 39 class TimerHeapElement; |
| 39 | 40 |
| 40 class PLATFORM_EXPORT TimerBase { | 41 class PLATFORM_EXPORT TimerBase { |
| 41 WTF_MAKE_NONCOPYABLE(TimerBase); WTF_MAKE_FAST_ALLOCATED; | 42 WTF_MAKE_NONCOPYABLE(TimerBase); WTF_MAKE_FAST_ALLOCATED; |
| 42 public: | 43 public: |
| 43 TimerBase(); | 44 TimerBase(); |
| 44 virtual ~TimerBase(); | 45 virtual ~TimerBase(); |
| 45 | 46 |
| 46 void start(double nextFireInterval, double repeatInterval); | 47 void start(double nextFireInterval, double repeatInterval, const TraceLocati
on&); |
| 47 | 48 |
| 48 void startRepeating(double repeatInterval) { start(repeatInterval, repeatInt
erval); } | 49 void startRepeating(double repeatInterval, const TraceLocation& caller) |
| 49 void startOneShot(double interval) { start(interval, 0); } | 50 { |
| 51 start(repeatInterval, repeatInterval, caller); |
| 52 } |
| 53 void startOneShot(double interval, const TraceLocation& caller) |
| 54 { |
| 55 start(interval, 0, caller); |
| 56 } |
| 50 | 57 |
| 51 void stop(); | 58 void stop(); |
| 52 bool isActive() const; | 59 bool isActive() const; |
| 60 const TraceLocation& location() const { return m_location; } |
| 53 | 61 |
| 54 double nextFireInterval() const; | 62 double nextFireInterval() const; |
| 55 double nextUnalignedFireInterval() const; | 63 double nextUnalignedFireInterval() const; |
| 56 double repeatInterval() const { return m_repeatInterval; } | 64 double repeatInterval() const { return m_repeatInterval; } |
| 57 | 65 |
| 58 void augmentRepeatInterval(double delta) { | 66 void augmentRepeatInterval(double delta) { |
| 59 setNextFireTime(m_nextFireTime + delta); | 67 setNextFireTime(m_nextFireTime + delta); |
| 60 m_repeatInterval += delta; | 68 m_repeatInterval += delta; |
| 61 } | 69 } |
| 62 | 70 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 88 void heapPopMin(); | 96 void heapPopMin(); |
| 89 | 97 |
| 90 Vector<TimerBase*>& timerHeap() const { ASSERT(m_cachedThreadGlobalTimerHeap
); return *m_cachedThreadGlobalTimerHeap; } | 98 Vector<TimerBase*>& timerHeap() const { ASSERT(m_cachedThreadGlobalTimerHeap
); return *m_cachedThreadGlobalTimerHeap; } |
| 91 | 99 |
| 92 double m_nextFireTime; // 0 if inactive | 100 double m_nextFireTime; // 0 if inactive |
| 93 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment
interval | 101 double m_unalignedNextFireTime; // m_nextFireTime not considering alignment
interval |
| 94 double m_repeatInterval; // 0 if not repeating | 102 double m_repeatInterval; // 0 if not repeating |
| 95 int m_heapIndex; // -1 if not in heap | 103 int m_heapIndex; // -1 if not in heap |
| 96 unsigned m_heapInsertionOrder; // Used to keep order among equal-fire-time t
imers | 104 unsigned m_heapInsertionOrder; // Used to keep order among equal-fire-time t
imers |
| 97 Vector<TimerBase*>* m_cachedThreadGlobalTimerHeap; | 105 Vector<TimerBase*>* m_cachedThreadGlobalTimerHeap; |
| 106 TraceLocation m_location; |
| 98 | 107 |
| 99 #ifndef NDEBUG | 108 #ifndef NDEBUG |
| 100 ThreadIdentifier m_thread; | 109 ThreadIdentifier m_thread; |
| 101 #endif | 110 #endif |
| 102 | 111 |
| 103 friend class ThreadTimers; | 112 friend class ThreadTimers; |
| 104 friend class TimerHeapLessThanFunction; | 113 friend class TimerHeapLessThanFunction; |
| 105 friend class TimerHeapReference; | 114 friend class TimerHeapReference; |
| 106 }; | 115 }; |
| 107 | 116 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 132 typedef void (TimerFiredClass::*TimerFiredFunction)(DeferrableOneShotTimer*)
; | 141 typedef void (TimerFiredClass::*TimerFiredFunction)(DeferrableOneShotTimer*)
; |
| 133 | 142 |
| 134 DeferrableOneShotTimer(TimerFiredClass* o, TimerFiredFunction f, double dela
y) | 143 DeferrableOneShotTimer(TimerFiredClass* o, TimerFiredFunction f, double dela
y) |
| 135 : m_object(o) | 144 : m_object(o) |
| 136 , m_function(f) | 145 , m_function(f) |
| 137 , m_delay(delay) | 146 , m_delay(delay) |
| 138 , m_shouldRestartWhenTimerFires(false) | 147 , m_shouldRestartWhenTimerFires(false) |
| 139 { | 148 { |
| 140 } | 149 } |
| 141 | 150 |
| 142 void restart() | 151 void restart(const TraceLocation& caller) |
| 143 { | 152 { |
| 144 // Setting this boolean is much more efficient than calling startOneShot | 153 // Setting this boolean is much more efficient than calling startOneShot |
| 145 // again, which might result in rescheduling the system timer which | 154 // again, which might result in rescheduling the system timer which |
| 146 // can be quite expensive. | 155 // can be quite expensive. |
| 147 | 156 |
| 148 if (isActive()) { | 157 if (isActive()) { |
| 149 m_shouldRestartWhenTimerFires = true; | 158 m_shouldRestartWhenTimerFires = true; |
| 150 return; | 159 return; |
| 151 } | 160 } |
| 152 startOneShot(m_delay); | 161 startOneShot(m_delay, caller); |
| 153 } | 162 } |
| 154 | 163 |
| 155 using TimerBase::stop; | 164 using TimerBase::stop; |
| 156 using TimerBase::isActive; | 165 using TimerBase::isActive; |
| 157 | 166 |
| 158 private: | 167 private: |
| 159 virtual void fired() OVERRIDE | 168 virtual void fired() OVERRIDE |
| 160 { | 169 { |
| 161 if (m_shouldRestartWhenTimerFires) { | 170 if (m_shouldRestartWhenTimerFires) { |
| 162 m_shouldRestartWhenTimerFires = false; | 171 m_shouldRestartWhenTimerFires = false; |
| 163 startOneShot(m_delay); | 172 // FIXME: This should not be FROM_HERE. |
| 173 startOneShot(m_delay, FROM_HERE); |
| 164 return; | 174 return; |
| 165 } | 175 } |
| 166 | 176 |
| 167 (m_object->*m_function)(this); | 177 (m_object->*m_function)(this); |
| 168 } | 178 } |
| 169 | 179 |
| 170 TimerFiredClass* m_object; | 180 TimerFiredClass* m_object; |
| 171 TimerFiredFunction m_function; | 181 TimerFiredFunction m_function; |
| 172 | 182 |
| 173 double m_delay; | 183 double m_delay; |
| 174 bool m_shouldRestartWhenTimerFires; | 184 bool m_shouldRestartWhenTimerFires; |
| 175 }; | 185 }; |
| 176 | 186 |
| 177 } | 187 } |
| 178 | 188 |
| 179 #endif | 189 #endif |
| OLD | NEW |