Changeset 214732 in webkit


Ignore:
Timestamp:
Apr 2, 2017 10:41:30 PM (7 years ago)
Author:
Carlos Garcia Campos
Message:

Share implementation of JSRunLoopTimer::timerDidFire
https://bugs.webkit.org/show_bug.cgi?id=170392

Reviewed by Michael Catanzaro.

The code is cross-platform but it's duplicated in CF and GLib implementations, it could be shared instead.

  • runtime/JSRunLoopTimer.cpp:

(JSC::JSRunLoopTimer::timerDidFire): Move common implementation here.
(JSC::JSRunLoopTimer::setRunLoop): Use timerDidFireCallback.
(JSC::JSRunLoopTimer::timerDidFireCallback): Call JSRunLoopTimer::timerDidFire().

  • runtime/JSRunLoopTimer.h:
Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r214714 r214732  
     12017-04-02  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        Share implementation of JSRunLoopTimer::timerDidFire
     4        https://bugs.webkit.org/show_bug.cgi?id=170392
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        The code is cross-platform but it's duplicated in CF and GLib implementations, it could be shared instead.
     9
     10        * runtime/JSRunLoopTimer.cpp:
     11        (JSC::JSRunLoopTimer::timerDidFire): Move common implementation here.
     12        (JSC::JSRunLoopTimer::setRunLoop): Use timerDidFireCallback.
     13        (JSC::JSRunLoopTimer::timerDidFireCallback): Call JSRunLoopTimer::timerDidFire().
     14        * runtime/JSRunLoopTimer.h:
     15
    1162017-04-01  Oleksandr Skachkov  <gskachkov@gmail.com>
    217
  • trunk/Source/JavaScriptCore/runtime/JSRunLoopTimer.cpp

    r214504 r214732  
    4242namespace JSC {
    4343
     44void JSRunLoopTimer::timerDidFire()
     45{
     46    m_apiLock->lock();
     47
     48    RefPtr<VM> vm = m_apiLock->vm();
     49    if (!vm) {
     50        // The VM has been destroyed, so we should just give up.
     51        m_apiLock->unlock();
     52        return;
     53    }
     54
     55    {
     56        JSLockHolder locker(vm.get());
     57        doWork();
     58    }
     59
     60    m_apiLock->unlock();
     61}
     62
    4463#if USE(CF)
    4564
     
    6685        memset(&m_context, 0, sizeof(CFRunLoopTimerContext));
    6786        m_context.info = this;
    68         m_timer = adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + s_decade, s_decade, 0, 0, JSRunLoopTimer::timerDidFire, &m_context));
     87        m_timer = adoptCF(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + s_decade, s_decade, 0, 0, JSRunLoopTimer::timerDidFireCallback, &m_context));
    6988        CFRunLoopAddTimer(m_runLoop.get(), m_timer.get(), kCFRunLoopCommonModes);
    7089    }
     
    7695}
    7796
    78 void JSRunLoopTimer::timerDidFire(CFRunLoopTimerRef, void* contextPtr)
     97void JSRunLoopTimer::timerDidFireCallback(CFRunLoopTimerRef, void* contextPtr)
    7998{
    80     JSRunLoopTimer* timer = static_cast<JSRunLoopTimer*>(contextPtr);
    81     timer->m_apiLock->lock();
    82 
    83     RefPtr<VM> vm = timer->m_apiLock->vm();
    84     if (!vm) {
    85         // The VM has been destroyed, so we should just give up.
    86         timer->m_apiLock->unlock();
    87         return;
    88     }
    89 
    90     {
    91         JSLockHolder locker(vm.get());
    92         timer->doWork();
    93     }
    94 
    95     timer->m_apiLock->unlock();
     99    static_cast<JSRunLoopTimer*>(contextPtr)->timerDidFire();
    96100}
    97101
     
    145149}
    146150
    147 void JSRunLoopTimer::timerDidFire()
    148 {
    149     m_apiLock->lock();
    150 
    151     if (!m_apiLock->vm()) {
    152         // The VM has been destroyed, so we should just give up.
    153         m_apiLock->unlock();
    154         return;
    155     }
    156 
    157     {
    158         JSLockHolder locker(m_vm);
    159         doWork();
    160     }
    161 
    162     m_apiLock->unlock();
    163 }
    164 
    165151void JSRunLoopTimer::scheduleTimer(double intervalInSeconds)
    166152{
     
    184170}
    185171
    186 void JSRunLoopTimer::invalidate()
    187 {
    188 }
    189 
    190172void JSRunLoopTimer::scheduleTimer(double)
    191173{
  • trunk/Source/JavaScriptCore/runtime/JSRunLoopTimer.h

    r214504 r214732  
    4949    JSRunLoopTimer(VM*);
    5050#if USE(CF)
    51     static void timerDidFire(CFRunLoopTimerRef, void*);
     51    static void timerDidFireCallback(CFRunLoopTimerRef, void*);
    5252#endif
    5353
     
    7979#elif USE(GLIB)
    8080    static const long s_decade;
    81     void timerDidFire();
    8281    GRefPtr<GSource> m_timer;
    8382#endif
    8483   
    8584private:
    86     void invalidate();
     85    void timerDidFire();
    8786};
    8887   
Note: See TracChangeset for help on using the changeset viewer.