[GTK] Move the socket polling off the WorkQueue
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Oct 2015 12:46:55 +0000 (12:46 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Oct 2015 12:46:55 +0000 (12:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150593

Reviewed by Anders Carlsson.

Source/WebKit2:

Create the socket poll source in Connection::open and attach it to
the connection work queue context.

* Platform/IPC/Connection.h:
* Platform/IPC/unix/ConnectionUnix.cpp:
(IPC::Connection::platformInvalidate):
(IPC::Connection::open):

Source/WTF:

It doesn't really belong to the WorkQueue, it's only used by the
WebKit2 connection, so it can be moved there.

* wtf/WorkQueue.h:
* wtf/glib/WorkQueueGLib.cpp:
(WTF::WorkQueue::registerSocketEventHandler): Deleted.
(WTF::WorkQueue::unregisterSocketEventHandler): Deleted.

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

Source/WTF/ChangeLog
Source/WTF/wtf/WorkQueue.h
Source/WTF/wtf/glib/WorkQueueGLib.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/Platform/IPC/Connection.h
Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp

index 748f2fe855c6ecdad81a1f3f96f7f3497045a205..06649315dc1565ee157ce5a8e67d60e6e4a7559b 100644 (file)
@@ -1,3 +1,18 @@
+2015-10-30  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Move the socket polling off the WorkQueue
+        https://bugs.webkit.org/show_bug.cgi?id=150593
+
+        Reviewed by Anders Carlsson.
+
+        It doesn't really belong to the WorkQueue, it's only used by the
+        WebKit2 connection, so it can be moved there.
+
+        * wtf/WorkQueue.h:
+        * wtf/glib/WorkQueueGLib.cpp:
+        (WTF::WorkQueue::registerSocketEventHandler): Deleted.
+        (WTF::WorkQueue::unregisterSocketEventHandler): Deleted.
+
 2015-10-29  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Use a persistent main loop source in RunLoop glib implementation
index 2b9bd3ecc0c0e6c19de232203b2e2b4fd5d1193e..1f12d4b924a2cbf424f05b2ec04cdd3c706c6029 100644 (file)
@@ -76,8 +76,7 @@ public:
 #if OS(DARWIN)
     dispatch_queue_t dispatchQueue() const { return m_dispatchQueue; }
 #elif PLATFORM(GTK)
-    void registerSocketEventHandler(int, std::function<void ()>, std::function<void ()>);
-    void unregisterSocketEventHandler(int);
+    GMainContext* mainContext() const { return m_eventContext.get(); }
 #elif PLATFORM(EFL)
     void registerSocketEventHandler(int, std::function<void ()>);
     void unregisterSocketEventHandler(int);
@@ -109,7 +108,6 @@ private:
     ThreadIdentifier m_workQueueThread;
     GRefPtr<GMainContext> m_eventContext;
     GRefPtr<GMainLoop> m_eventLoop;
-    GMainLoopSource m_socketEventSource;
 #elif PLATFORM(EFL)
     RefPtr<DispatchQueue> m_dispatchQueue;
 #elif OS(WINDOWS)
index ee1b60baf5d068ba2cead3d81148fb4a2c7c41b2..39d3bf9311da6c61ffdec37c678f78f851b8f3e3 100644 (file)
@@ -28,7 +28,7 @@
 #include "config.h"
 #include "WorkQueue.h"
 
-#include <gio/gio.h>
+#include <glib.h>
 #include <string.h>
 
 namespace WTF {
@@ -84,33 +84,6 @@ void WorkQueue::platformInvalidate()
     m_eventContext = nullptr;
 }
 
-void WorkQueue::registerSocketEventHandler(int fileDescriptor, std::function<void ()> function, std::function<void ()> closeFunction)
-{
-    GRefPtr<GSocket> socket = adoptGRef(g_socket_new_from_fd(fileDescriptor, 0));
-    ref();
-    m_socketEventSource.schedule("[WebKit] WorkQueue::SocketEventHandler", [function, closeFunction](GIOCondition condition) {
-            if (condition & G_IO_HUP || condition & G_IO_ERR || condition & G_IO_NVAL) {
-                closeFunction();
-                return GMainLoopSource::Stop;
-            }
-
-            if (condition & G_IO_IN) {
-                function();
-                return GMainLoopSource::Continue;
-            }
-
-            ASSERT_NOT_REACHED();
-            return GMainLoopSource::Stop;
-        }, socket.get(), G_IO_IN,
-        [this] { deref(); },
-        m_eventContext.get());
-}
-
-void WorkQueue::unregisterSocketEventHandler(int)
-{
-    m_socketEventSource.cancel();
-}
-
 void WorkQueue::dispatch(std::function<void ()> function)
 {
     ref();
index 24fa00c36902eb5865007d9312c69897fcb27ac4..9e281dbc282300e9347201e6dc0659511521488c 100644 (file)
@@ -1,3 +1,18 @@
+2015-10-30  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Move the socket polling off the WorkQueue
+        https://bugs.webkit.org/show_bug.cgi?id=150593
+
+        Reviewed by Anders Carlsson.
+
+        Create the socket poll source in Connection::open and attach it to
+        the connection work queue context.
+
+        * Platform/IPC/Connection.h:
+        * Platform/IPC/unix/ConnectionUnix.cpp:
+        (IPC::Connection::platformInvalidate):
+        (IPC::Connection::open):
+
 2015-10-30  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Use RunLoop::Timer instead of GMainLoopSource
index df36ea0209fac317621d87bc784db7d66b77402f..f3466e23c0e3a9616fbc3805a5bdf15fb9cd5db5 100644 (file)
 #include "PlatformProcessIdentifier.h"
 #endif
 
+#if PLATFORM(GTK)
+#include <wtf/glib/GMainLoopSource.h>
+#endif
+
 namespace IPC {
 
 struct WaitForMessageState;
@@ -354,6 +358,9 @@ private:
     Vector<int> m_fileDescriptors;
     size_t m_fileDescriptorsSize;
     int m_socketDescriptor;
+#if PLATFORM(GTK)
+    GMainLoopSource m_socketEventSource;
+#endif
 #endif
 };
 
index 2e72c596eda09df5302bb037661c6fa054abf60a..21792ffbd68914bb8624a34e4511f907fdb5030e 100644 (file)
@@ -40,7 +40,7 @@
 #include <wtf/UniStdExtras.h>
 
 #if PLATFORM(GTK)
-#include <glib.h>
+#include <gio/gio.h>
 #endif
 
 #ifdef SOCK_SEQPACKET
@@ -147,7 +147,9 @@ void Connection::platformInvalidate()
     if (!m_isConnected)
         return;
 
-#if PLATFORM(GTK) || PLATFORM(EFL)
+#if PLATFORM(GTK)
+    m_socketEventSource.cancel();
+#elif PLATFORM(EFL)
     m_connectionQueue->unregisterSocketEventHandler(m_socketDescriptor);
 #endif
 
@@ -374,13 +376,21 @@ bool Connection::open()
     RefPtr<Connection> protectedThis(this);
     m_isConnected = true;
 #if PLATFORM(GTK)
-    m_connectionQueue->registerSocketEventHandler(m_socketDescriptor,
-        [protectedThis] {
-            protectedThis->readyReadHandler();
-        },
-        [protectedThis] {
+    GRefPtr<GSocket> socket = adoptGRef(g_socket_new_from_fd(m_socketDescriptor, nullptr));
+    m_socketEventSource.schedule("[WebKit] Connection::SocketEventHandler", [protectedThis] (GIOCondition condition) {
+        if (condition & G_IO_HUP || condition & G_IO_ERR || condition & G_IO_NVAL) {
             protectedThis->connectionDidClose();
-        });
+            return GMainLoopSource::Stop;
+        }
+
+        if (condition & G_IO_IN) {
+            protectedThis->readyReadHandler();
+            return GMainLoopSource::Continue;
+        }
+
+        ASSERT_NOT_REACHED();
+        return GMainLoopSource::Stop;
+    }, socket.get(), G_IO_IN, nullptr, m_connectionQueue->mainContext());
 #elif PLATFORM(EFL)
     m_connectionQueue->registerSocketEventHandler(m_socketDescriptor,
         [protectedThis] {