Changeset 215228 in webkit for trunk/Source/JavaScriptCore/runtime/JSRunLoopTimer.cpp
- Timestamp:
- Apr 11, 2017, 7:56:21 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/JSRunLoopTimer.cpp
r215223 r215228 36 36 #include <wtf/Threading.h> 37 37 38 #if USE(GLIB )38 #if USE(GLIB_EVENT_LOOP) 39 39 #include <glib.h> 40 40 #include <wtf/glib/RunLoopSourcePriority.h> … … 42 42 43 43 namespace JSC { 44 45 const Seconds JSRunLoopTimer::s_decade { 60 * 60 * 24 * 365 * 10 }; 44 46 45 47 void JSRunLoopTimer::timerDidFire() … … 64 66 #if USE(CF) 65 67 66 const CFTimeInterval JSRunLoopTimer::s_decade = 60 * 60 * 24 * 365 * 10;67 68 68 JSRunLoopTimer::JSRunLoopTimer(VM* vm) 69 69 : m_vm(vm) … … 86 86 memset(&m_context, 0, sizeof(CFRunLoopTimerContext)); 87 87 m_context.info = this; 88 m_timer = adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + s_decade , s_decade, 0, 0, JSRunLoopTimer::timerDidFireCallback, &m_context));88 m_timer = adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + s_decade.seconds(), s_decade.seconds(), 0, 0, JSRunLoopTimer::timerDidFireCallback, &m_context)); 89 89 CFRunLoopAddTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes); 90 90 } … … 101 101 } 102 102 103 void JSRunLoopTimer::scheduleTimer( doubleintervalInSeconds)103 void JSRunLoopTimer::scheduleTimer(Seconds intervalInSeconds) 104 104 { 105 CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + intervalInSeconds );105 CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + intervalInSeconds.seconds()); 106 106 m_isScheduled = true; 107 107 } … … 109 109 void JSRunLoopTimer::cancelTimer() 110 110 { 111 CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade); 112 m_isScheduled = false; 113 } 114 115 #elif USE(GLIB) 116 117 const long JSRunLoopTimer::s_decade = 60 * 60 * 24 * 365 * 10; 118 119 static GSourceFuncs JSRunLoopTimerSourceFunctions = { 120 nullptr, // prepare 121 nullptr, // check 122 // dispatch 123 [](GSource*, GSourceFunc callback, gpointer userData) -> gboolean 124 { 125 return callback(userData); 126 }, 127 nullptr, // finalize 128 nullptr, // closure_callback 129 nullptr, // closure_marshall 130 }; 131 132 JSRunLoopTimer::JSRunLoopTimer(VM* vm) 133 : m_vm(vm) 134 , m_apiLock(&vm->apiLock()) 135 , m_timer(adoptGRef(g_source_new(&JSRunLoopTimerSourceFunctions, sizeof(GSource)))) 136 { 137 g_source_set_priority(m_timer.get(), RunLoopSourcePriority::JavascriptTimer); 138 g_source_set_name(m_timer.get(), "[JavaScriptCore] JSRunLoopTimer"); 139 g_source_set_callback(m_timer.get(), [](gpointer userData) -> gboolean { 140 auto& runLoopTimer = *static_cast<JSRunLoopTimer*>(userData); 141 g_source_set_ready_time(runLoopTimer.m_timer.get(), g_get_monotonic_time() + JSRunLoopTimer::s_decade * G_USEC_PER_SEC); 142 runLoopTimer.timerDidFire(); 143 return G_SOURCE_CONTINUE; 144 }, this, nullptr); 145 g_source_attach(m_timer.get(), g_main_context_get_thread_default()); 146 } 147 148 JSRunLoopTimer::~JSRunLoopTimer() 149 { 150 g_source_destroy(m_timer.get()); 151 } 152 153 void JSRunLoopTimer::scheduleTimer(double intervalInSeconds) 154 { 155 g_source_set_ready_time(m_timer.get(), g_get_monotonic_time() + intervalInSeconds * G_USEC_PER_SEC); 156 m_isScheduled = true; 157 } 158 159 void JSRunLoopTimer::cancelTimer() 160 { 161 g_source_set_ready_time(m_timer.get(), g_get_monotonic_time() + s_decade * G_USEC_PER_SEC); 111 CFRunLoopTimerSetNextFireDate(m_timer.get(), CFAbsoluteTimeGetCurrent() + s_decade.seconds()); 162 112 m_isScheduled = false; 163 113 } … … 165 115 #else 166 116 167 const Seconds JSRunLoopTimer::s_decade { 60 * 60 * 24 * 365 * 10 };168 169 117 JSRunLoopTimer::JSRunLoopTimer(VM* vm) 170 118 : m_vm(vm) 171 119 , m_apiLock(&vm->apiLock()) 172 , m_timer(RunLoop::current(), this, &JSRunLoopTimer::timerDidFire )120 , m_timer(RunLoop::current(), this, &JSRunLoopTimer::timerDidFireCallback) 173 121 { 122 #if USE(GLIB_EVENT_LOOP) 123 m_timer.setPriority(RunLoopSourcePriority::JavascriptTimer); 124 m_timer.setName("[JavaScriptCore] JSRunLoopTimer"); 125 #endif 174 126 m_timer.startOneShot(s_decade); 175 127 } … … 179 131 } 180 132 181 void JSRunLoopTimer::scheduleTimer(double intervalInSeconds) 133 void JSRunLoopTimer::timerDidFireCallback() 134 { 135 m_timer.startOneShot(s_decade); 136 timerDidFire(); 137 } 138 139 void JSRunLoopTimer::scheduleTimer(Seconds intervalInSeconds) 182 140 { 183 141 m_timer.startOneShot(intervalInSeconds);
Note:
See TracChangeset
for help on using the changeset viewer.