diff options
author | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2022-04-04 15:18:27 +0300 |
---|---|---|
committer | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2022-04-21 14:24:31 +0000 |
commit | 99db65c70ab7cdc458e197440af8251cd48c8e89 (patch) | |
tree | 55fe59ac8f89f48343d430536df2eb48bb15dc1e /src/libs/installer/concurrentoperationrunner.cpp | |
parent | 4b1af7d32b062f954a84616e28bb6296a28522b4 (diff) |
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 <riitta-leena.miettinen@qt.io>
Reviewed-by: Katja Marttila <katja.marttila@qt.io>
Diffstat (limited to 'src/libs/installer/concurrentoperationrunner.cpp')
-rw-r--r-- | src/libs/installer/concurrentoperationrunner.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
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(); } @@ -112,6 +115,19 @@ void ConcurrentOperationRunner::setType(const Operation::OperationType 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 Runs \a operation in mode of \a type. Returns \c true on success, \c false otherwise. @@ -148,7 +164,7 @@ QHash<Operation *, bool> ConcurrentOperationRunner::run() connect(futureWatcher, &QFutureWatcher<bool>::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()) { |