summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/concurrentoperationrunner.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/installer/concurrentoperationrunner.cpp')
-rw-r--r--src/libs/installer/concurrentoperationrunner.cpp22
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()) {