Changeset 191852 in webkit


Ignore:
Timestamp:
Nov 1, 2015 12:54:38 AM (8 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Use RunLoop::Timer in main thread shared timer GTK+ implementation
https://bugs.webkit.org/show_bug.cgi?id=150754

Reviewed by Darin Adler.

Source/WebCore:

It's more efficient because it uses a persistent source and it
simplifies the code even more.

  • platform/MainThreadSharedTimer.cpp:

(WebCore::MainThreadSharedTimer::fired): Make it non-const to be
able to use it as function callback of a RunLoop::Timer.

  • platform/MainThreadSharedTimer.h:
  • platform/gtk/MainThreadSharedTimerGtk.cpp:

(WebCore::MainThreadSharedTimer::MainThreadSharedTimer):
Initialize the RunLoop::Timer and set the prioriry.
(WebCore::MainThreadSharedTimer::setFireInterval):
(WebCore::MainThreadSharedTimer::stop):

Source/WTF:

Add API to set the priority of a RunLoop::Timer for GLib.

  • wtf/RunLoop.h:
  • wtf/glib/RunLoopGLib.cpp:

(WTF::RunLoop::TimerBase::setPriority):

Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r191849 r191852  
     12015-11-01  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Use RunLoop::Timer in main thread shared timer GTK+ implementation
     4        https://bugs.webkit.org/show_bug.cgi?id=150754
     5
     6        Reviewed by Darin Adler.
     7
     8        Add API to set the priority of a RunLoop::Timer for GLib.
     9
     10        * wtf/RunLoop.h:
     11        * wtf/glib/RunLoopGLib.cpp:
     12        (WTF::RunLoop::TimerBase::setPriority):
     13
    1142015-10-31  Andreas Kling  <akling@apple.com>
    215
  • trunk/Source/WTF/wtf/RunLoop.h

    r191786 r191852  
    8383
    8484        virtual void fired() = 0;
     85
     86#if USE(GLIB) && !PLATFORM(EFL)
     87        void setPriority(int);
     88#endif
    8589
    8690    private:
  • trunk/Source/WTF/wtf/glib/RunLoopGLib.cpp

    r191786 r191852  
    142142}
    143143
     144void RunLoop::TimerBase::setPriority(int priority)
     145{
     146    g_source_set_priority(m_source.get(), priority);
     147}
     148
    144149void RunLoop::TimerBase::updateReadyTime()
    145150{
  • trunk/Source/WebCore/ChangeLog

    r191851 r191852  
     12015-11-01  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Use RunLoop::Timer in main thread shared timer GTK+ implementation
     4        https://bugs.webkit.org/show_bug.cgi?id=150754
     5
     6        Reviewed by Darin Adler.
     7
     8        It's more efficient because it uses a persistent source and it
     9        simplifies the code even more.
     10
     11        * platform/MainThreadSharedTimer.cpp:
     12        (WebCore::MainThreadSharedTimer::fired): Make it non-const to be
     13        able to use it as function callback of a RunLoop::Timer.
     14        * platform/MainThreadSharedTimer.h:
     15        * platform/gtk/MainThreadSharedTimerGtk.cpp:
     16        (WebCore::MainThreadSharedTimer::MainThreadSharedTimer):
     17        Initialize the RunLoop::Timer and set the prioriry.
     18        (WebCore::MainThreadSharedTimer::setFireInterval):
     19        (WebCore::MainThreadSharedTimer::stop):
     20
    1212015-10-31  Andreas Kling  <akling@apple.com>
    222
  • trunk/Source/WebCore/platform/MainThreadSharedTimer.cpp

    r191789 r191852  
    3535}
    3636
     37#if !PLATFORM(GTK)
    3738MainThreadSharedTimer::MainThreadSharedTimer()
    3839{
    3940}
     41#endif
    4042
    4143void MainThreadSharedTimer::setFiredFunction(std::function<void()>&& firedFunction)
     
    4547}
    4648
    47 void MainThreadSharedTimer::fired() const
     49void MainThreadSharedTimer::fired()
    4850{
    4951    ASSERT(m_firedFunction);
  • trunk/Source/WebCore/platform/MainThreadSharedTimer.h

    r191789 r191852  
    3131#include <wtf/NeverDestroyed.h>
    3232
     33#if PLATFORM(GTK)
     34#include <wtf/RunLoop.h>
     35#endif
     36
    3337namespace WebCore {
    3438
     
    4549    // FIXME: This should be private, but CF and Windows implementations
    4650    // need to call this from non-member functions at the moment.
    47     void fired() const;
     51    void fired();
    4852
    4953private:
     
    5155
    5256    std::function<void()> m_firedFunction;
     57#if PLATFORM(GTK)
     58    RunLoop::Timer<MainThreadSharedTimer> m_timer;
     59#endif
    5360};
    5461
  • trunk/Source/WebCore/platform/gtk/MainThreadSharedTimerGtk.cpp

    r191789 r191852  
    2929#include "MainThreadSharedTimer.h"
    3030
    31 #include <wtf/glib/GMainLoopSource.h>
     31#include <glib.h>
    3232
    3333namespace WebCore {
    3434
    35 static GMainLoopSource gSharedTimer;
     35MainThreadSharedTimer::MainThreadSharedTimer()
     36    : m_timer(RunLoop::main(), this, &MainThreadSharedTimer::fired)
     37{
     38    // This is GDK_PRIORITY_REDRAW, but we don't want to depend on GDK here just to use a constant.
     39    m_timer.setPriority(G_PRIORITY_HIGH_IDLE + 20);
     40}
    3641
    3742void MainThreadSharedTimer::setFireInterval(double interval)
    3843{
    3944    ASSERT(m_firedFunction);
    40 
    41     // This is GDK_PRIORITY_REDRAW, but we don't want to depend on GDK here just to use a constant.
    42     static const int priority = G_PRIORITY_HIGH_IDLE + 20;
    43     gSharedTimer.scheduleAfterDelay("[WebKit] sharedTimerTimeoutCallback", [this] { fired(); },
    44         std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::duration<double>(interval)), priority);
     45    m_timer.startOneShot(interval);
    4546}
    4647
    4748void MainThreadSharedTimer::stop()
    4849{
    49     gSharedTimer.cancel();
     50    m_timer.stop();
    5051}
    5152
Note: See TracChangeset for help on using the changeset viewer.