Kaydet (Commit) 93e630a7 authored tarafından Michael Meeks's avatar Michael Meeks Kaydeden (comit) Jan Holesovsky

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/52859Reviewed-by: 's avatarJan Holesovsky <kendy@collabora.com>
Tested-by: 's avatarJan Holesovsky <kendy@collabora.com>
üst f53fbfa7
...@@ -134,12 +134,21 @@ ThreadPool::ThreadPool( sal_Int32 nWorkers ) : ...@@ -134,12 +134,21 @@ ThreadPool::ThreadPool( sal_Int32 nWorkers ) :
mnThreadsWorking( 0 ), mnThreadsWorking( 0 ),
mbTerminate( false ) 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++ ) for( sal_Int32 i = 0; i < nWorkers; i++ )
maWorkers.push_back( new ThreadWorker( this ) ); maWorkers.push_back( new ThreadWorker( this ) );
maTasksComplete.set(); maTasksComplete.set();
osl::MutexGuard aGuard( maGuard );
for(rtl::Reference<ThreadWorker> & rpWorker : maWorkers) for(rtl::Reference<ThreadWorker> & rpWorker : maWorkers)
rpWorker->launch(); rpWorker->launch();
} }
...@@ -160,7 +169,15 @@ struct ThreadPoolStatic : public rtl::StaticWithInit< std::shared_ptr< ThreadPoo ...@@ -160,7 +169,15 @@ struct ThreadPoolStatic : public rtl::StaticWithInit< std::shared_ptr< ThreadPoo
ThreadPool& ThreadPool::getSharedOptimalPool() 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() sal_Int32 ThreadPool::getPreferredConcurrency()
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <comphelper/string.hxx> #include <comphelper/string.hxx>
#include <comphelper/propertysequence.hxx> #include <comphelper/propertysequence.hxx>
#include <comphelper/scopeguard.hxx> #include <comphelper/scopeguard.hxx>
#include <comphelper/threadpool.hxx>
#include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XNameAccess.hpp> #include <com/sun/star/container/XNameAccess.hpp>
...@@ -3816,7 +3817,10 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char ...@@ -3816,7 +3817,10 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
} }
if (eStage == PRE_INIT) if (eStage == PRE_INIT)
{
comphelper::ThreadPool::resetSharedOptimalPool();
rtl_alloc_preInit(sal_False); rtl_alloc_preInit(sal_False);
}
return bInitialized; return bInitialized;
} }
......
...@@ -43,6 +43,9 @@ public: ...@@ -43,6 +43,9 @@ public:
/// count for the CPU /// count for the CPU
static ThreadPool& getSharedOptimalPool(); static ThreadPool& getSharedOptimalPool();
/// resets / closes shared optimal pool workers.
static void resetSharedOptimalPool();
static std::shared_ptr<ThreadTaskTag> createThreadTaskTag(); static std::shared_ptr<ThreadTaskTag> createThreadTaskTag();
static bool isTaskTagDone(const std::shared_ptr<ThreadTaskTag>&); static bool isTaskTagDone(const std::shared_ptr<ThreadTaskTag>&);
...@@ -56,6 +59,9 @@ public: ...@@ -56,6 +59,9 @@ public:
ThreadPool( sal_Int32 nWorkers ); ThreadPool( sal_Int32 nWorkers );
~ThreadPool(); ~ThreadPool();
/// Instantiate a given number of workers
void launchWorkers( sal_Int32 nWorkers );
/// push a new task onto the work queue /// push a new task onto the work queue
void pushTask( ThreadTask *pTask /* takes ownership */ ); void pushTask( ThreadTask *pTask /* takes ownership */ );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment