Kaydet (Commit) 769832cc authored tarafından Dennis Francis's avatar Dennis Francis Kaydeden (comit) Michael Meeks

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: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst 3d9f973e
...@@ -213,7 +213,7 @@ std::unique_ptr<ThreadTask> ThreadPool::popWorkLocked( std::unique_lock< std::mu ...@@ -213,7 +213,7 @@ std::unique_ptr<ThreadTask> ThreadPool::popWorkLocked( std::unique_lock< std::mu
return nullptr; return nullptr;
} }
void ThreadPool::waitUntilDone(const std::shared_ptr<ThreadTaskTag>& rTag) void ThreadPool::waitUntilDone(const std::shared_ptr<ThreadTaskTag>& rTag, bool bJoinAll)
{ {
#if defined DBG_UTIL && (defined LINUX || defined _WIN32) #if defined DBG_UTIL && (defined LINUX || defined _WIN32)
assert(!gbIsWorkerThread && "cannot wait for tasks from inside a task"); assert(!gbIsWorkerThread && "cannot wait for tasks from inside a task");
...@@ -232,12 +232,16 @@ void ThreadPool::waitUntilDone(const std::shared_ptr<ThreadTaskTag>& rTag) ...@@ -232,12 +232,16 @@ void ThreadPool::waitUntilDone(const std::shared_ptr<ThreadTaskTag>& rTag)
rTag->waitUntilDone(); 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 ); shutdownLocked(aGuard);
if (maTasks.empty()) // check if there are still tasks from another tag
{
shutdownLocked(aGuard);
}
} }
} }
......
...@@ -63,8 +63,13 @@ public: ...@@ -63,8 +63,13 @@ public:
/// push a new task onto the work queue /// push a new task onto the work queue
void pushTask( std::unique_ptr<ThreadTask> pTask); void pushTask( std::unique_ptr<ThreadTask> pTask);
/// wait until all queued tasks associated with the tag are completed /** Wait until all queued tasks associated with the tag are completed
void waitUntilDone(const std::shared_ptr<ThreadTaskTag>&); @param bJoinAll - if set it joins all threads at the end if no other tasks from other tags.
*/
void waitUntilDone(const std::shared_ptr<ThreadTaskTag>&, bool bJoinAll = true);
/// join all threads if there are no tasks presently.
void joinAll();
/// return the number of live worker threads /// return the number of live worker threads
sal_Int32 getWorkerCount() const { return mnWorkers; } sal_Int32 getWorkerCount() const { return mnWorkers; }
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <tools/urlobj.hxx> #include <tools/urlobj.hxx>
#include <rtl/crc.h> #include <rtl/crc.h>
#include <basic/basmgr.hxx> #include <basic/basmgr.hxx>
#include <comphelper/threadpool.hxx>
#include <sal/log.hxx> #include <sal/log.hxx>
#include <document.hxx> #include <document.hxx>
...@@ -307,6 +308,9 @@ ScDocument::~ScDocument() ...@@ -307,6 +308,9 @@ ScDocument::~ScDocument()
{ {
OSL_PRECOND( !bInLinkUpdate, "bInLinkUpdate in dtor" ); OSL_PRECOND( !bInLinkUpdate, "bInLinkUpdate in dtor" );
// Join any pending(recalc) threads in global threadpool
comphelper::ThreadPool::getSharedOptimalPool().joinAll();
bInDtorClear = true; bInDtorClear = true;
// first of all disable all refresh timers by deleting the control // first of all disable all refresh timers by deleting the control
......
...@@ -4758,8 +4758,10 @@ bool ScFormulaCell::InterpretFormulaGroupThreading(sc::FormulaLogger::GroupScope ...@@ -4758,8 +4758,10 @@ bool ScFormulaCell::InterpretFormulaGroupThreading(sc::FormulaLogger::GroupScope
nStartOffset, nEndOffset)); nStartOffset, nEndOffset));
} }
SAL_INFO("sc.threaded", "Joining threads"); SAL_INFO("sc.threaded", "Waiting for threads to finish work");
rThreadPool.waitUntilDone(aTag); // Do not join the threads here. They will get joined in ScDocument destructor
// if they don't get joined from elsewhere before (via ThreadPool::waitUntilDone).
rThreadPool.waitUntilDone(aTag, false);
pDocument->SetThreadedGroupCalcInProgress(false); pDocument->SetThreadedGroupCalcInProgress(false);
......
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