From 769832cc1f592b1d0c39cda7795fe4548fc97566 Mon Sep 17 00:00:00 2001 From: Dennis Francis Date: Wed, 20 Mar 2019 20:07:58 +0530 Subject: Increase the life-cycle of threads in thread-pool... to ScDocument lifetime if possible. This helps to avoid lots of thread setup-cost while doing recalcs especially if there are many formula-groups in the document and most of them are fairly light-weight. Change-Id: Idd57e1ebd0d4e492f99e31237d4a55ec9c95a121 Reviewed-on: https://gerrit.libreoffice.org/69473 Tested-by: Jenkins Reviewed-by: Michael Meeks --- comphelper/source/misc/threadpool.cxx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'comphelper') diff --git a/comphelper/source/misc/threadpool.cxx b/comphelper/source/misc/threadpool.cxx index d0178e9aa9a7..89d80298432b 100644 --- a/comphelper/source/misc/threadpool.cxx +++ b/comphelper/source/misc/threadpool.cxx @@ -213,7 +213,7 @@ std::unique_ptr ThreadPool::popWorkLocked( std::unique_lock< std::mu return nullptr; } -void ThreadPool::waitUntilDone(const std::shared_ptr& rTag) +void ThreadPool::waitUntilDone(const std::shared_ptr& rTag, bool bJoinAll) { #if defined DBG_UTIL && (defined LINUX || defined _WIN32) assert(!gbIsWorkerThread && "cannot wait for tasks from inside a task"); @@ -232,12 +232,16 @@ void ThreadPool::waitUntilDone(const std::shared_ptr& rTag) rTag->waitUntilDone(); + if (bJoinAll) + joinAll(); +} + +void ThreadPool::joinAll() +{ + std::unique_lock< std::mutex > aGuard( maMutex ); + if (maTasks.empty()) // check if there are still tasks from another tag { - std::unique_lock< std::mutex > aGuard( maMutex ); - if (maTasks.empty()) // check if there are still tasks from another tag - { - shutdownLocked(aGuard); - } + shutdownLocked(aGuard); } } -- cgit