https://bugs.webkit.org/show_bug.cgi?id=150771
Reviewed by Žan Doberšek.
Source/WTF:
Delete on destroy sources made the GMainLoopSource implementation
more complex and they are currently unused.
* wtf/glib/GMainLoopSource.cpp:
(WTF::GMainLoopSource::boolCallback):
(WTF::GMainLoopSource::create): Deleted.
(WTF::GMainLoopSource::GMainLoopSource): Deleted.
(WTF::GMainLoopSource::cancel): Deleted.
(WTF::GMainLoopSource::scheduleAndDeleteOnDestroy): Deleted.
(WTF::GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy): Deleted.
(WTF::GMainLoopSource::voidCallback): Deleted.
* wtf/glib/GMainLoopSource.h:
Tools:
* TestWebKitAPI/Tests/WTF/glib/GMainLoopSource.cpp:
(TestWebKitAPI::TEST): Remove DeleteOnDestroy unit tests.
* TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp:
(WebViewTest::wait): Use g_timeout_add instead of GMainLoopSource.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@191880
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2015-11-02 Carlos Garcia Campos <cgarcia@igalia.com>
+
+ [GLIB] Remove delete on destroy GMainLoopSources
+ https://bugs.webkit.org/show_bug.cgi?id=150771
+
+ Reviewed by Žan Doberšek.
+
+ Delete on destroy sources made the GMainLoopSource implementation
+ more complex and they are currently unused.
+
+ * wtf/glib/GMainLoopSource.cpp:
+ (WTF::GMainLoopSource::boolCallback):
+ (WTF::GMainLoopSource::create): Deleted.
+ (WTF::GMainLoopSource::GMainLoopSource): Deleted.
+ (WTF::GMainLoopSource::cancel): Deleted.
+ (WTF::GMainLoopSource::scheduleAndDeleteOnDestroy): Deleted.
+ (WTF::GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy): Deleted.
+ (WTF::GMainLoopSource::voidCallback): Deleted.
+ * wtf/glib/GMainLoopSource.h:
+
2015-11-01 Carlos Garcia Campos <cgarcia@igalia.com>
[GTK] Use RunLoop in WorkQueue implementation
namespace WTF {
-GMainLoopSource& GMainLoopSource::create()
-{
- return *new GMainLoopSource(DeleteOnDestroy);
-}
-
-GMainLoopSource::GMainLoopSource()
- : m_deleteOnDestroy(DoNotDeleteOnDestroy)
- , m_status(Ready)
-{
-}
-
-GMainLoopSource::GMainLoopSource(DeleteOnDestroyType deleteOnDestroy)
- : m_deleteOnDestroy(deleteOnDestroy)
- , m_status(Ready)
-{
-}
-
GMainLoopSource::~GMainLoopSource()
{
cancel();
void GMainLoopSource::cancel()
{
- // Delete-on-destroy GMainLoopSource objects can't be cancelled.
- if (m_deleteOnDestroy == DeleteOnDestroy)
- return;
-
// A valid context should only be present if GMainLoopSource is in the Scheduled or Dispatching state.
ASSERT(!m_context.source || m_status == Scheduled || m_status == Dispatching);
scheduleTimeoutSource(name, reinterpret_cast<GSourceFunc>(boolSourceCallback), priority, context);
}
-void GMainLoopSource::scheduleAndDeleteOnDestroy(const char* name, std::function<void()>&& function, int priority, std::function<void()>&& destroyFunction, GMainContext* context)
-{
- create().schedule(name, WTF::move(function), priority, WTF::move(destroyFunction), context);
-}
-
-void GMainLoopSource::scheduleAndDeleteOnDestroy(const char* name, std::function<bool()>&& function, int priority, std::function<void()>&& destroyFunction, GMainContext* context)
-{
- create().schedule(name, WTF::move(function), priority, WTF::move(destroyFunction), context);
-}
-
-void GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<void()>&& function, std::chrono::milliseconds delay, int priority, std::function<void()>&& destroyFunction, GMainContext* context)
-{
- create().scheduleAfterDelay(name, WTF::move(function), delay, priority, WTF::move(destroyFunction), context);
-}
-
-void GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<bool()>&& function, std::chrono::milliseconds delay, int priority, std::function<void()>&& destroyFunction, GMainContext* context)
-{
- create().scheduleAfterDelay(name, WTF::move(function), delay, priority, WTF::move(destroyFunction), context);
-}
-
-void GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<void()>&& function, std::chrono::seconds delay, int priority, std::function<void()>&& destroyFunction, GMainContext* context)
-{
- create().scheduleAfterDelay(name, WTF::move(function), delay, priority, WTF::move(destroyFunction), context);
-}
-
-void GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<bool()>&& function, std::chrono::seconds delay, int priority, std::function<void()>&& destroyFunction, GMainContext* context)
-{
- create().scheduleAfterDelay(name, WTF::move(function), delay, priority, WTF::move(destroyFunction), context);
-}
-
-void GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<void()>&& function, std::chrono::microseconds delay, int priority, std::function<void()>&& destroyFunction, GMainContext* context)
-{
- create().scheduleAfterDelay(name, WTF::move(function), delay, priority, WTF::move(destroyFunction), context);
-}
-
-void GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<bool()>&& function, std::chrono::microseconds delay, int priority, std::function<void()>&& destroyFunction, GMainContext* context)
-{
- create().scheduleAfterDelay(name, WTF::move(function), delay, priority, WTF::move(destroyFunction), context);
-}
-
bool GMainLoopSource::prepareVoidCallback(Context& context)
{
if (!m_context.source)
}
context.destroySource();
- if (m_deleteOnDestroy == DeleteOnDestroy)
- delete this;
}
bool GMainLoopSource::prepareBoolCallback(Context& context)
finishBoolCallback(retval, context);
}
- if (context.source) {
+ if (context.source)
context.destroySource();
- if (m_deleteOnDestroy == DeleteOnDestroy)
- delete this;
- }
return retval;
}
WTF_MAKE_NONCOPYABLE(GMainLoopSource);
WTF_MAKE_FAST_ALLOCATED;
public:
- WTF_EXPORT_PRIVATE GMainLoopSource();
+ WTF_EXPORT_PRIVATE GMainLoopSource() = default;
WTF_EXPORT_PRIVATE virtual ~GMainLoopSource();
static const bool Stop = false;
WTF_EXPORT_PRIVATE void schedule(const char* name, std::function<bool(GIOCondition)>&&, GSocket*, GIOCondition, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
- static void scheduleAndDeleteOnDestroy(const char* name, std::function<void()>&&, int priority = G_PRIORITY_DEFAULT, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
- static void scheduleAndDeleteOnDestroy(const char* name, std::function<bool()>&&, int priority = G_PRIORITY_DEFAULT, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
- static void scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<void()>&&, std::chrono::milliseconds, int priority = G_PRIORITY_DEFAULT, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
- static void scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<bool()>&&, std::chrono::milliseconds, int priority = G_PRIORITY_DEFAULT, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
- static void scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<void()>&&, std::chrono::seconds, int priority = G_PRIORITY_DEFAULT, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
- static void scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<bool()>&&, std::chrono::seconds, int priority = G_PRIORITY_DEFAULT, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
- static void scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<void()>&&, std::chrono::microseconds, int priority = G_PRIORITY_DEFAULT, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
- static void scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<bool()>&&, std::chrono::microseconds, int priority = G_PRIORITY_DEFAULT, std::function<void()>&& destroyFunction = nullptr, GMainContext* = nullptr);
-
protected:
enum Status { Ready, Scheduled, Dispatching };
virtual void finishBoolCallback(bool retval, Context&);
private:
- static GMainLoopSource& create();
-
- enum DeleteOnDestroyType { DeleteOnDestroy, DoNotDeleteOnDestroy };
- GMainLoopSource(DeleteOnDestroyType);
-
void scheduleIdleSource(const char* name, GSourceFunc, int priority, GMainContext*);
void scheduleTimeoutSource(const char* name, GSourceFunc, int priority, GMainContext*);
bool socketCallback(GIOCondition);
static gboolean boolSourceCallback(GMainLoopSource*);
static gboolean socketSourceCallback(GSocket*, GIOCondition, GMainLoopSource*);
- DeleteOnDestroyType m_deleteOnDestroy;
-
protected:
Context m_context;
- Status m_status;
+ Status m_status { Ready };
};
} // namespace WTF
+2015-11-02 Carlos Garcia Campos <cgarcia@igalia.com>
+
+ [GLIB] Remove delete on destroy GMainLoopSources
+ https://bugs.webkit.org/show_bug.cgi?id=150771
+
+ Reviewed by Žan Doberšek.
+
+ * TestWebKitAPI/Tests/WTF/glib/GMainLoopSource.cpp:
+ (TestWebKitAPI::TEST): Remove DeleteOnDestroy unit tests.
+ * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp:
+ (WebViewTest::wait): Use g_timeout_add instead of GMainLoopSource.
+
2015-11-01 Yusuke Suzuki <utatane.tea@gmail.com>
[ES6] Support Generator Syntax
destroyCallbacksAfterReschedulingDuringDispatch<ThreadSafeTestingContext>();
}
-TEST(WTF_GMainLoopSource, DeleteOnDestroySources)
-{
- // Testing the delete-on-destroy sources is very limited. There's no good way
- // of testing that the GMainLoopSource objects are deleted when their GSource
- // is destroyed.
-
- struct TestingContext {
- GMainLoopSourceTest<GMainLoopSource> test;
- unsigned callbackCallCount = 0;
- bool destroyCallbackCalled = false;
- } context;
-
- {
- TestingContext context;
-
- GMainLoopSource::scheduleAndDeleteOnDestroy("[Test] DeleteOnDestroy",
- [&] {
- context.callbackCallCount++;
- }, G_PRIORITY_DEFAULT,
- [&] {
- EXPECT_FALSE(context.destroyCallbackCalled);
- context.destroyCallbackCalled = true;
- });
-
- context.test.delayedFinish();
- context.test.runLoop();
- EXPECT_EQ(1, context.callbackCallCount);
- EXPECT_TRUE(context.destroyCallbackCalled);
- }
-
- {
- TestingContext context;
-
- GMainLoopSource::scheduleAndDeleteOnDestroy("[Test] DeleteOnDestroy",
- std::function<bool ()>([&] {
- context.callbackCallCount++;
- return context.callbackCallCount != 3;
- }), G_PRIORITY_DEFAULT,
- [&] {
- EXPECT_FALSE(context.destroyCallbackCalled);
- context.destroyCallbackCalled = true;
- });
-
- context.test.delayedFinish();
- context.test.runLoop();
- EXPECT_EQ(3, context.callbackCallCount);
- EXPECT_TRUE(context.destroyCallbackCalled);
- }
-}
-
} // namespace TestWebKitAPI
void WebViewTest::wait(double seconds)
{
- GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy("WebViewTest wait", [this] { quitMainLoop(); },
- std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::duration<double>(seconds)));
+ g_timeout_add(seconds * 1000, [](gpointer userData) -> gboolean {
+ static_cast<WebViewTest*>(userData)->quitMainLoop();
+ return G_SOURCE_REMOVE;
+ }, this);
g_main_loop_run(m_mainLoop);
}