summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2020-11-26 15:05:16 +0100
committerLuboš Luňák <l.lunak@collabora.com>2020-12-01 11:15:22 +0100
commitebd9e833fab5a26a137bef6c0e7bce2b3c9e0cf9 (patch)
treecdeeb7a46ea0ac7b4b190e5cd44664a447335767 /include
parentba8156d5a1dd2d37c7daef15f48b988bf6ded7a7 (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> (cherry picked from commit 583b0612696f42571ac97b66c159570ea452fe17) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106824
Diffstat (limited to 'include')
-rw-r--r--include/comphelper/threadpool.hxx9
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; }