comphelper/source/misc/threadpool.cxx | 21 +++++++++++++++++++-- desktop/source/lib/init.cxx | 4 ++++ include/comphelper/threadpool.hxx | 6 ++++++ 3 files changed, 29 insertions(+), 2 deletions(-)
New commits: commit 93e630a78330bb4b6076f8f638232dcc425f5b7c Author: Michael Meeks <michael.me...@collabora.com> Date: Fri Apr 13 23:11:13 2018 +0100 Allow the comphelper threadpool to be reset after construction. Otherwise some pre-init components can start it, and threads get stranded in the forkit process causing grief. Change-Id: I104a38271662e9f8cc2fd128e7b758700fd3ca84 Reviewed-on: https://gerrit.libreoffice.org/52859 Reviewed-by: Jan Holesovsky <ke...@collabora.com> Tested-by: Jan Holesovsky <ke...@collabora.com> diff --git a/comphelper/source/misc/threadpool.cxx b/comphelper/source/misc/threadpool.cxx index 286fbf697358..a065c5f6606e 100644 --- a/comphelper/source/misc/threadpool.cxx +++ b/comphelper/source/misc/threadpool.cxx @@ -134,12 +134,21 @@ ThreadPool::ThreadPool( sal_Int32 nWorkers ) : mnThreadsWorking( 0 ), mbTerminate( false ) { + launchWorkers( nWorkers ); +} + +void ThreadPool::launchWorkers( sal_Int32 nWorkers ) +{ + osl::MutexGuard aGuard( maGuard ); + + mbTerminate = false; + mnThreadsWorking = 0; + for( sal_Int32 i = 0; i < nWorkers; i++ ) maWorkers.push_back( new ThreadWorker( this ) ); maTasksComplete.set(); - osl::MutexGuard aGuard( maGuard ); for(rtl::Reference<ThreadWorker> & rpWorker : maWorkers) rpWorker->launch(); } @@ -160,7 +169,15 @@ struct ThreadPoolStatic : public rtl::StaticWithInit< std::shared_ptr< ThreadPoo ThreadPool& ThreadPool::getSharedOptimalPool() { - return *ThreadPoolStatic::get().get(); + ThreadPool *pPool = ThreadPoolStatic::get().get(); + if (pPool->maWorkers.size() <= 0) + pPool->launchWorkers( ThreadPool::getPreferredConcurrency() ); + return *pPool; +} + +void ThreadPool::resetSharedOptimalPool() +{ + ThreadPoolStatic::get()->waitAndCleanupWorkers(); } sal_Int32 ThreadPool::getPreferredConcurrency() diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 81700d548e26..f550958ab4f1 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -35,6 +35,7 @@ #include <comphelper/string.hxx> #include <comphelper/propertysequence.hxx> #include <comphelper/scopeguard.hxx> +#include <comphelper/threadpool.hxx> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/container/XNameAccess.hpp> @@ -3816,7 +3817,10 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char } if (eStage == PRE_INIT) + { + comphelper::ThreadPool::resetSharedOptimalPool(); rtl_alloc_preInit(sal_False); + } return bInitialized; } diff --git a/include/comphelper/threadpool.hxx b/include/comphelper/threadpool.hxx index 7910a83ceeb7..d45e4fb89aaa 100644 --- a/include/comphelper/threadpool.hxx +++ b/include/comphelper/threadpool.hxx @@ -43,6 +43,9 @@ public: /// count for the CPU static ThreadPool& getSharedOptimalPool(); + /// resets / closes shared optimal pool workers. + static void resetSharedOptimalPool(); + static std::shared_ptr<ThreadTaskTag> createThreadTaskTag(); static bool isTaskTagDone(const std::shared_ptr<ThreadTaskTag>&); @@ -56,6 +59,9 @@ public: ThreadPool( sal_Int32 nWorkers ); ~ThreadPool(); + /// Instantiate a given number of workers + void launchWorkers( sal_Int32 nWorkers ); + /// push a new task onto the work queue void pushTask( ThreadTask *pTask /* takes ownership */ ); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits