diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2020-11-26 15:05:16 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2020-11-30 13:16:53 +0100 |
commit | 583b0612696f42571ac97b66c159570ea452fe17 (patch) | |
tree | e370a37e6a6ed6b019f8be78d62a676d89e0c7c5 /include/comphelper | |
parent | af361b464b46dcc39a1bb4ab098a6ddf6ff40a53 (diff) |
add ThreadPool::isIdle() to avoid incorrect detection of "no tasks"
Tasks that are being worked on but are not yet finished are removed
from maTasks, so maTasks.empty() does not mean "idle". I fixed one
case already in 2ad4e77a0f266ae6e6fccaebb1d080d2880bdac3, this one
fixes joinAll() which has a similar problem and triggers
https://gerrit.libreoffice.org/c/core/+/69473/3/sc/source/core/data/documen2.cxx#312
Also rename joinAll() to joinThreadsIfIdle(), as that's what it really is.
Change-Id: I8129cfadb81be968575ea8718de9ae997b877a4e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106701
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'include/comphelper')
-rw-r--r-- | include/comphelper/threadpool.hxx | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/include/comphelper/threadpool.hxx b/include/comphelper/threadpool.hxx index f51daf4f70a4..ec128b1422bd 100644 --- a/include/comphelper/threadpool.hxx +++ b/include/comphelper/threadpool.hxx @@ -64,12 +64,15 @@ public: void pushTask( std::unique_ptr<ThreadTask> pTask); /** Wait until all queued tasks associated with the tag are completed - @param bJoinAll - if set it joins all threads at the end if no other tasks from other tags. + @param bJoin - if set call joinThreadsIfIdle() at the end */ - void waitUntilDone(const std::shared_ptr<ThreadTaskTag>&, bool bJoinAll = true); + void waitUntilDone(const std::shared_ptr<ThreadTaskTag>&, bool bJoin = true); /// join all threads if there are no tasks presently. - void joinAll(); + void joinThreadsIfIdle(); + + /// return true if there are no queued or worked-on tasks + bool isIdle() const { return maTasks.empty() && mnBusyWorkers == 0; }; /// return the number of live worker threads sal_Int32 getWorkerCount() const { return mnMaxWorkers; } |