[GTK] Use Generic WorkQueue instead of WorkQueueGLib
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Apr 2016 09:16:40 +0000 (09:16 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Apr 2016 09:16:40 +0000 (09:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=156721

Reviewed by Benjamin Poulain.

WorkQueueGLib includes platform-dependent part only for WorkQueue::dispatchAfter.
However, its code is related to RunLoopGLib rather than WorkQueueGLib.
In this patch, we move the code from WorkQueueGLib to RunLoopGLib, drop WorkQueueGLib
and use WorkQueueGeneric.

* wtf/PlatformGTK.cmake:
* wtf/RunLoop.h:
* wtf/WorkQueue.h:
* wtf/glib/RunLoopGLib.cpp:
(WTF::DispatchAfterContext::DispatchAfterContext):
(WTF::DispatchAfterContext::dispatch):
(WTF::RunLoop::dispatchAfter):
* wtf/glib/WorkQueueGLib.cpp: Removed.
(WTF::WorkQueue::platformInitialize): Deleted.
(WTF::WorkQueue::platformInvalidate): Deleted.
(WTF::WorkQueue::dispatch): Deleted.
(WTF::DispatchAfterContext::DispatchAfterContext): Deleted.
(WTF::DispatchAfterContext::~DispatchAfterContext): Deleted.
(WTF::DispatchAfterContext::dispatch): Deleted.
(WTF::WorkQueue::dispatchAfter): Deleted.

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

Source/WTF/ChangeLog
Source/WTF/wtf/PlatformGTK.cmake
Source/WTF/wtf/RunLoop.h
Source/WTF/wtf/WorkQueue.h
Source/WTF/wtf/glib/RunLoopGLib.cpp
Source/WTF/wtf/glib/WorkQueueGLib.cpp [deleted file]

index 79288f8..419a330 100644 (file)
@@ -1,3 +1,31 @@
+2016-04-19  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [GTK] Use Generic WorkQueue instead of WorkQueueGLib
+        https://bugs.webkit.org/show_bug.cgi?id=156721
+
+        Reviewed by Benjamin Poulain.
+
+        WorkQueueGLib includes platform-dependent part only for WorkQueue::dispatchAfter.
+        However, its code is related to RunLoopGLib rather than WorkQueueGLib.
+        In this patch, we move the code from WorkQueueGLib to RunLoopGLib, drop WorkQueueGLib
+        and use WorkQueueGeneric.
+
+        * wtf/PlatformGTK.cmake:
+        * wtf/RunLoop.h:
+        * wtf/WorkQueue.h:
+        * wtf/glib/RunLoopGLib.cpp:
+        (WTF::DispatchAfterContext::DispatchAfterContext):
+        (WTF::DispatchAfterContext::dispatch):
+        (WTF::RunLoop::dispatchAfter):
+        * wtf/glib/WorkQueueGLib.cpp: Removed.
+        (WTF::WorkQueue::platformInitialize): Deleted.
+        (WTF::WorkQueue::platformInvalidate): Deleted.
+        (WTF::WorkQueue::dispatch): Deleted.
+        (WTF::DispatchAfterContext::DispatchAfterContext): Deleted.
+        (WTF::DispatchAfterContext::~DispatchAfterContext): Deleted.
+        (WTF::DispatchAfterContext::dispatch): Deleted.
+        (WTF::WorkQueue::dispatchAfter): Deleted.
+
 2016-04-18  Yusuke Suzuki  <utatane.tea@gmail.com>
 
         [JSCOnly] Implement RunLoop and remove glib dependency
index cc7df7c..1115904 100644 (file)
@@ -2,11 +2,11 @@ set(WTF_LIBRARY_TYPE STATIC)
 set(WTF_OUTPUT_NAME WTFGTK)
 
 list(APPEND WTF_SOURCES
+    generic/WorkQueueGeneric.cpp
     glib/GLibUtilities.cpp
     glib/GRefPtr.cpp
     glib/MainThreadGLib.cpp
     glib/RunLoopGLib.cpp
-    glib/WorkQueueGLib.cpp
 )
 
 list(APPEND WTF_LIBRARIES
index fc85a2b..060b811 100644 (file)
@@ -76,6 +76,9 @@ public:
 #if USE(GENERIC_EVENT_LOOP)
     // Run the single iteration of the RunLoop. It consumes the pending tasks and expired timers, but it won't be blocked.
     WTF_EXPORT_PRIVATE static void iterate();
+#endif
+
+#if USE(GLIB_EVENT_LOOP) || USE(GENERIC_EVENT_LOOP)
     WTF_EXPORT_PRIVATE void dispatchAfter(std::chrono::nanoseconds, std::function<void()>);
 #endif
 
index 78cdac9..c4ea72e 100644 (file)
 #include <wtf/win/WorkItemWin.h>
 #endif
 
-#if USE(GLIB_EVENT_LOOP)
-#include <wtf/glib/GRefPtr.h>
-#endif
-
 #if USE(GLIB_EVENT_LOOP) || USE(GENERIC_EVENT_LOOP)
 #include <wtf/Condition.h>
 #include <wtf/RunLoop.h>
index 63c0318..39a21dd 100644 (file)
@@ -121,6 +121,37 @@ void RunLoop::wakeUp()
     g_source_set_ready_time(m_source.get(), g_get_monotonic_time());
 }
 
+class DispatchAfterContext {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    DispatchAfterContext(std::function<void()>&& function)
+        : m_function(WTFMove(function))
+    {
+    }
+
+    void dispatch()
+    {
+        m_function();
+    }
+
+private:
+    std::function<void()> m_function;
+};
+
+void RunLoop::dispatchAfter(std::chrono::nanoseconds duration, std::function<void()> function)
+{
+    GRefPtr<GSource> source = adoptGRef(g_timeout_source_new(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count()));
+    g_source_set_name(source.get(), "[WebKit] RunLoop dispatchAfter");
+
+    std::unique_ptr<DispatchAfterContext> context = std::make_unique<DispatchAfterContext>(WTFMove(function));
+    g_source_set_callback(source.get(), [](gpointer userData) -> gboolean {
+        std::unique_ptr<DispatchAfterContext> context(static_cast<DispatchAfterContext*>(userData));
+        context->dispatch();
+        return G_SOURCE_REMOVE;
+    }, context.release(), nullptr);
+    g_source_attach(source.get(), m_mainContext.get());
+}
+
 RunLoop::TimerBase::TimerBase(RunLoop& runLoop)
     : m_runLoop(runLoop)
     , m_source(adoptGRef(g_source_new(&runLoopSourceFunctions, sizeof(GSource))))
diff --git a/Source/WTF/wtf/glib/WorkQueueGLib.cpp b/Source/WTF/wtf/glib/WorkQueueGLib.cpp
deleted file mode 100644 (file)
index 632ff40..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (C) 2011 Igalia S.L.
- * Copyright (C) 2010 Apple Inc. All rights reserved.
- * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
- *
- * 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 "WorkQueue.h"
-
-#include <glib.h>
-#include <string.h>
-
-namespace WTF {
-
-static const size_t kVisualStudioThreadNameLimit = 31;
-
-void WorkQueue::platformInitialize(const char* name, Type, QOS)
-{
-    // This name can be com.apple.WebKit.ProcessLauncher or com.apple.CoreIPC.ReceiveQueue.
-    // We are using those names for the thread name, but both are longer than 31 characters,
-    // which is the limit of Visual Studio for thread names.
-    // When log is enabled createThread() will assert instead of truncate the name, so we need
-    // to make sure we don't use a name longer than 31 characters.
-    const char* threadName = g_strrstr(name, ".");
-    if (threadName)
-        threadName++;
-    else
-        threadName = name;
-    if (strlen(threadName) > kVisualStudioThreadNameLimit)
-        threadName += strlen(threadName) - kVisualStudioThreadNameLimit;
-
-    LockHolder locker(m_initializeRunLoopConditionMutex);
-    m_workQueueThread = createThread(threadName, [this] {
-        {
-            LockHolder locker(m_initializeRunLoopConditionMutex);
-            m_runLoop = &RunLoop::current();
-            m_initializeRunLoopCondition.notifyOne();
-        }
-        m_runLoop->run();
-        {
-            LockHolder locker(m_terminateRunLoopConditionMutex);
-            m_runLoop = nullptr;
-            m_terminateRunLoopCondition.notifyOne();
-        }
-    });
-    m_initializeRunLoopCondition.wait(m_initializeRunLoopConditionMutex);
-}
-
-void WorkQueue::platformInvalidate()
-{
-    {
-        LockHolder locker(m_terminateRunLoopConditionMutex);
-        if (m_runLoop) {
-            m_runLoop->stop();
-            m_terminateRunLoopCondition.wait(m_terminateRunLoopConditionMutex);
-        }
-    }
-
-    if (m_workQueueThread) {
-        detachThread(m_workQueueThread);
-        m_workQueueThread = 0;
-    }
-}
-
-void WorkQueue::dispatch(std::function<void ()> function)
-{
-    RefPtr<WorkQueue> protector(this);
-    m_runLoop->dispatch([protector, function] { function(); });
-}
-
-class DispatchAfterContext {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    DispatchAfterContext(WorkQueue& queue, std::function<void ()> function)
-        : m_queue(&queue)
-        , m_function(WTFMove(function))
-    {
-    }
-
-    ~DispatchAfterContext()
-    {
-    }
-
-    void dispatch()
-    {
-        m_function();
-    }
-
-private:
-    RefPtr<WorkQueue> m_queue;
-    std::function<void ()> m_function;
-};
-
-void WorkQueue::dispatchAfter(std::chrono::nanoseconds duration, std::function<void ()> function)
-{
-    GRefPtr<GSource> source = adoptGRef(g_timeout_source_new(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count()));
-    g_source_set_name(source.get(), "[WebKit] WorkQueue dispatchAfter");
-
-    std::unique_ptr<DispatchAfterContext> context = std::make_unique<DispatchAfterContext>(*this, WTFMove(function));
-    g_source_set_callback(source.get(), [](gpointer userData) -> gboolean {
-        std::unique_ptr<DispatchAfterContext> context(static_cast<DispatchAfterContext*>(userData));
-        context->dispatch();
-        return G_SOURCE_REMOVE;
-    }, context.release(), nullptr);
-    g_source_attach(source.get(), m_runLoop->mainContext());
-}
-
-}