Title: [184072] trunk/Source/WTF
Revision
184072
Author
[email protected]
Date
2015-05-11 03:21:40 -0700 (Mon, 11 May 2015)

Log Message

[GTK] WorkQueue objects are not released
https://bugs.webkit.org/show_bug.cgi?id=144824

Reviewed by Žan Doberšek.

Do not keep a reference of the WorkQueue for the entire life of
its worker thread, since every task scheduled on the WorkQueue
already takes a reference. Instead, take a reference of the main
loop to make sure that when the worker thread starts, the main
loop hasn't been released to avoid runtime warnings (see
webkit.org/b/140998). Also removed the g_main_context_pop_thread_default()
from the thread body, since the thread-specific context queue will
be freed anyway when the thread exits.
If the WorkQueue is released early, before the thread has started,
schedule a main loop quit in the context, to make sure it will
be the first thing run by the main loop and the thread will exit.

* wtf/WorkQueue.h: Remove unused event loop mutex.
* wtf/gtk/WorkQueueGtk.cpp:
(WTF::WorkQueue::platformInitialize):
(WTF::WorkQueue::platformInvalidate):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (184071 => 184072)


--- trunk/Source/WTF/ChangeLog	2015-05-11 09:38:25 UTC (rev 184071)
+++ trunk/Source/WTF/ChangeLog	2015-05-11 10:21:40 UTC (rev 184072)
@@ -1,3 +1,27 @@
+2015-05-11  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] WorkQueue objects are not released
+        https://bugs.webkit.org/show_bug.cgi?id=144824
+
+        Reviewed by Žan Doberšek.
+
+        Do not keep a reference of the WorkQueue for the entire life of
+        its worker thread, since every task scheduled on the WorkQueue
+        already takes a reference. Instead, take a reference of the main
+        loop to make sure that when the worker thread starts, the main
+        loop hasn't been released to avoid runtime warnings (see
+        webkit.org/b/140998). Also removed the g_main_context_pop_thread_default()
+        from the thread body, since the thread-specific context queue will
+        be freed anyway when the thread exits.
+        If the WorkQueue is released early, before the thread has started,
+        schedule a main loop quit in the context, to make sure it will
+        be the first thing run by the main loop and the thread will exit.
+
+        * wtf/WorkQueue.h: Remove unused event loop mutex.
+        * wtf/gtk/WorkQueueGtk.cpp:
+        (WTF::WorkQueue::platformInitialize):
+        (WTF::WorkQueue::platformInvalidate):
+
 2015-05-09  Yoav Weiss  <[email protected]>
 
         Remove the PICTURE_SIZES build flag

Modified: trunk/Source/WTF/wtf/WorkQueue.h (184071 => 184072)


--- trunk/Source/WTF/wtf/WorkQueue.h	2015-05-11 09:38:25 UTC (rev 184071)
+++ trunk/Source/WTF/wtf/WorkQueue.h	2015-05-11 10:21:40 UTC (rev 184072)
@@ -106,7 +106,6 @@
 #elif PLATFORM(GTK)
     ThreadIdentifier m_workQueueThread;
     GRefPtr<GMainContext> m_eventContext;
-    Mutex m_eventLoopLock;
     GRefPtr<GMainLoop> m_eventLoop;
     GMainLoopSource m_socketEventSource;
 #elif PLATFORM(EFL)

Modified: trunk/Source/WTF/wtf/gtk/WorkQueueGtk.cpp (184071 => 184072)


--- trunk/Source/WTF/wtf/gtk/WorkQueueGtk.cpp	2015-05-11 09:38:25 UTC (rev 184071)
+++ trunk/Source/WTF/wtf/gtk/WorkQueueGtk.cpp	2015-05-11 10:21:40 UTC (rev 184072)
@@ -55,11 +55,10 @@
     if (strlen(threadName) > kVisualStudioThreadNameLimit)
         threadName += strlen(threadName) - kVisualStudioThreadNameLimit;
 
-    RefPtr<WorkQueue> protector(this);
-    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());
+    GRefPtr<GMainLoop> eventLoop(m_eventLoop.get());
+    m_workQueueThread = createThread(threadName, [eventLoop] {
+        g_main_context_push_thread_default(g_main_loop_get_context(eventLoop.get()));
+        g_main_loop_run(eventLoop.get());
     });
 }
 
@@ -70,14 +69,19 @@
         m_workQueueThread = 0;
     }
 
-    MutexLocker locker(m_eventLoopLock);
     if (m_eventLoop) {
         if (g_main_loop_is_running(m_eventLoop.get()))
             g_main_loop_quit(m_eventLoop.get());
-        m_eventLoop.clear();
+        else {
+            // The thread hasn't started yet, so schedule a main loop quit to ensure the thread finishes.
+            GMainLoop* eventLoop = m_eventLoop.get();
+            GMainLoopSource::scheduleAndDeleteOnDestroy("[WebKit] WorkQueue quit main loop", [eventLoop] { g_main_loop_quit(eventLoop); },
+                G_PRIORITY_HIGH, nullptr, m_eventContext.get());
+        }
+        m_eventLoop = nullptr;
     }
 
-    m_eventContext.clear();
+    m_eventContext = nullptr;
 }
 
 void WorkQueue::registerSocketEventHandler(int fileDescriptor, std::function<void ()> function, std::function<void ()> closeFunction)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to