summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2018-04-13 23:11:13 +0100
committerJan Holesovsky <kendy@collabora.com>2018-05-22 12:07:59 +0200
commit595b44740dd567a1e711c131c8e9750f3694c79b (patch)
treebce63ed671da8012766b8ea78814849ca9e2fc51 /comphelper
parent590fca888a5420b1681922d0184b15f3e0d5d8d5 (diff)
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 <kendy@collabora.com> Tested-by: Jan Holesovsky <kendy@collabora.com>
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/source/misc/threadpool.cxx21
1 files changed, 19 insertions, 2 deletions
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()