WebKit Bugzilla
Attachment 342167 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-20180608000558.patch (text/plain), 25.96 KB, created by
Yusuke Suzuki
on 2018-06-07 08:05:59 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Yusuke Suzuki
Created:
2018-06-07 08:05:59 PDT
Size:
25.96 KB
patch
obsolete
>Subversion Revision: 232574 >diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index 05db42447c58fa0bf37e7a8e514eaff731767a85..e3c258dfc6473cd9bc377e0c881133a16ed11fb2 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,31 @@ >+2018-06-07 Yusuke Suzuki <utatane.tea@gmail.com> >+ >+ [WTF] Add WorkerPool >+ https://bugs.webkit.org/show_bug.cgi?id=174569 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ This patch adds WorkerPool, which is a thread pool that consists of AutomaticThread. >+ Since it is based on AutomaticThread, this WorkerPool can take `timeout`: once `timeout` >+ passes without any tasks, threads in WorkerPool will be destroyed. >+ >+ We add shouldSleep handler to AutomaticThread to make destruction of threads in WorkerPool moderate. >+ Without this, all threads are destroyed at once after `timeout` passes. >+ >+ * WTF.xcodeproj/project.pbxproj: >+ * wtf/AutomaticThread.cpp: >+ (WTF::AutomaticThread::AutomaticThread): >+ (WTF::AutomaticThread::start): >+ * wtf/AutomaticThread.h: >+ * wtf/CMakeLists.txt: >+ * wtf/WorkerPool.cpp: Added. >+ (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..3b6c546fa7dd0bd51d79ff83d99a4102d7bbbac8 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,20 @@ >+2018-06-07 Yusuke Suzuki <utatane.tea@gmail.com> >+ >+ [WTF] Add WorkerPool >+ https://bugs.webkit.org/show_bug.cgi?id=174569 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ We start using WorkerPool for NicosiaPaintingEngineThreaded instead of glib thread pool. >+ This makes NicosiaPaintingEngineThreaded platform-independent and usable for WinCairo. >+ >+ * 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.xcodeproj/project.pbxproj b/Source/WTF/WTF.xcodeproj/project.pbxproj >index 862c7ccbc2f08e0c6ee8ee20728156eddef7d3ff..3b04b708b0f33efdcbb4d6548c7f21ab4cda4942 100644 >--- a/Source/WTF/WTF.xcodeproj/project.pbxproj >+++ b/Source/WTF/WTF.xcodeproj/project.pbxproj >@@ -145,6 +145,7 @@ > DCEE22011CEA7551000C2396 /* BlockObjCExceptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = DCEE21FD1CEA7551000C2396 /* BlockObjCExceptions.mm */; }; > E15556F518A0CC18006F48FB /* CryptographicUtilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E15556F318A0CC18006F48FB /* CryptographicUtilities.cpp */; }; > E311FB171F0A568B003C08DE /* ThreadGroup.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E311FB151F0A568B003C08DE /* ThreadGroup.cpp */; }; >+ E388886F20C9095100E632BC /* WorkerPool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E388886D20C9095100E632BC /* WorkerPool.cpp */; }; > E38C41251EB4E04C0042957D /* CPUTimeCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = E38C41241EB4E04C0042957D /* CPUTimeCocoa.mm */; }; > E38C41281EB4E0680042957D /* CPUTime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38C41261EB4E0680042957D /* CPUTime.cpp */; }; > E38D6E271F5522E300A75CC4 /* StringBuilderJSON.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38D6E261F5522E300A75CC4 /* StringBuilderJSON.cpp */; }; >@@ -614,6 +615,8 @@ > E311FB161F0A568B003C08DE /* ThreadGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadGroup.h; sourceTree = "<group>"; }; > E3200AB41E9A536D003B59D2 /* PlatformRegisters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformRegisters.h; sourceTree = "<group>"; }; > E33D5F871FBED66700BF625E /* RecursableLambda.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RecursableLambda.h; sourceTree = "<group>"; }; >+ E388886D20C9095100E632BC /* WorkerPool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkerPool.cpp; sourceTree = "<group>"; }; >+ E388886E20C9095100E632BC /* WorkerPool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerPool.h; sourceTree = "<group>"; }; > E38C41241EB4E04C0042957D /* CPUTimeCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CPUTimeCocoa.mm; sourceTree = "<group>"; }; > E38C41261EB4E0680042957D /* CPUTime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CPUTime.cpp; sourceTree = "<group>"; }; > E38C41271EB4E0680042957D /* CPUTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPUTime.h; sourceTree = "<group>"; }; >@@ -1122,6 +1125,8 @@ > 0F3501631BB258C800F0A2A3 /* WeakRandom.h */, > 0FE4479A1B7AAA03009498EB /* WordLock.cpp */, > 0FE4479B1B7AAA03009498EB /* WordLock.h */, >+ E388886D20C9095100E632BC /* WorkerPool.cpp */, >+ E388886E20C9095100E632BC /* WorkerPool.h */, > E4A0AD371A96245500536DF6 /* WorkQueue.cpp */, > E4A0AD381A96245500536DF6 /* WorkQueue.h */, > FE05FAFE1FE5007500093230 /* WTFAssertions.cpp */, >@@ -1554,6 +1559,7 @@ > 0F66B2921DC97BAB004A1D3F /* WallTime.cpp in Sources */, > 1FA47C8A152502DA00568D1B /* WebCoreThread.cpp in Sources */, > 0FE4479C1B7AAA03009498EB /* WordLock.cpp in Sources */, >+ E388886F20C9095100E632BC /* WorkerPool.cpp in Sources */, > E4A0AD391A96245500536DF6 /* WorkQueue.cpp in Sources */, > E4A0AD3D1A96253C00536DF6 /* WorkQueueCocoa.cpp in Sources */, > FE05FAFF1FE5007500093230 /* WTFAssertions.cpp in Sources */, >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..00545245091350bf060c7c15830323685fbafd95 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; >@@ -176,6 +181,7 @@ class WTF_EXPORT_PRIVATE AutomaticThread : public ThreadSafeRefCounted<Automatic > > Box<Lock> m_lock; > RefPtr<AutomaticThreadCondition> m_condition; >+ Seconds m_timeout; > bool m_isRunning { true }; > bool m_isWaiting { false }; > bool m_hasUnderlyingThread { false }; >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/WorkerPool.cpp b/Source/WTF/wtf/WorkerPool.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..b879076dd7b34dcc2f7d98e0f1cec90a1c693c5a >--- /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 final : 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&) final >+ { >+ 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() final >+ { >+ m_task(); >+ m_task = nullptr; >+ return WorkResult::Continue; >+ } >+ >+ void threadDidStart() final >+ { >+ LockHolder locker(*m_pool.m_lock); >+ m_pool.m_numberOfActiveWorkers++; >+ } >+ >+ void threadIsStopping(const AbstractLocker&) final >+ { >+ m_pool.m_numberOfActiveWorkers--; >+ } >+ >+ bool shouldSleep(const AbstractLocker& locker) final >+ { >+ 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..b5f4d345dc18a69c302c5984254d0932240e2af3 >--- /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: >+ WTF_EXPORT_PRIVATE void postTask(Function<void()>&&); >+ >+ WTF_EXPORT_PRIVATE ~WorkerPool(); >+ >+ // 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; >+ >+ WTF_EXPORT_PRIVATE 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 95329ffd6887a11a90cb634768ae9274cc51efcd..11d7c448c54861c969945faa28f010f56c270bd8 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,15 @@ >+2018-06-07 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/TestWebKitAPI.xcodeproj/project.pbxproj: >+ * TestWebKitAPI/Tests/WTF/WorkerPool.cpp: Added. >+ (TestWebKitAPI::TEST): >+ > 2018-06-06 Fujii Hironori <Hironori.Fujii@sony.com> > > [Win][MiniBrowser] Remove gMainWindow global variable >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/TestWebKitAPI.xcodeproj/project.pbxproj b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >index 13167a892a4bf946b80ab55a7b56a710e80919fc..60c62a300b987b34ee4c329a5d260328e5d10bda 100644 >--- a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >+++ b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >@@ -1912,6 +1912,7 @@ > E194E1BA177E5145009C4D4E /* StopLoadingFromDidReceiveResponse.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StopLoadingFromDidReceiveResponse.mm; sourceTree = "<group>"; }; > E194E1BC177E534A009C4D4E /* StopLoadingFromDidReceiveResponse.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = StopLoadingFromDidReceiveResponse.html; sourceTree = "<group>"; }; > E19DB9781B32137C00DB38D4 /* NavigatorLanguage.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NavigatorLanguage.mm; sourceTree = "<group>"; }; >+ E388887020C9098100E632BC /* WorkerPool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkerPool.cpp; sourceTree = "<group>"; }; > E38A0D341FD50CBC00E98C8B /* Threading.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Threading.cpp; sourceTree = "<group>"; }; > E3953F951F2CF32100A76A2E /* Signals.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Signals.cpp; sourceTree = "<group>"; }; > E398BC0F2041C76300387136 /* UniqueArray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UniqueArray.cpp; sourceTree = "<group>"; }; >@@ -2892,6 +2893,7 @@ > 7CD0D5AA1D5534DE000CC9E1 /* Variant.cpp */, > BC55F5F814AD78EE00484BE1 /* Vector.cpp */, > 1CB9BC371A67482300FE5678 /* WeakPtr.cpp */, >+ E388887020C9098100E632BC /* WorkerPool.cpp */, > 7AA6A1511AAC0B31002B2ED3 /* WorkQueue.cpp */, > 265AF54F15D1E48A00B0CB4A /* WTFString.cpp */, > ); >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
Flags:
cgarcia
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 174569
:
315618
|
342125
|
342126
|
342133
|
342147
|
342164
|
342165
| 342167