Changeset 214504 in webkit for trunk/Source/JavaScriptCore/runtime/JSRunLoopTimer.cpp
- Timestamp:
- Mar 28, 2017, 4:12:11 PM (8 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/JSRunLoopTimer.cpp
r214502 r214504 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 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 26 #include "config.h" 27 #include " HeapTimer.h"27 #include "JSRunLoopTimer.h" 28 28 29 29 #include "GCActivityCallback.h" 30 30 #include "IncrementalSweeper.h" 31 #include "JSCInlines.h" 31 32 #include "JSObject.h" 32 33 #include "JSString.h" 33 #include "JSCInlines.h" 34 34 35 #include <wtf/MainThread.h> 35 36 #include <wtf/Threading.h> … … 42 43 43 44 #if USE(CF) 44 45 const CFTimeInterval HeapTimer::s_decade = 60 * 60 * 24 * 365 * 10;46 45 47 HeapTimer::HeapTimer(VM* vm) 46 const CFTimeInterval JSRunLoopTimer::s_decade = 60 * 60 * 24 * 365 * 10; 47 48 JSRunLoopTimer::JSRunLoopTimer(VM* vm) 48 49 : m_vm(vm) 49 50 , m_apiLock(&vm->apiLock()) … … 52 53 } 53 54 54 void HeapTimer::setRunLoop(CFRunLoopRef runLoop)55 void JSRunLoopTimer::setRunLoop(CFRunLoopRef runLoop) 55 56 { 56 57 if (m_runLoop) { … … 60 61 m_timer.clear(); 61 62 } 62 63 63 64 if (runLoop) { 64 65 m_runLoop = runLoop; 65 66 memset(&m_context, 0, sizeof(CFRunLoopTimerContext)); 66 67 m_context.info = this; 67 m_timer = adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, s_decade, s_decade, 0, 0, HeapTimer::timerDidFire, &m_context));68 m_timer = adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + s_decade, s_decade, 0, 0, JSRunLoopTimer::timerDidFire, &m_context)); 68 69 CFRunLoopAddTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes); 69 70 } 70 71 } 71 72 72 HeapTimer::~HeapTimer()73 JSRunLoopTimer::~JSRunLoopTimer() 73 74 { 74 75 setRunLoop(0); 75 76 } 76 77 77 void HeapTimer::timerDidFire(CFRunLoopTimerRef, void* contextPtr)78 void JSRunLoopTimer::timerDidFire(CFRunLoopTimerRef, void* contextPtr) 78 79 { 79 HeapTimer* timer = static_cast<HeapTimer*>(contextPtr);80 JSRunLoopTimer* timer = static_cast<JSRunLoopTimer*>(contextPtr); 80 81 timer->m_apiLock->lock(); 81 82 … … 95 96 } 96 97 97 void HeapTimer::scheduleTimer(double intervalInSeconds)98 void JSRunLoopTimer::scheduleTimer(double intervalInSeconds) 98 99 { 99 100 CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + intervalInSeconds); … … 101 102 } 102 103 103 void HeapTimer::cancelTimer()104 void JSRunLoopTimer::cancelTimer() 104 105 { 105 106 CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade); … … 109 110 #elif USE(GLIB) 110 111 111 const long HeapTimer::s_decade = 60 * 60 * 24 * 365 * 10;112 const long JSRunLoopTimer::s_decade = 60 * 60 * 24 * 365 * 10; 112 113 113 static GSourceFuncs heapTimerSourceFunctions = {114 static GSourceFuncs JSRunLoopTimerSourceFunctions = { 114 115 nullptr, // prepare 115 116 nullptr, // check … … 124 125 }; 125 126 126 HeapTimer::HeapTimer(VM* vm)127 JSRunLoopTimer::JSRunLoopTimer(VM* vm) 127 128 : m_vm(vm) 128 129 , m_apiLock(&vm->apiLock()) 129 , m_timer(adoptGRef(g_source_new(& heapTimerSourceFunctions, sizeof(GSource))))130 , m_timer(adoptGRef(g_source_new(&JSRunLoopTimerSourceFunctions, sizeof(GSource)))) 130 131 { 131 g_source_set_name(m_timer.get(), "[JavaScriptCore] HeapTimer");132 g_source_set_name(m_timer.get(), "[JavaScriptCore] JSRunLoopTimer"); 132 133 g_source_set_callback(m_timer.get(), [](gpointer userData) -> gboolean { 133 auto& heapTimer = *static_cast<HeapTimer*>(userData);134 g_source_set_ready_time( heapTimer.m_timer.get(), g_get_monotonic_time() + HeapTimer::s_decade * G_USEC_PER_SEC);135 heapTimer.timerDidFire();134 auto& runLoopTimer = *static_cast<JSRunLoopTimer*>(userData); 135 g_source_set_ready_time(runLoopTimer.m_timer.get(), g_get_monotonic_time() + JSRunLoopTimer::s_decade * G_USEC_PER_SEC); 136 runLoopTimer.timerDidFire(); 136 137 return G_SOURCE_CONTINUE; 137 138 }, this, nullptr); … … 139 140 } 140 141 141 HeapTimer::~HeapTimer()142 JSRunLoopTimer::~JSRunLoopTimer() 142 143 { 143 144 g_source_destroy(m_timer.get()); 144 145 } 145 146 146 void HeapTimer::timerDidFire()147 void JSRunLoopTimer::timerDidFire() 147 148 { 148 149 m_apiLock->lock(); … … 162 163 } 163 164 164 void HeapTimer::scheduleTimer(double intervalInSeconds)165 void JSRunLoopTimer::scheduleTimer(double intervalInSeconds) 165 166 { 166 167 g_source_set_ready_time(m_timer.get(), g_get_monotonic_time() + intervalInSeconds * G_USEC_PER_SEC); … … 168 169 } 169 170 170 void HeapTimer::cancelTimer()171 void JSRunLoopTimer::cancelTimer() 171 172 { 172 173 g_source_set_ready_time(m_timer.get(), g_get_monotonic_time() + s_decade * G_USEC_PER_SEC); … … 174 175 } 175 176 #else 176 HeapTimer::HeapTimer(VM* vm)177 JSRunLoopTimer::JSRunLoopTimer(VM* vm) 177 178 : m_vm(vm) 178 179 { 179 180 } 180 181 181 HeapTimer::~HeapTimer()182 JSRunLoopTimer::~JSRunLoopTimer() 182 183 { 183 184 } 184 185 185 void HeapTimer::invalidate()186 void JSRunLoopTimer::invalidate() 186 187 { 187 188 } 188 189 189 void HeapTimer::scheduleTimer(double)190 void JSRunLoopTimer::scheduleTimer(double) 190 191 { 191 192 } 192 193 193 void HeapTimer::cancelTimer()194 void JSRunLoopTimer::cancelTimer() 194 195 { 195 196 } 196 197 #endif 197 198 198 199 199 } // namespace JSC
Note:
See TracChangeset
for help on using the changeset viewer.