From 99db65c70ab7cdc458e197440af8251cd48c8e89 Mon Sep 17 00:00:00 2001 From: Arttu Tarkiainen Date: Mon, 4 Apr 2022 15:18:27 +0300 Subject: Add option for specifying maximum concurrent unpack operations For tracing issues with the multithreaded extraction and limiting the processor load from the installer. Task-number: QTIFW-2586 Change-Id: I5df0bf6be30b4ee5ef8470c407281e2a4318ed0c Reviewed-by: Leena Miettinen Reviewed-by: Katja Marttila --- src/libs/installer/concurrentoperationrunner.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/libs/installer/concurrentoperationrunner.cpp') diff --git a/src/libs/installer/concurrentoperationrunner.cpp b/src/libs/installer/concurrentoperationrunner.cpp index 03012c593..c1a87ded2 100644 --- a/src/libs/installer/concurrentoperationrunner.cpp +++ b/src/libs/installer/concurrentoperationrunner.cpp @@ -42,8 +42,9 @@ using namespace QInstaller; The class accepts an operation list of any registered operation type. It can be used to execute the \c Backup, \c Perform, or \c Undo steps of the operations. The - operations are run in the global thread pool, which by default limits the maximum - number of threads to the ideal number of logical processor cores in the system. + operations are run in a separate thread pool of this class, which by default limits + the maximum number of threads to the ideal number of logical processor cores in the + system. */ /*! @@ -67,6 +68,7 @@ ConcurrentOperationRunner::ConcurrentOperationRunner(QObject *parent) , m_totalOperations(0) , m_operations(nullptr) , m_type(Operation::OperationType::Perform) + , m_threadPool(new QThreadPool(this)) { } @@ -81,6 +83,7 @@ ConcurrentOperationRunner::ConcurrentOperationRunner(OperationList *operations, , m_totalOperations(0) , m_operations(operations) , m_type(type) + , m_threadPool(new QThreadPool(this)) { m_totalOperations = m_operations->size(); } @@ -111,6 +114,19 @@ void ConcurrentOperationRunner::setType(const Operation::OperationType type) m_type = type; } +/*! + Sets the maximum \a count of threads used by the thread pool of this class. + A value of \c 0 sets the count automatically to ideal number of threads. +*/ +void ConcurrentOperationRunner::setMaxThreadCount(int count) +{ + if (count == 0) { + m_threadPool->setMaxThreadCount(QThread::idealThreadCount()); + return; + } + m_threadPool->setMaxThreadCount(count); +} + /*! \internal @@ -148,7 +164,7 @@ QHash ConcurrentOperationRunner::run() connect(futureWatcher, &QFutureWatcher::finished, this, &ConcurrentOperationRunner::onOperationfinished); - futureWatcher->setFuture(QtConcurrent::run(&runOperation, operation, m_type)); + futureWatcher->setFuture(QtConcurrent::run(m_threadPool, &runOperation, operation, m_type)); } if (!m_operationWatchers.isEmpty()) { -- cgit v1.2.3