<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[242266] trunk/Source/WebKit</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/242266">242266</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2019-03-01 10:08:00 -0800 (Fri, 01 Mar 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>[ThreadedCompositor] Simply the compositing run loop worker thread
https://bugs.webkit.org/show_bug.cgi?id=195208

Patch by Carlos Garcia Campos <cgarcia@igalia.com> on 2019-03-01
Reviewed by Don Olmstead.

We can remove the WorkQueuePool, since we never really supported more than one thread, and now that single
process model non longer exists it doesn't even make sense. We can simply use a RunLoop instead of a WorkQueue
so that the implementation is not specific to the generic WorkQueue implementation.

* Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp:
(WebKit::createRunLoop): Helper function to create the RunLoop in a worker thread before m_updateTimer is initialized.
(WebKit::CompositingRunLoop::CompositingRunLoop): Use createRunLoop().
(WebKit::CompositingRunLoop::~CompositingRunLoop): Stop the worker thread run loop in the next main run loop iteration.
(WebKit::CompositingRunLoop::performTask): Use m_runLoop.
(WebKit::CompositingRunLoop::performTaskSync): Ditto.
(WebKit::WorkQueuePool::singleton): Deleted.
(WebKit::WorkQueuePool::dispatch): Deleted.
(WebKit::WorkQueuePool::runLoop): Deleted.
(WebKit::WorkQueuePool::invalidate): Deleted.
(WebKit::WorkQueuePool::WorkQueuePool): Deleted.
(WebKit::WorkQueuePool::getOrCreateWorkQueueForContext): Deleted.
(): Deleted.
* Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitSharedCoordinatedGraphicsthreadedcompositorCompositingRunLoopcpp">trunk/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp</a></li>
<li><a href="#trunkSourceWebKitSharedCoordinatedGraphicsthreadedcompositorCompositingRunLooph">trunk/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (242265 => 242266)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2019-03-01 17:57:56 UTC (rev 242265)
+++ trunk/Source/WebKit/ChangeLog       2019-03-01 18:08:00 UTC (rev 242266)
</span><span class="lines">@@ -1,3 +1,29 @@
</span><ins>+2019-03-01  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [ThreadedCompositor] Simply the compositing run loop worker thread
+        https://bugs.webkit.org/show_bug.cgi?id=195208
+
+        Reviewed by Don Olmstead.
+
+        We can remove the WorkQueuePool, since we never really supported more than one thread, and now that single
+        process model non longer exists it doesn't even make sense. We can simply use a RunLoop instead of a WorkQueue
+        so that the implementation is not specific to the generic WorkQueue implementation.
+
+        * Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp:
+        (WebKit::createRunLoop): Helper function to create the RunLoop in a worker thread before m_updateTimer is initialized.
+        (WebKit::CompositingRunLoop::CompositingRunLoop): Use createRunLoop().
+        (WebKit::CompositingRunLoop::~CompositingRunLoop): Stop the worker thread run loop in the next main run loop iteration.
+        (WebKit::CompositingRunLoop::performTask): Use m_runLoop.
+        (WebKit::CompositingRunLoop::performTaskSync): Ditto.
+        (WebKit::WorkQueuePool::singleton): Deleted.
+        (WebKit::WorkQueuePool::dispatch): Deleted.
+        (WebKit::WorkQueuePool::runLoop): Deleted.
+        (WebKit::WorkQueuePool::invalidate): Deleted.
+        (WebKit::WorkQueuePool::WorkQueuePool): Deleted.
+        (WebKit::WorkQueuePool::getOrCreateWorkQueueForContext): Deleted.
+        (): Deleted.
+        * Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.h:
+
</ins><span class="cx"> 2019-03-01  Justin Fan  <justin_fan@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [Web GPU] 32-bit builds broken by attempt to disable WebGPU on 32-bit
</span></span></pre></div>
<a id="trunkSourceWebKitSharedCoordinatedGraphicsthreadedcompositorCompositingRunLoopcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp (242265 => 242266)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp 2019-03-01 17:57:56 UTC (rev 242265)
+++ trunk/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp    2019-03-01 18:08:00 UTC (rev 242266)
</span><span class="lines">@@ -30,8 +30,8 @@
</span><span class="cx"> 
</span><span class="cx"> #include <wtf/HashMap.h>
</span><span class="cx"> #include <wtf/MainThread.h>
</span><del>-#include <wtf/NeverDestroyed.h>
-#include <wtf/WorkQueue.h>
</del><ins>+#include <wtf/Threading.h>
+#include <wtf/threads/BinarySemaphore.h>
</ins><span class="cx"> 
</span><span class="cx"> #if USE(GLIB_EVENT_LOOP)
</span><span class="cx"> #include <wtf/glib/RunLoopSourcePriority.h>
</span><span class="lines">@@ -39,74 +39,23 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><del>-class WorkQueuePool {
-    WTF_MAKE_NONCOPYABLE(WorkQueuePool);
-    friend NeverDestroyed<WorkQueuePool>;
-public:
-    static WorkQueuePool& singleton()
-    {
-        ASSERT(RunLoop::isMain());
-        static NeverDestroyed<WorkQueuePool> workQueuePool;
-        return workQueuePool;
-    }
</del><ins>+static RunLoop* createRunLoop()
+{
+    RunLoop* runLoop = nullptr;
+    BinarySemaphore semaphore;
+    Thread::create("org.webkit.ThreadedCompositor", [&] {
+        runLoop = &RunLoop::current();
+        semaphore.signal();
+        runLoop->run();
+    })->detach();
+    semaphore.wait();
</ins><span class="cx"> 
</span><del>-    void dispatch(void* context, Function<void ()>&& function)
-    {
-        ASSERT(RunLoop::isMain());
-        getOrCreateWorkQueueForContext(context).dispatch(WTFMove(function));
-    }
</del><ins>+    return runLoop;
+}
</ins><span class="cx"> 
</span><del>-    RunLoop& runLoop(void* context)
-    {
-        return getOrCreateWorkQueueForContext(context).runLoop();
-    }
-
-    void invalidate(void* context)
-    {
-        auto workQueue = m_workQueueMap.take(context);
-        ASSERT(workQueue);
-        if (m_workQueueMap.isEmpty()) {
-            m_sharedWorkQueue = nullptr;
-            m_threadCount = 0;
-        } else if (workQueue->hasOneRef())
-            m_threadCount--;
-    }
-
-private:
-    WorkQueuePool()
-    {
-        // FIXME: This is a sane default limit, but it should be configurable somehow.
-        m_threadCountLimit = 1;
-    }
-
-    WorkQueue& getOrCreateWorkQueueForContext(void* context)
-    {
-        auto addResult = m_workQueueMap.add(context, nullptr);
-        if (addResult.isNewEntry) {
-            // FIXME: This is OK for now, and it works for a single-thread limit. But for configurations where more (but not unlimited)
-            // threads could be used, one option would be to use a HashSet here and disperse the contexts across the available threads.
-            if (m_threadCount >= m_threadCountLimit) {
-                ASSERT(m_sharedWorkQueue);
-                addResult.iterator->value = m_sharedWorkQueue;
-            } else {
-                addResult.iterator->value = WorkQueue::create("org.webkit.ThreadedCompositorWorkQueue");
-                if (!m_threadCount)
-                    m_sharedWorkQueue = addResult.iterator->value;
-                m_threadCount++;
-            }
-        }
-
-        return *addResult.iterator->value;
-    }
-
-    HashMap<void*, RefPtr<WorkQueue>> m_workQueueMap;
-    RefPtr<WorkQueue> m_sharedWorkQueue;
-    unsigned m_threadCount { 0 };
-    unsigned m_threadCountLimit;
-};
-
</del><span class="cx"> CompositingRunLoop::CompositingRunLoop(Function<void ()>&& updateFunction)
</span><del>-    : m_updateTimer(WorkQueuePool::singleton().runLoop(this), this, &CompositingRunLoop::updateTimerFired)
</del><ins>+    : m_runLoop(createRunLoop())
+    , m_updateTimer(*m_runLoop, this, &CompositingRunLoop::updateTimerFired)
</ins><span class="cx">     , m_updateFunction(WTFMove(updateFunction))
</span><span class="cx"> {
</span><span class="cx"> #if USE(GLIB_EVENT_LOOP)
</span><span class="lines">@@ -118,16 +67,19 @@
</span><span class="cx"> CompositingRunLoop::~CompositingRunLoop()
</span><span class="cx"> {
</span><span class="cx">     ASSERT(RunLoop::isMain());
</span><del>-    // Make sure the WorkQueue is deleted after the CompositingRunLoop, because m_updateTimer has a reference
-    // of the WorkQueue run loop. Passing this is not a problem because the pointer will only be used as a
-    // HashMap key by WorkQueuePool.
-    RunLoop::main().dispatch([context = this] { WorkQueuePool::singleton().invalidate(context); });
</del><ins>+    // Make sure the RunLoop is stopped after the CompositingRunLoop, because m_updateTimer has a reference.
+    RunLoop::main().dispatch([runLoop = makeRef(*m_runLoop)] {
+        runLoop->stop();
+        runLoop->dispatch([] {
+            RunLoop::current().stop();
+        });
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void CompositingRunLoop::performTask(Function<void ()>&& function)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(RunLoop::isMain());
</span><del>-    WorkQueuePool::singleton().dispatch(this, WTFMove(function));
</del><ins>+    m_runLoop->dispatch(WTFMove(function));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void CompositingRunLoop::performTaskSync(Function<void ()>&& function)
</span><span class="lines">@@ -134,7 +86,7 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT(RunLoop::isMain());
</span><span class="cx">     LockHolder locker(m_dispatchSyncConditionMutex);
</span><del>-    WorkQueuePool::singleton().dispatch(this, [this, function = WTFMove(function)] {
</del><ins>+    m_runLoop->dispatch([this, function = WTFMove(function)] {
</ins><span class="cx">         function();
</span><span class="cx">         LockHolder locker(m_dispatchSyncConditionMutex);
</span><span class="cx">         m_dispatchSyncCondition.notifyOne();
</span></span></pre></div>
<a id="trunkSourceWebKitSharedCoordinatedGraphicsthreadedcompositorCompositingRunLooph"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.h (242265 => 242266)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.h   2019-03-01 17:57:56 UTC (rev 242265)
+++ trunk/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.h      2019-03-01 18:08:00 UTC (rev 242266)
</span><span class="lines">@@ -70,12 +70,12 @@
</span><span class="cx"> 
</span><span class="cx">     void updateTimerFired();
</span><span class="cx"> 
</span><ins>+    RunLoop* m_runLoop { nullptr };
</ins><span class="cx">     RunLoop::Timer<CompositingRunLoop> m_updateTimer;
</span><span class="cx">     Function<void ()> m_updateFunction;
</span><span class="cx">     Lock m_dispatchSyncConditionMutex;
</span><span class="cx">     Condition m_dispatchSyncCondition;
</span><span class="cx"> 
</span><del>-
</del><span class="cx">     struct {
</span><span class="cx">         Lock lock;
</span><span class="cx">         CompositionState composition { CompositionState::Idle };
</span></span></pre>
</div>
</div>

</body>
</html>