Title: [191852] trunk/Source
Revision
191852
Author
[email protected]
Date
2015-11-01 00:54:38 -0700 (Sun, 01 Nov 2015)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (191851 => 191852)


--- trunk/Source/WTF/ChangeLog	2015-11-01 05:47:41 UTC (rev 191851)
+++ trunk/Source/WTF/ChangeLog	2015-11-01 07:54:38 UTC (rev 191852)
@@ -1,3 +1,16 @@
+2015-11-01  Carlos Garcia Campos  <[email protected]>
+
+        [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  <[email protected]>
 
         Add a debug overlay with information about web process resource usage.

Modified: trunk/Source/WTF/wtf/RunLoop.h (191851 => 191852)


--- trunk/Source/WTF/wtf/RunLoop.h	2015-11-01 05:47:41 UTC (rev 191851)
+++ trunk/Source/WTF/wtf/RunLoop.h	2015-11-01 07:54:38 UTC (rev 191852)
@@ -83,6 +83,10 @@
 
         virtual void fired() = 0;
 
+#if USE(GLIB) && !PLATFORM(EFL)
+        void setPriority(int);
+#endif
+
     private:
         WTF_EXPORT_PRIVATE void start(double nextFireInterval, bool repeat);
 

Modified: trunk/Source/WTF/wtf/glib/RunLoopGLib.cpp (191851 => 191852)


--- trunk/Source/WTF/wtf/glib/RunLoopGLib.cpp	2015-11-01 05:47:41 UTC (rev 191851)
+++ trunk/Source/WTF/wtf/glib/RunLoopGLib.cpp	2015-11-01 07:54:38 UTC (rev 191852)
@@ -141,6 +141,11 @@
     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);

Modified: trunk/Source/WebCore/ChangeLog (191851 => 191852)


--- trunk/Source/WebCore/ChangeLog	2015-11-01 05:47:41 UTC (rev 191851)
+++ trunk/Source/WebCore/ChangeLog	2015-11-01 07:54:38 UTC (rev 191852)
@@ -1,3 +1,23 @@
+2015-11-01  Carlos Garcia Campos  <[email protected]>
+
+        [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  <[email protected]>
 
         Add a debug overlay with information about web process resource usage.

Modified: trunk/Source/WebCore/platform/MainThreadSharedTimer.cpp (191851 => 191852)


--- trunk/Source/WebCore/platform/MainThreadSharedTimer.cpp	2015-11-01 05:47:41 UTC (rev 191851)
+++ trunk/Source/WebCore/platform/MainThreadSharedTimer.cpp	2015-11-01 07:54:38 UTC (rev 191852)
@@ -34,9 +34,11 @@
     return instance;
 }
 
+#if !PLATFORM(GTK)
 MainThreadSharedTimer::MainThreadSharedTimer()
 {
 }
+#endif
 
 void MainThreadSharedTimer::setFiredFunction(std::function<void()>&& firedFunction)
 {
@@ -44,7 +46,7 @@
     m_firedFunction = WTF::move(firedFunction);
 }
 
-void MainThreadSharedTimer::fired() const
+void MainThreadSharedTimer::fired()
 {
     ASSERT(m_firedFunction);
     m_firedFunction();

Modified: trunk/Source/WebCore/platform/MainThreadSharedTimer.h (191851 => 191852)


--- trunk/Source/WebCore/platform/MainThreadSharedTimer.h	2015-11-01 05:47:41 UTC (rev 191851)
+++ trunk/Source/WebCore/platform/MainThreadSharedTimer.h	2015-11-01 07:54:38 UTC (rev 191852)
@@ -30,6 +30,10 @@
 #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 @@
 
     // 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

Modified: trunk/Source/WebCore/platform/gtk/MainThreadSharedTimerGtk.cpp (191851 => 191852)


--- trunk/Source/WebCore/platform/gtk/MainThreadSharedTimerGtk.cpp	2015-11-01 05:47:41 UTC (rev 191851)
+++ trunk/Source/WebCore/platform/gtk/MainThreadSharedTimerGtk.cpp	2015-11-01 07:54:38 UTC (rev 191852)
@@ -28,25 +28,26 @@
 #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()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to