From 9d2994fad074cf5f15821487482fe01adfdea1cd Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sat, 20 Apr 2024 17:32:44 +0300 Subject: [PATCH] kdecore: start as many threads as possible from the queue of KThreadPool Signed-off-by: Ivailo Monev --- kdecore/kernel/kthreadpool.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kdecore/kernel/kthreadpool.cpp b/kdecore/kernel/kthreadpool.cpp index b8a39ae8..762e46c5 100644 --- a/kdecore/kernel/kthreadpool.cpp +++ b/kdecore/kernel/kthreadpool.cpp @@ -59,7 +59,8 @@ void KThreadPoolPrivate::appendThread(QThread *thread) activethreads.append(thread); parent->connect( thread, SIGNAL(finished()), - parent, SLOT(_k_slotFinished()) + parent, SLOT(_k_slotFinished()), + Qt::QueuedConnection ); } @@ -77,13 +78,13 @@ void KThreadPoolPrivate::_k_slotFinished() thread->deleteLater(); } } - if (!queuedthreads.isEmpty()) { + while (activethreadcount < maxthreads && !queuedthreads.isEmpty()) { QThread* thread = queuedthreads.takeFirst(); kDebug() << "starting thread from queue" << thread; appendThread(thread); - locker.unlock(); thread->start(); } + kDebug() << "currently" << activethreadcount << "active threads"; } @@ -108,7 +109,6 @@ void KThreadPool::start(QThread *thread, const QThread::Priority priority) } else { kDebug() << "starting thread" << thread; d->appendThread(thread); - locker.unlock(); thread->start(priority); } } @@ -120,7 +120,7 @@ void KThreadPool::waitForDone(const int timeout) QElapsedTimer elapsedtimer; elapsedtimer.start(); QMutableListIterator iter(d->activethreads); - kDebug() << "currently" << d->activethreads << "active threads"; + kDebug() << "currently" << d->activethreadcount << "active threads"; while ((timeout < 1 || elapsedtimer.elapsed() < timeout) && d->activethreadcount > 0) { iter.toFront(); while (iter.hasNext()) {