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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 106 |
107 #if ENABLE(ASSERT) | 107 #if ENABLE(ASSERT) |
108 ThreadIdentifier m_thread; | 108 ThreadIdentifier m_thread; |
109 #endif | 109 #endif |
110 | 110 |
111 friend class ThreadTimers; | 111 friend class ThreadTimers; |
112 friend class TimerHeapLessThanFunction; | 112 friend class TimerHeapLessThanFunction; |
113 friend class TimerHeapReference; | 113 friend class TimerHeapReference; |
114 }; | 114 }; |
115 | 115 |
| 116 template<typename T, bool = IsGarbageCollectedType<T>::value> |
| 117 class TimerIsObjectAliveTrait { |
| 118 public: |
| 119 static bool isAlive(T*) { return true; } |
| 120 }; |
| 121 |
| 122 template<typename T> |
| 123 class TimerIsObjectAliveTrait<T, true> { |
| 124 public: |
| 125 static bool isAlive(T* objectPointer) |
| 126 { |
| 127 // Oilpan: if a timer fires while Oilpan heaps are being lazily |
| 128 // swept, it is not safe to proceed if the object is about to |
| 129 // be swept (and this timer will be stopped while doing so.) |
| 130 return Heap::isFinalizedObjectAlive(objectPointer); |
| 131 } |
| 132 }; |
| 133 |
116 template <typename TimerFiredClass> | 134 template <typename TimerFiredClass> |
117 class Timer final : public TimerBase { | 135 class Timer final : public TimerBase { |
118 public: | 136 public: |
119 typedef void (TimerFiredClass::*TimerFiredFunction)(Timer*); | 137 typedef void (TimerFiredClass::*TimerFiredFunction)(Timer*); |
120 | 138 |
121 Timer(TimerFiredClass* o, TimerFiredFunction f) | 139 Timer(TimerFiredClass* o, TimerFiredFunction f) |
122 : m_object(o), m_function(f) { } | 140 : m_object(o), m_function(f) { } |
123 | 141 |
124 private: | 142 private: |
125 virtual void fired() override { (m_object->*m_function)(this); } | 143 virtual void fired() override |
| 144 { |
| 145 if (!TimerIsObjectAliveTrait<TimerFiredClass>::isAlive(m_object)) |
| 146 return; |
| 147 (m_object->*m_function)(this); |
| 148 } |
126 | 149 |
127 // FIXME: oilpan: TimerBase should be moved to the heap and m_object should
be traced. | 150 // FIXME: oilpan: TimerBase should be moved to the heap and m_object should
be traced. |
128 // This raw pointer is safe as long as Timer<X> is held by the X itself (Tha
t's the case | 151 // This raw pointer is safe as long as Timer<X> is held by the X itself (Tha
t's the case |
129 // in the current code base). | 152 // in the current code base). |
130 GC_PLUGIN_IGNORE("363031") | 153 GC_PLUGIN_IGNORE("363031") |
131 TimerFiredClass* m_object; | 154 TimerFiredClass* m_object; |
132 TimerFiredFunction m_function; | 155 TimerFiredFunction m_function; |
133 }; | 156 }; |
134 | 157 |
135 inline bool TimerBase::isActive() const | 158 inline bool TimerBase::isActive() const |
136 { | 159 { |
137 ASSERT(m_thread == currentThread()); | 160 ASSERT(m_thread == currentThread()); |
138 return m_nextFireTime; | 161 return m_nextFireTime; |
139 } | 162 } |
140 | 163 |
141 } | 164 } |
142 | 165 |
143 #endif | 166 #endif |
OLD | NEW |