| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 99 #ifndef NDEBUG | 99 #ifndef NDEBUG | 
| 100     ThreadIdentifier m_thread; | 100     ThreadIdentifier m_thread; | 
| 101 #endif | 101 #endif | 
| 102 | 102 | 
| 103     friend class ThreadTimers; | 103     friend class ThreadTimers; | 
| 104     friend class TimerHeapLessThanFunction; | 104     friend class TimerHeapLessThanFunction; | 
| 105     friend class TimerHeapReference; | 105     friend class TimerHeapReference; | 
| 106 }; | 106 }; | 
| 107 | 107 | 
| 108 template <typename TimerFiredClass> | 108 template <typename TimerFiredClass> | 
| 109 class Timer : public TimerBase { | 109 class Timer FINAL : public TimerBase { | 
| 110 public: | 110 public: | 
| 111     typedef void (TimerFiredClass::*TimerFiredFunction)(Timer*); | 111     typedef void (TimerFiredClass::*TimerFiredFunction)(Timer*); | 
| 112 | 112 | 
| 113     Timer(TimerFiredClass* o, TimerFiredFunction f) | 113     Timer(TimerFiredClass* o, TimerFiredFunction f) | 
| 114         : m_object(o), m_function(f) { } | 114         : m_object(o), m_function(f) { } | 
| 115 | 115 | 
| 116 private: | 116 private: | 
| 117     virtual void fired() { (m_object->*m_function)(this); } | 117     virtual void fired() OVERRIDE { (m_object->*m_function)(this); } | 
| 118 | 118 | 
| 119     TimerFiredClass* m_object; | 119     TimerFiredClass* m_object; | 
| 120     TimerFiredFunction m_function; | 120     TimerFiredFunction m_function; | 
| 121 }; | 121 }; | 
| 122 | 122 | 
| 123 inline bool TimerBase::isActive() const | 123 inline bool TimerBase::isActive() const | 
| 124 { | 124 { | 
| 125     ASSERT(m_thread == currentThread()); | 125     ASSERT(m_thread == currentThread()); | 
| 126     return m_nextFireTime; | 126     return m_nextFireTime; | 
| 127 } | 127 } | 
| 128 | 128 | 
| 129 template <typename TimerFiredClass> | 129 template <typename TimerFiredClass> | 
| 130 class DeferrableOneShotTimer : private TimerBase { | 130 class DeferrableOneShotTimer FINAL : private TimerBase { | 
| 131 public: | 131 public: | 
| 132     typedef void (TimerFiredClass::*TimerFiredFunction)(DeferrableOneShotTimer*)
     ; | 132     typedef void (TimerFiredClass::*TimerFiredFunction)(DeferrableOneShotTimer*)
     ; | 
| 133 | 133 | 
| 134     DeferrableOneShotTimer(TimerFiredClass* o, TimerFiredFunction f, double dela
     y) | 134     DeferrableOneShotTimer(TimerFiredClass* o, TimerFiredFunction f, double dela
     y) | 
| 135         : m_object(o) | 135         : m_object(o) | 
| 136         , m_function(f) | 136         , m_function(f) | 
| 137         , m_delay(delay) | 137         , m_delay(delay) | 
| 138         , m_shouldRestartWhenTimerFires(false) | 138         , m_shouldRestartWhenTimerFires(false) | 
| 139     { | 139     { | 
| 140     } | 140     } | 
| 141 | 141 | 
| 142     void restart() | 142     void restart() | 
| 143     { | 143     { | 
| 144         // Setting this boolean is much more efficient than calling startOneShot | 144         // Setting this boolean is much more efficient than calling startOneShot | 
| 145         // again, which might result in rescheduling the system timer which | 145         // again, which might result in rescheduling the system timer which | 
| 146         // can be quite expensive. | 146         // can be quite expensive. | 
| 147 | 147 | 
| 148         if (isActive()) { | 148         if (isActive()) { | 
| 149             m_shouldRestartWhenTimerFires = true; | 149             m_shouldRestartWhenTimerFires = true; | 
| 150             return; | 150             return; | 
| 151         } | 151         } | 
| 152         startOneShot(m_delay); | 152         startOneShot(m_delay); | 
| 153     } | 153     } | 
| 154 | 154 | 
| 155     using TimerBase::stop; | 155     using TimerBase::stop; | 
| 156     using TimerBase::isActive; | 156     using TimerBase::isActive; | 
| 157 | 157 | 
| 158 private: | 158 private: | 
| 159     virtual void fired() | 159     virtual void fired() OVERRIDE | 
| 160     { | 160     { | 
| 161         if (m_shouldRestartWhenTimerFires) { | 161         if (m_shouldRestartWhenTimerFires) { | 
| 162             m_shouldRestartWhenTimerFires = false; | 162             m_shouldRestartWhenTimerFires = false; | 
| 163             startOneShot(m_delay); | 163             startOneShot(m_delay); | 
| 164             return; | 164             return; | 
| 165         } | 165         } | 
| 166 | 166 | 
| 167         (m_object->*m_function)(this); | 167         (m_object->*m_function)(this); | 
| 168     } | 168     } | 
| 169 | 169 | 
| 170     TimerFiredClass* m_object; | 170     TimerFiredClass* m_object; | 
| 171     TimerFiredFunction m_function; | 171     TimerFiredFunction m_function; | 
| 172 | 172 | 
| 173     double m_delay; | 173     double m_delay; | 
| 174     bool m_shouldRestartWhenTimerFires; | 174     bool m_shouldRestartWhenTimerFires; | 
| 175 }; | 175 }; | 
| 176 | 176 | 
| 177 } | 177 } | 
| 178 | 178 | 
| 179 #endif | 179 #endif | 
| OLD | NEW | 
|---|