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
+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.
virtual void fired() = 0;
+#if USE(GLIB) && !PLATFORM(EFL)
+ void setPriority(int);
+#endif
+
private:
WTF_EXPORT_PRIVATE void start(double nextFireInterval, bool repeat);
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);
+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.
return instance;
}
+#if !PLATFORM(GTK)
MainThreadSharedTimer::MainThreadSharedTimer()
{
}
+#endif
void MainThreadSharedTimer::setFiredFunction(std::function<void()>&& firedFunction)
{
m_firedFunction = WTF::move(firedFunction);
}
-void MainThreadSharedTimer::fired() const
+void MainThreadSharedTimer::fired()
{
ASSERT(m_firedFunction);
m_firedFunction();
#include "SharedTimer.h"
#include <wtf/NeverDestroyed.h>
+#if PLATFORM(GTK)
+#include <wtf/RunLoop.h>
+#endif
+
namespace WebCore {
class MainThreadSharedTimer final : public SharedTimer {
// 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
#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()