summaryrefslogtreecommitdiffstats
path: root/include/comphelper
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2020-10-05 12:14:34 +0200
committerLuboš Luňák <l.lunak@collabora.com>2020-10-05 19:36:16 +0200
commit2ad4e77a0f266ae6e6fccaebb1d080d2880bdac3 (patch)
tree8d0f004997fb2f65cbfdd81a4e5bd5e5fa380927 /include/comphelper
parentSwGetRefFieldType ctor never passed a null SwDoc* (diff)
downloadcore-2ad4e77a0f266ae6e6fccaebb1d080d2880bdac3.tar.gz
core-2ad4e77a0f266ae6e6fccaebb1d080d2880bdac3.zip
fix allocating thread pool workers
Tasks are removed from the queue before a worker starts working on it, which means that maTasks.size() is not the number of tasks to do, because the worked on tasks are not included there. This means the code could spawn only a smaller number of workers than were needed (and than CPU cores that are available). Change-Id: Ic6e6a79316cf48d82f2b80be7ad477b723b2c4e5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103955 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'include/comphelper')
-rw-r--r--include/comphelper/threadpool.hxx7
1 files changed, 5 insertions, 2 deletions
diff --git a/include/comphelper/threadpool.hxx b/include/comphelper/threadpool.hxx
index 1cb9441cfdd1..f51daf4f70a4 100644
--- a/include/comphelper/threadpool.hxx
+++ b/include/comphelper/threadpool.hxx
@@ -72,7 +72,7 @@ public:
void joinAll();
/// return the number of live worker threads
- sal_Int32 getWorkerCount() const { return mnWorkers; }
+ sal_Int32 getWorkerCount() const { return mnMaxWorkers; }
/// wait until all work is completed, then join all threads
void shutdown();
@@ -90,12 +90,15 @@ private:
*/
std::unique_ptr<ThreadTask> popWorkLocked( std::unique_lock< std::mutex > & rGuard, bool bWait );
void shutdownLocked(std::unique_lock<std::mutex>&);
+ void incBusyWorker();
+ void decBusyWorker();
/// signalled when all in-progress tasks are complete
std::mutex maMutex;
std::condition_variable maTasksChanged;
bool mbTerminate;
- std::size_t const mnWorkers;
+ std::size_t const mnMaxWorkers;
+ std::size_t mnBusyWorkers;
std::vector< std::unique_ptr<ThreadTask> > maTasks;
std::vector< rtl::Reference< ThreadWorker > > maWorkers;
};