diff options
author | Armin Le Grand <Armin.Le.Grand@cib.de> | 2016-07-07 10:16:02 +0200 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@cib.de> | 2018-08-09 13:20:02 +0200 |
commit | 949ecd96e8bec1709b89bca6177a1fbba6cc6f94 (patch) | |
tree | 1620defee71ceab5df27c8f226083e55bee978e0 | |
parent | 2f91c89baae9b0cf9e11cff02cf56338ebdda177 (diff) |
Related: tdf#50613 use an own instance of ThreadPool
Using the global ThreadPool (getSharedOptimalPool()) can lead to
problems when more than one usage executes and one of them
already calls waitUntilEmpty() what of course influences the
other usage. Thus I added an own instance of ThreadPool for
async loading of chart models in writer
Change-Id: I4bea64af0d36e87081abec95c75574966d0fe5b9
-rw-r--r-- | sw/source/core/ole/ndole.cxx | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/sw/source/core/ole/ndole.cxx b/sw/source/core/ole/ndole.cxx index 903d96814bc1..1be81749133e 100644 --- a/sw/source/core/ole/ndole.cxx +++ b/sw/source/core/ole/ndole.cxx @@ -676,7 +676,36 @@ void SwOLENode::SetChanged() } } ////////////////////////////////////////////////////////////////////////////// +// due to some problems in test cases with the SharedOptimalPool, use +// an own instance of comphelper::ThreadPool. Problem is that other +// usages of getSharedOptimalPool() may interfere if more than one +// pool user calls waitUntilEmpty(). +// +// It gets created on-demand and will be available during LO's +// lifetime for loading chart models used in writer in parallel. It +// would be possible to add a usage count, then trigger a timer and +// clean it up (due to lifetime issues), but that's probably overkill. +// It gets created on demand, is ready for global reuse and makes no +// harm (not much ressources needed) +static comphelper::ThreadPool* pLocalPool = 0; + +comphelper::ThreadPool* getLocalThreadPool() +{ + if (pLocalPool) + { + return pLocalPool; + } + + if (0 == comphelper::ThreadPool::getSharedOptimalPool().getWorkerCount()) + { + return nullptr; + } + + pLocalPool = new comphelper::ThreadPool(comphelper::ThreadPool::getSharedOptimalPool().getWorkerCount()); + return pLocalPool; +} +/// Holder for local data for a parallely-executed task to load a chart model class DeflateData { private: @@ -734,8 +763,7 @@ public: } }; -////////////////////////////////////////////////////////////////////////////// - +/// Task for parallely-executed task to load a chart model class DeflateThread : public comphelper::ThreadTask { // the data to work on @@ -1080,11 +1108,14 @@ drawinglayer::primitive2d::Primitive2DContainer SwOLEObj::tryToGetChartContentAs if(aXModel.is()) { + // loaded using own instance of comphelper::ThreadPool, + // see getLocalThreadPool(). Disable via bool below if + // trouble surfaces somewhere static bool bAnynchronousLoadingAllowed = true; if(bSynchron || !bAnynchronousLoadingAllowed || - 0 == comphelper::ThreadPool::getSharedOptimalPool().getWorkerCount()) + nullptr == getLocalThreadPool()) { // load chart synchron in this Thread m_aPrimitive2DSequence = ChartHelper::tryToGetChartContentAsPrimitive2DSequence( @@ -1100,7 +1131,7 @@ drawinglayer::primitive2d::Primitive2DContainer SwOLEObj::tryToGetChartContentAs { m_pDeflateData = new DeflateData(aXModel); DeflateThread* pNew = new DeflateThread(*m_pDeflateData); - comphelper::ThreadPool::getSharedOptimalPool().pushTask(pNew); + getLocalThreadPool()->pushTask(pNew); } } } |