Title: [183800] trunk
Revision
183800
Author
[email protected]
Date
2015-05-05 01:16:16 -0700 (Tue, 05 May 2015)

Log Message

[GTK] Async operations running in the WorkQueue thread should schedule their sources to the WorkQueue main lopp
https://bugs.webkit.org/show_bug.cgi?id=144541

Reviewed by Žan Doberšek.

Source/WTF:

They are currently sent to the main thread run loop, because we
are not setting the WorkQueue main context as the default one in
the worker thread.

* wtf/gtk/WorkQueueGtk.cpp:
(WTF::WorkQueue::platformInitialize): Call
g_main_context_push_thread_default() to set the WorkQueue main
context as the default of the thread before running the main loop,
and g_main_context_pop_thread_default() when the main loop quits.

Tools:

Add a test case to WorkQueue unit test, to check that sources of
asynchronous IO operations running in the WorkQueue thread are
dispatched by the WorkQueue main loop.

* TestWebKitAPI/PlatformGTK.cmake:
* TestWebKitAPI/Tests/WTF/gtk/WorkQueueGtk.cpp: Added.
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (183799 => 183800)


--- trunk/Source/WTF/ChangeLog	2015-05-05 07:49:13 UTC (rev 183799)
+++ trunk/Source/WTF/ChangeLog	2015-05-05 08:16:16 UTC (rev 183800)
@@ -1,3 +1,20 @@
+2015-05-05  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Async operations running in the WorkQueue thread should schedule their sources to the WorkQueue main lopp
+        https://bugs.webkit.org/show_bug.cgi?id=144541
+
+        Reviewed by Žan Doberšek.
+
+        They are currently sent to the main thread run loop, because we
+        are not setting the WorkQueue main context as the default one in
+        the worker thread.
+
+        * wtf/gtk/WorkQueueGtk.cpp:
+        (WTF::WorkQueue::platformInitialize): Call
+        g_main_context_push_thread_default() to set the WorkQueue main
+        context as the default of the thread before running the main loop,
+        and g_main_context_pop_thread_default() when the main loop quits.
+
 2015-05-04  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r183661.

Modified: trunk/Source/WTF/wtf/gtk/WorkQueueGtk.cpp (183799 => 183800)


--- trunk/Source/WTF/wtf/gtk/WorkQueueGtk.cpp	2015-05-05 07:49:13 UTC (rev 183799)
+++ trunk/Source/WTF/wtf/gtk/WorkQueueGtk.cpp	2015-05-05 08:16:16 UTC (rev 183800)
@@ -56,7 +56,11 @@
         threadName += strlen(threadName) - kVisualStudioThreadNameLimit;
 
     RefPtr<WorkQueue> protector(this);
-    m_workQueueThread = createThread(threadName, [protector] { g_main_loop_run(protector->m_eventLoop.get()); });
+    m_workQueueThread = createThread(threadName, [protector] {
+        g_main_context_push_thread_default(protector->m_eventContext.get());
+        g_main_loop_run(protector->m_eventLoop.get());
+        g_main_context_pop_thread_default(protector->m_eventContext.get());
+    });
 }
 
 void WorkQueue::platformInvalidate()

Modified: trunk/Tools/ChangeLog (183799 => 183800)


--- trunk/Tools/ChangeLog	2015-05-05 07:49:13 UTC (rev 183799)
+++ trunk/Tools/ChangeLog	2015-05-05 08:16:16 UTC (rev 183800)
@@ -1,3 +1,18 @@
+2015-05-05  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Async operations running in the WorkQueue thread should schedule their sources to the WorkQueue main lopp
+        https://bugs.webkit.org/show_bug.cgi?id=144541
+
+        Reviewed by Žan Doberšek.
+
+        Add a test case to WorkQueue unit test, to check that sources of
+        asynchronous IO operations running in the WorkQueue thread are
+        dispatched by the WorkQueue main loop.
+
+        * TestWebKitAPI/PlatformGTK.cmake:
+        * TestWebKitAPI/Tests/WTF/gtk/WorkQueueGtk.cpp: Added.
+        (TestWebKitAPI::TEST):
+
 2015-05-04  Brent Fulgham  <[email protected]>
 
         Correct '--show-webview' option for Tiled Drawing tests

Modified: trunk/Tools/TestWebKitAPI/PlatformGTK.cmake (183799 => 183800)


--- trunk/Tools/TestWebKitAPI/PlatformGTK.cmake	2015-05-05 07:49:13 UTC (rev 183799)
+++ trunk/Tools/TestWebKitAPI/PlatformGTK.cmake	2015-05-05 08:16:16 UTC (rev 183800)
@@ -134,4 +134,5 @@
 list(APPEND TestWTF_SOURCES
     ${TESTWEBKITAPI_DIR}/Tests/WTF/gobject/GMainLoopSource.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WTF/gobject/GUniquePtr.cpp
+    ${TESTWEBKITAPI_DIR}/Tests/WTF/gtk/WorkQueueGtk.cpp
 )

Added: trunk/Tools/TestWebKitAPI/Tests/WTF/gtk/WorkQueueGtk.cpp (0 => 183800)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/gtk/WorkQueueGtk.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/gtk/WorkQueueGtk.cpp	2015-05-05 08:16:16 UTC (rev 183800)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2015 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "Test.h"
+#include <gio/gio.h>
+#include <thread>
+#include <wtf/WorkQueue.h>
+#include <wtf/gobject/GRefPtr.h>
+#include <wtf/gobject/GUniquePtr.h>
+
+namespace TestWebKitAPI {
+
+TEST(WTF_WorkQueue, AsyncIO)
+{
+    struct TestingContext {
+        Mutex m_lock;
+        ThreadCondition m_testCompleted;
+        GMainContext* m_mainContext;
+    } context;
+
+    auto queue = WorkQueue::create("com.apple.WebKit.Test.AsyncIO");
+    context.m_mainContext = g_main_context_default();
+    EXPECT_FALSE(g_main_context_get_thread_default());
+
+    GUniquePtr<char> currentDirectory(g_get_current_dir());
+    GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(currentDirectory.get()));
+
+    MutexLocker locker(context.m_lock);
+    queue->dispatch([&](void) {
+        EXPECT_TRUE(g_main_context_get_thread_default());
+        EXPECT_TRUE(g_main_context_get_thread_default() != context.m_mainContext);
+        context.m_mainContext = g_main_context_get_thread_default();
+        g_file_query_info_async(file.get(), G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, nullptr,
+            [](GObject*, GAsyncResult*, gpointer userData) {
+                TestingContext* context = static_cast<TestingContext*>(userData);
+                MutexLocker locker(context->m_lock);
+                EXPECT_EQ(g_main_context_get_thread_default(), context->m_mainContext);
+                context->m_testCompleted.signal();
+            }, &context);
+    });
+
+    context.m_testCompleted.wait(context.m_lock);
+}
+
+} // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to