WebKit Bugzilla
Attachment 342125 Details for
Bug 174569
: [WTF] Add WorkerPool
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-174569-20180607152301.patch (text/plain), 23.51 KB, created by
Yusuke Suzuki
on 2018-06-06 23:23:03 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Yusuke Suzuki
Created:
2018-06-06 23:23:03 PDT
Size:
23.51 KB
patch
obsolete
>Subversion Revision: 232572 >diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index 05db42447c58fa0bf37e7a8e514eaff731767a85..488e347440222798682e0ca58e54dc1a75933865 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,30 @@ >+2018-06-06 Yusuke Suzuki <utatane.tea@gmail.com> >+ >+ [WTF] Add WorkerPool >+ https://bugs.webkit.org/show_bug.cgi?id=174569 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * wtf/AutomaticThread.cpp: >+ (WTF::AutomaticThread::AutomaticThread): >+ (WTF::AutomaticThread::start): >+ * wtf/AutomaticThread.h: >+ * wtf/CMakeLists.txt: >+ * wtf/ThreadPool.cpp: Added. >+ (WTF::ThreadPool::ThreadPool): >+ (WTF::ThreadPool::postTask): >+ * wtf/ThreadPool.h: Added. >+ (WTF::ThreadPool::numberOfThreads const): >+ * wtf/WorkerPool.cpp: Added. >+ (WTF::WorkerPool::Worker::Worker): >+ (WTF::WorkerPool::Worker::threadIsStopping): >+ (WTF::WorkerPool::WorkerPool): >+ (WTF::WorkerPool::~WorkerPool): >+ (WTF::WorkerPool::shouldSleep): >+ (WTF::WorkerPool::postTask): >+ * wtf/WorkerPool.h: Added. >+ (WTF::WorkerPool::create): >+ > 2018-06-05 Darin Adler <darin@apple.com> > > [Cocoa] Retire DispatchPtr, and add more move semantics and simpler #ifs to other smart pointers >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index c27e6b45d67d7e440f531184f5f62fab7492d17d..f787955c4b842bc219aecd2d197d27e3eea879b2 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,17 @@ >+2018-06-06 Yusuke Suzuki <utatane.tea@gmail.com> >+ >+ [WTF] Add WorkerPool >+ https://bugs.webkit.org/show_bug.cgi?id=174569 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * platform/graphics/nicosia/NicosiaPaintingEngineThreaded.cpp: >+ (Nicosia::PaintingEngineThreaded::PaintingEngineThreaded): >+ (Nicosia::PaintingEngineThreaded::~PaintingEngineThreaded): >+ (Nicosia::PaintingEngineThreaded::paint): >+ (Nicosia::s_threadFunc): Deleted. >+ * platform/graphics/nicosia/NicosiaPaintingEngineThreaded.h: >+ > 2018-06-06 Youenn Fablet <youenn@apple.com> > > HTTP Header values validation is too strict >diff --git a/Source/WTF/wtf/AutomaticThread.cpp b/Source/WTF/wtf/AutomaticThread.cpp >index 2c486c4808aae32858dd2b2264484726aa9a99b9..a59c5d1bc969240d8c7addccc2cbb471e9e70187 100644 >--- a/Source/WTF/wtf/AutomaticThread.cpp >+++ b/Source/WTF/wtf/AutomaticThread.cpp >@@ -104,9 +104,10 @@ bool AutomaticThreadCondition::contains(const AbstractLocker&, AutomaticThread* > return m_threads.contains(thread); > } > >-AutomaticThread::AutomaticThread(const AbstractLocker& locker, Box<Lock> lock, RefPtr<AutomaticThreadCondition> condition) >+AutomaticThread::AutomaticThread(const AbstractLocker& locker, Box<Lock> lock, RefPtr<AutomaticThreadCondition> condition, Seconds timeout) > : m_lock(lock) > , m_condition(condition) >+ , m_timeout(timeout) > { > if (verbose) > dataLog(RawPointer(this), ": Allocated AutomaticThread.\n"); >@@ -204,10 +205,10 @@ void AutomaticThread::start(const AbstractLocker&) > // Shut the thread down after a timeout. > m_isWaiting = true; > bool awokenByNotify = >- m_waitCondition.waitFor(*m_lock, 10_s); >+ m_waitCondition.waitFor(*m_lock, m_timeout); > if (verbose && !awokenByNotify && !m_isWaiting) > dataLog(RawPointer(this), ": waitFor timed out, but notified via m_isWaiting flag!\n"); >- if (m_isWaiting) { >+ if (m_isWaiting && shouldSleep(locker)) { > m_isWaiting = false; > if (verbose) > dataLog(RawPointer(this), ": Going to sleep!\n"); >diff --git a/Source/WTF/wtf/AutomaticThread.h b/Source/WTF/wtf/AutomaticThread.h >index 1b904540c7f6046b0752afe975d22a3b4a2c8b8a..ff54f31741be78fd3a52ce4247671874b2cd6dc9 100644 >--- a/Source/WTF/wtf/AutomaticThread.h >+++ b/Source/WTF/wtf/AutomaticThread.h >@@ -129,7 +129,7 @@ class WTF_EXPORT_PRIVATE AutomaticThread : public ThreadSafeRefCounted<Automatic > protected: > // This logically creates the thread, but in reality the thread won't be created until someone > // calls AutomaticThreadCondition::notifyOne() or notifyAll(). >- AutomaticThread(const AbstractLocker&, Box<Lock>, RefPtr<AutomaticThreadCondition>); >+ AutomaticThread(const AbstractLocker&, Box<Lock>, RefPtr<AutomaticThreadCondition>, Seconds timeout = 10_s); > > // To understand PollResult and WorkResult, imagine that poll() and work() are being called like > // so: >@@ -168,6 +168,11 @@ class WTF_EXPORT_PRIVATE AutomaticThread : public ThreadSafeRefCounted<Automatic > // can be sure that the default ones don't do anything (so you don't need a super call). > virtual void threadDidStart(); > virtual void threadIsStopping(const AbstractLocker&); >+ >+ // Control whether this automatic thread should sleep when timeout happens. >+ // By overriding this function, we can customize how automatic threads will sleep. >+ // For example, when you have thread pool, you can decrease active threads moderately. >+ virtual bool shouldSleep(const AbstractLocker&) { return true; } > > private: > friend class AutomaticThreadCondition; >@@ -181,6 +186,7 @@ class WTF_EXPORT_PRIVATE AutomaticThread : public ThreadSafeRefCounted<Automatic > bool m_hasUnderlyingThread { false }; > Condition m_waitCondition; > Condition m_isRunningCondition; >+ Seconds m_timeout; > }; > > } // namespace WTF >diff --git a/Source/WTF/wtf/CMakeLists.txt b/Source/WTF/wtf/CMakeLists.txt >index 6ce617a7b4dca4048b57a26286361d4577333b3a..0f9f4e1f2da16c312c0dd52d8dbe953b554d344d 100644 >--- a/Source/WTF/wtf/CMakeLists.txt >+++ b/Source/WTF/wtf/CMakeLists.txt >@@ -256,6 +256,7 @@ set(WTF_PUBLIC_HEADERS > WindowsExtras.h > WordLock.h > WorkQueue.h >+ WorkerPool.h > dtoa.h > > dtoa/bignum-dtoa.h >@@ -390,6 +391,7 @@ set(WTF_SOURCES > WallTime.cpp > WordLock.cpp > WorkQueue.cpp >+ WorkerPool.cpp > dtoa.cpp > > dtoa/bignum-dtoa.cc >diff --git a/Source/WTF/wtf/ThreadPool.cpp b/Source/WTF/wtf/ThreadPool.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..ea41802cd41e4f12e8da68884f51a0a727a369a8 >--- /dev/null >+++ b/Source/WTF/wtf/ThreadPool.cpp >@@ -0,0 +1,39 @@ >+/* >+ * Copyright (C) 2018 Yusuke Suzuki <utatane.tea@gmail.com>. >+ * >+ * 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. ``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 >+ * 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 "ThreadPool.h" >+ >+namespace WTF { >+ >+ThreadPool::ThreadPool(unsigned numberOfThreads) >+{ >+} >+ >+void ThreadPool::postTask(Function<void()> task) >+{ >+} >+ >+} >diff --git a/Source/WTF/wtf/ThreadPool.h b/Source/WTF/wtf/ThreadPool.h >new file mode 100644 >index 0000000000000000000000000000000000000000..c741ecded71bd55fb2479c859ab91671dd729e07 >--- /dev/null >+++ b/Source/WTF/wtf/ThreadPool.h >@@ -0,0 +1,50 @@ >+/* >+ * Copyright (C) 2017 Yusuke Suzuki <utatane.tea@gmail.com>. >+ * >+ * 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. ``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 >+ * 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. >+ */ >+ >+#pragma once >+ >+#include <wtf/Noncopyable.h> >+#include <wtf/Vector.h> >+ >+namespace WTF { >+ >+class ThreadPool { >+ WTF_MAKE_FAST_ALLOCATED; >+ WTF_MAKE_NONCOPYABLE(ThreadPool); >+public: >+ ThreadPool(unsigned numberOfThreads); >+ ~ThreadPool(); >+ >+ unsigned numberOfThreads() const { return m_threads.size(); } >+ >+ void postTask(Function<void()>); >+ >+private: >+ Vector<Ref<Thread>> m_threads; >+}; >+ >+} >+ >+using WTF::ThreadPool; >diff --git a/Source/WTF/wtf/WorkerPool.cpp b/Source/WTF/wtf/WorkerPool.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..55a236e4f26cf9aeee8b2bdf250e4a60fa53ce4d >--- /dev/null >+++ b/Source/WTF/wtf/WorkerPool.cpp >@@ -0,0 +1,124 @@ >+/* >+ * Copyright (C) 2017 Yusuke Suzuki <utatane.tea@gmail.com>. >+ * >+ * 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. ``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 >+ * 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 "WorkerPool.h" >+ >+#include <wtf/NeverDestroyed.h> >+ >+namespace WTF { >+ >+class WorkerPool::Worker : public AutomaticThread { >+public: >+ friend class WorkerPool; >+ >+ Worker(const AbstractLocker& locker, WorkerPool& pool, Box<Lock> lock, RefPtr<AutomaticThreadCondition> condition, Seconds timeout) >+ : AutomaticThread(locker, lock, condition, timeout) >+ , m_pool(pool) >+ { >+ } >+ >+ PollResult poll(const AbstractLocker&) override >+ { >+ if (m_pool.m_tasks.isEmpty()) >+ return PollResult::Wait; >+ m_task = m_pool.m_tasks.takeFirst(); >+ if (!m_task) >+ return PollResult::Stop; >+ return PollResult::Work; >+ } >+ >+ WorkResult work() override >+ { >+ m_task(); >+ m_task = nullptr; >+ return WorkResult::Continue; >+ } >+ >+ void threadDidStart() override >+ { >+ LockHolder locker(*m_pool.m_lock); >+ m_pool.m_numberOfActiveWorkers++; >+ } >+ >+ virtual void threadIsStopping(const AbstractLocker&) >+ { >+ m_pool.m_numberOfActiveWorkers--; >+ } >+ >+ bool shouldSleep(const AbstractLocker& locker) override >+ { >+ return m_pool.shouldSleep(locker); >+ } >+ >+private: >+ WorkerPool& m_pool; >+ Function<void()> m_task; >+}; >+ >+WorkerPool::WorkerPool(unsigned numberOfWorkers, Seconds timeout) >+ : m_lock(Box<Lock>::create()) >+ , m_condition(AutomaticThreadCondition::create()) >+ , m_timeout(timeout) >+{ >+ LockHolder locker(*m_lock); >+ for (unsigned i = 0; i < numberOfWorkers; ++i) >+ m_workers.append(adoptRef(*new Worker(locker, *this, m_lock, m_condition, timeout))); >+} >+ >+WorkerPool::~WorkerPool() >+{ >+ { >+ LockHolder locker(*m_lock); >+ for (unsigned i = m_workers.size(); i--;) >+ m_tasks.append(nullptr); // Use null task to indicate that we want the thread to terminate. >+ m_condition->notifyAll(locker); >+ } >+ for (auto& worker : m_workers) >+ worker->join(); >+ ASSERT(!m_numberOfActiveWorkers); >+} >+ >+bool WorkerPool::shouldSleep(const AbstractLocker&) >+{ >+ if (m_timeout > 0_s && std::isinf(m_timeout)) >+ return false; >+ >+ MonotonicTime currentTime = MonotonicTime::now(); >+ if (std::isnan(m_lastTimeoutTime) || (currentTime >= (m_lastTimeoutTime + m_timeout))) { >+ m_lastTimeoutTime = currentTime; >+ return true; >+ } >+ return false; >+} >+ >+void WorkerPool::postTask(Function<void()> task) >+{ >+ LockHolder locker(*m_lock); >+ m_tasks.append(WTFMove(task)); >+ m_condition->notifyOne(locker); >+} >+ >+} >diff --git a/Source/WTF/wtf/WorkerPool.h b/Source/WTF/wtf/WorkerPool.h >new file mode 100644 >index 0000000000000000000000000000000000000000..d0ed82cb4bd150050710bb3704948f69be18a075 >--- /dev/null >+++ b/Source/WTF/wtf/WorkerPool.h >@@ -0,0 +1,68 @@ >+/* >+ * Copyright (C) 2017 Yusuke Suzuki <utatane.tea@gmail.com>. >+ * >+ * 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. ``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 >+ * 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. >+ */ >+ >+#pragma once >+ >+#include <wtf/AutomaticThread.h> >+#include <wtf/Deque.h> >+#include <wtf/Function.h> >+#include <wtf/NumberOfCores.h> >+#include <wtf/Vector.h> >+ >+namespace WTF { >+ >+class WorkerPool : public ThreadSafeRefCounted<WorkerPool> { >+public: >+ ~WorkerPool(); >+ >+ void postTask(Function<void()>); >+ >+ // If timeout is infinity, it means AutomaticThread will be never automatically destroyed. >+ static Ref<WorkerPool> create(unsigned numberOfWorkers = WTF::numberOfProcessorCores(), Seconds timeout = Seconds::infinity()) >+ { >+ ASSERT(numberOfWorkers >= 1); >+ return adoptRef(*new WorkerPool(numberOfWorkers, timeout)); >+ } >+ >+private: >+ class Worker; >+ friend class Worker; >+ >+ WorkerPool(unsigned numberOfWorkers, Seconds timeout); >+ >+ bool shouldSleep(const AbstractLocker&); >+ >+ Box<Lock> m_lock; >+ RefPtr<AutomaticThreadCondition> m_condition; >+ Seconds m_timeout; >+ MonotonicTime m_lastTimeoutTime { MonotonicTime::nan() }; >+ unsigned m_numberOfActiveWorkers { 0 }; >+ Vector<Ref<Worker>> m_workers; >+ Deque<Function<void()>> m_tasks; >+}; >+ >+} >+ >+using WTF::WorkerPool; >diff --git a/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingEngineThreaded.cpp b/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingEngineThreaded.cpp >index 64617ff30aad444836555a0aa604fd01a7a2179b..565d9201b9da99a22a20b07aa91ea410ce992458 100644 >--- a/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingEngineThreaded.cpp >+++ b/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingEngineThreaded.cpp >@@ -33,27 +33,10 @@ > #include "GraphicsLayer.h" > #include "NicosiaBuffer.h" > #include "NicosiaPaintingContext.h" >-#include <glib.h> >-#include <wtf/FastMalloc.h> > > namespace Nicosia { > using namespace WebCore; > >-struct TaskData { >- WTF_MAKE_STRUCT_FAST_ALLOCATED; >- >- Ref<Buffer> buffer; >- PaintingOperations paintingOperations; >-}; >- >-void s_threadFunc(gpointer data, gpointer) >-{ >- std::unique_ptr<TaskData> taskData(static_cast<TaskData*>(data)); >- >- PaintingContext::replay(taskData->buffer, taskData->paintingOperations); >- taskData->buffer->completePainting(); >-} >- > static void paintLayer(GraphicsContext& context, GraphicsLayer& layer, const IntRect& sourceRect, const IntRect& mappedSourceRect, const IntRect& targetRect, float contentsScale, bool supportsAlpha) > { > context.save(); >@@ -75,14 +58,12 @@ static void paintLayer(GraphicsContext& context, GraphicsLayer& layer, const Int > } > > PaintingEngineThreaded::PaintingEngineThreaded() >+ : m_workerPool(WorkerPool::create(4)) > { >- // FIXME: these parameters should be fine-tuned, or maybe made configurable. >- m_threadPool = g_thread_pool_new(s_threadFunc, nullptr, 4, TRUE, nullptr); > } > > PaintingEngineThreaded::~PaintingEngineThreaded() > { >- g_thread_pool_free(m_threadPool, TRUE, FALSE); > } > > bool PaintingEngineThreaded::paint(GraphicsLayer& layer, Ref<Buffer>&& buffer, const IntRect& sourceRect, const IntRect& mappedSourceRect, const IntRect& targetRect, float contentsScale) >@@ -96,7 +77,10 @@ bool PaintingEngineThreaded::paint(GraphicsLayer& layer, Ref<Buffer>&& buffer, c > paintLayer(context, layer, sourceRect, mappedSourceRect, targetRect, contentsScale, buffer->supportsAlpha()); > }); > >- g_thread_pool_push(m_threadPool, new TaskData { WTFMove(buffer), WTFMove(paintingOperations) }, nullptr); >+ m_workerPool->postTask([paintingOperations = WTFMove(paintingOperations), buffer = WTFMove(buffer)] { >+ PaintingContext::replay(buffer, paintingOperations); >+ buffer->completePainting(); >+ }); > > return true; > } >diff --git a/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingEngineThreaded.h b/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingEngineThreaded.h >index 391c8cc3e284a57edeca9ec1270cce42bc0e8f5e..add14ed5f95c3022734ff942744726d5490c6e71 100644 >--- a/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingEngineThreaded.h >+++ b/Source/WebCore/platform/graphics/nicosia/NicosiaPaintingEngineThreaded.h >@@ -29,8 +29,7 @@ > #pragma once > > #include "NicosiaPaintingEngine.h" >- >-typedef struct _GThreadPool GThreadPool; >+#include <wtf/WorkerPool.h> > > namespace Nicosia { > >@@ -42,7 +41,7 @@ class PaintingEngineThreaded final : public PaintingEngine { > private: > bool paint(WebCore::GraphicsLayer&, Ref<Buffer>&&, const WebCore::IntRect&, const WebCore::IntRect&, const WebCore::IntRect&, float) override; > >- GThreadPool* m_threadPool; >+ Ref<WorkerPool> m_workerPool; > }; > > } // namespace Nicosia >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 58ce70fd8cbfcb06eb79d674bffefed51d71b2df..f4ea0c3eefa9cd82524d29564060f272acc420a7 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,14 @@ >+2018-06-06 Yusuke Suzuki <utatane.tea@gmail.com> >+ >+ [WTF] Add WorkerPool >+ https://bugs.webkit.org/show_bug.cgi?id=174569 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * TestWebKitAPI/CMakeLists.txt: >+ * TestWebKitAPI/Tests/WTF/WorkerPool.cpp: Added. >+ (TestWebKitAPI::TEST): >+ > 2018-06-06 Antoine Quint <graouts@apple.com> > > Rename color-filter to -apple-color-filter and do not expose it to Web content >diff --git a/Tools/TestWebKitAPI/CMakeLists.txt b/Tools/TestWebKitAPI/CMakeLists.txt >index 10f8fcafc05aa7d8e770f835e92ccee881857672..2e7d1c3d89a325eb5d9aef95e81fdfc7233ac0d7 100644 >--- a/Tools/TestWebKitAPI/CMakeLists.txt >+++ b/Tools/TestWebKitAPI/CMakeLists.txt >@@ -158,6 +158,7 @@ set(TestWTF_SOURCES > ${TESTWEBKITAPI_DIR}/Tests/WTF/WTFString.cpp > ${TESTWEBKITAPI_DIR}/Tests/WTF/WeakPtr.cpp > ${TESTWEBKITAPI_DIR}/Tests/WTF/WorkQueue.cpp >+ ${TESTWEBKITAPI_DIR}/Tests/WTF/WorkerPool.cpp > ) > > # FIXME: Tests/WTF/RunLoop.cpp is missing because it doesn't work for Windows. >diff --git a/Tools/TestWebKitAPI/Tests/WTF/WorkerPool.cpp b/Tools/TestWebKitAPI/Tests/WTF/WorkerPool.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..f98e28a1a7a2b1ef2717eac524476045a9e6c6b5 >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WTF/WorkerPool.cpp >@@ -0,0 +1,51 @@ >+/* >+ * Copyright (C) 2017 Yusuke Suzuki <utatane.tea@gmail.com>. >+ * >+ * 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 <wtf/DataLog.h> >+#include <wtf/Seconds.h> >+#include <wtf/Threading.h> >+#include <wtf/WorkerPool.h> >+ >+namespace TestWebKitAPI { >+ >+TEST(WTF, WorkerPoolDecrease) >+{ >+ std::atomic<unsigned> counter { 0 }; >+ { >+ Ref<WorkerPool> pool = WorkerPool::create(); >+ for (int i = 0; i < 10000; ++i) { >+ pool->postTask([&] { >+ ++counter; >+ Thread::yield(); >+ }); >+ } >+ // When destroying WorkerPool, all the tasks are drained. >+ } >+ EXPECT_EQ(counter.load(), 10000U); >+} >+ >+} // namespace TestWebKitAPI
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 174569
:
315618
|
342125
|
342126
|
342133
|
342147
|
342164
|
342165
|
342167