fix(Tasks): don't try to start more tasks than necessary

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2023-01-24 15:44:12 -03:00
parent 6d27ef5eea
commit 90feaaf2df
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469

View File

@ -115,7 +115,7 @@ void ConcurrentTask::startNext()
QMetaObject::invokeMethod(next.get(), &Task::start, Qt::QueuedConnection); QMetaObject::invokeMethod(next.get(), &Task::start, Qt::QueuedConnection);
// Allow going up the number of concurrent tasks in case of tasks being added in the middle of a running task. // Allow going up the number of concurrent tasks in case of tasks being added in the middle of a running task.
int num_starts = m_total_max_size - m_doing.size(); int num_starts = qMin(m_queue.size(), m_total_max_size - m_doing.size());
for (int i = 0; i < num_starts; i++) for (int i = 0; i < num_starts; i++)
QMetaObject::invokeMethod(this, &ConcurrentTask::startNext, Qt::QueuedConnection); QMetaObject::invokeMethod(this, &ConcurrentTask::startNext, Qt::QueuedConnection);
} }