[GTK] Use RunLoop::Timer in main thread shared timer GTK+ implementation
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Nov 2015 07:54:38 +0000 (07:54 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Nov 2015 07:54:38 +0000 (07:54 +0000)
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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@191852 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/RunLoop.h
Source/WTF/wtf/glib/RunLoopGLib.cpp
Source/WebCore/ChangeLog
Source/WebCore/platform/MainThreadSharedTimer.cpp
Source/WebCore/platform/MainThreadSharedTimer.h
Source/WebCore/platform/gtk/MainThreadSharedTimerGtk.cpp

index 2898e920faea0446c334f18a22071d5ab326a40e..cd4c21adbdef648b894d8e740e6c2cb50a94aa7c 100644 (file)
@@ -1,3 +1,16 @@
+2015-11-01  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Use RunLoop::Timer in main thread shared timer GTK+ implementation
+        https://bugs.webkit.org/show_bug.cgi?id=150754
+
+        Reviewed by Darin Adler.
+
+        Add API to set the priority of a RunLoop::Timer for GLib.
+
+        * wtf/RunLoop.h:
+        * wtf/glib/RunLoopGLib.cpp:
+        (WTF::RunLoop::TimerBase::setPriority):
+
 2015-10-31  Andreas Kling  <akling@apple.com>
 
         Add a debug overlay with information about web process resource usage.
index 9b159e6823abedb867a10032377d8053c7db975f..56ae6b1a726918384b92cd84ea4ce3e2bbeb8bb1 100644 (file)
@@ -83,6 +83,10 @@ public:
 
         virtual void fired() = 0;
 
+#if USE(GLIB) && !PLATFORM(EFL)
+        void setPriority(int);
+#endif
+
     private:
         WTF_EXPORT_PRIVATE void start(double nextFireInterval, bool repeat);
 
index c5e8ffd3acb1ca4d5249706afa2570041068004c..9fa9b9b04d8089bac4a393a24d7bb8636de498fd 100644 (file)
@@ -141,6 +141,11 @@ RunLoop::TimerBase::~TimerBase()
     g_source_destroy(m_source.get());
 }
 
+void RunLoop::TimerBase::setPriority(int priority)
+{
+    g_source_set_priority(m_source.get(), priority);
+}
+
 void RunLoop::TimerBase::updateReadyTime()
 {
     g_source_set_ready_time(m_source.get(), m_fireInterval.count() ? g_get_monotonic_time() + m_fireInterval.count() : 0);
index 957b7acf08c1378030dfb34b007019c19554a29c..a6678422a6474f0b87b6df0a81d0ba1649d20346 100644 (file)
@@ -1,3 +1,23 @@
+2015-11-01  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Use RunLoop::Timer in main thread shared timer GTK+ implementation
+        https://bugs.webkit.org/show_bug.cgi?id=150754
+
+        Reviewed by Darin Adler.
+
+        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):
+
 2015-10-31  Andreas Kling  <akling@apple.com>
 
         Add a debug overlay with information about web process resource usage.
index 67f17c6b4bd40256e2a00ffbee4cf766f40a7968..72b3a7e6cf8175dd49c1a2911dc59aa4f458e189 100644 (file)
@@ -34,9 +34,11 @@ MainThreadSharedTimer& MainThreadSharedTimer::singleton()
     return instance;
 }
 
+#if !PLATFORM(GTK)
 MainThreadSharedTimer::MainThreadSharedTimer()
 {
 }
+#endif
 
 void MainThreadSharedTimer::setFiredFunction(std::function<void()>&& firedFunction)
 {
@@ -44,7 +46,7 @@ void MainThreadSharedTimer::setFiredFunction(std::function<void()>&& firedFuncti
     m_firedFunction = WTF::move(firedFunction);
 }
 
-void MainThreadSharedTimer::fired() const
+void MainThreadSharedTimer::fired()
 {
     ASSERT(m_firedFunction);
     m_firedFunction();
index 73cfcbce9cb1b6fa5a90a8d5e8a35490edbc30ed..f7a0c91daa0d9307c83c2efcc74ffe02af7ccf8f 100644 (file)
 #include "SharedTimer.h"
 #include <wtf/NeverDestroyed.h>
 
+#if PLATFORM(GTK)
+#include <wtf/RunLoop.h>
+#endif
+
 namespace WebCore {
 
 class MainThreadSharedTimer final : public SharedTimer {
@@ -44,12 +48,15 @@ public:
 
     // FIXME: This should be private, but CF and Windows implementations
     // need to call this from non-member functions at the moment.
-    void fired() const;
+    void fired();
 
 private:
     MainThreadSharedTimer();
 
     std::function<void()> m_firedFunction;
+#if PLATFORM(GTK)
+    RunLoop::Timer<MainThreadSharedTimer> m_timer;
+#endif
 };
 
 } // namespace WebCore
index 87d9b50bdf8a02cc5793376e1b780cc00983976c..8b867664edcd4057b74cdd655b2b009763f85cf4 100644 (file)
 #include "config.h"
 #include "MainThreadSharedTimer.h"
 
-#include <wtf/glib/GMainLoopSource.h>
+#include <glib.h>
 
 namespace WebCore {
 
-static GMainLoopSource gSharedTimer;
+MainThreadSharedTimer::MainThreadSharedTimer()
+    : m_timer(RunLoop::main(), this, &MainThreadSharedTimer::fired)
+{
+    // This is GDK_PRIORITY_REDRAW, but we don't want to depend on GDK here just to use a constant.
+    m_timer.setPriority(G_PRIORITY_HIGH_IDLE + 20);
+}
 
 void MainThreadSharedTimer::setFireInterval(double interval)
 {
     ASSERT(m_firedFunction);
-
-    // This is GDK_PRIORITY_REDRAW, but we don't want to depend on GDK here just to use a constant.
-    static const int priority = G_PRIORITY_HIGH_IDLE + 20;
-    gSharedTimer.scheduleAfterDelay("[WebKit] sharedTimerTimeoutCallback", [this] { fired(); },
-        std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::duration<double>(interval)), priority);
+    m_timer.startOneShot(interval);
 }
 
 void MainThreadSharedTimer::stop()
 {
-    gSharedTimer.cancel();
+    m_timer.stop();
 }
 
 void MainThreadSharedTimer::invalidate()