From a2b5b5c8f6e09ccfaca8044b34f4d9675c3be14a Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Fri, 29 Nov 2019 11:59:26 +0100 Subject: Make QThreadPooler use the global thread pool This should ensure we don't have too many idling threads Change-Id: Ia533fc07140a4944a1149aca1565b0d8ae3cda22 Reviewed-by: Sean Harmer --- src/core/jobs/qthreadpooler.cpp | 13 ++++++++----- src/core/jobs/qthreadpooler_p.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/jobs/qthreadpooler.cpp b/src/core/jobs/qthreadpooler.cpp index a9f4e7a31..3ab321542 100644 --- a/src/core/jobs/qthreadpooler.cpp +++ b/src/core/jobs/qthreadpooler.cpp @@ -66,16 +66,19 @@ QThreadPooler::QThreadPooler(QObject *parent) , m_futureInterface(nullptr) , m_mutex() , m_taskCount(0) + , m_threadPool(QThreadPool::globalInstance()) { const QByteArray maxThreadCount = qgetenv("QT3D_MAX_THREAD_COUNT"); if (!maxThreadCount.isEmpty()) { bool conversionOK = false; const int maxThreadCountValue = maxThreadCount.toInt(&conversionOK); if (conversionOK) - m_threadPool.setMaxThreadCount(maxThreadCountValue); + m_threadPool->setMaxThreadCount(maxThreadCountValue); } + + // Ensures that threads will never be recycled - m_threadPool.setExpiryTimeout(-1); + m_threadPool->setExpiryTimeout(-1); #if QT_CONFIG(qt3d_profile_jobs) QThreadPooler::m_jobsStatTimer.start(); #endif @@ -105,7 +108,7 @@ void QThreadPooler::enqueueTasks(const QVector &tasks) if (!hasDependencies(*it) && !(*it)->reserved()) { (*it)->setReserved(true); (*it)->setPooler(this); - m_threadPool.start((*it)); + m_threadPool->start((*it)); } } } @@ -125,7 +128,7 @@ void QThreadPooler::taskFinished(RunnableInterface *task) if (!aspectTask->reserved()) { aspectTask->setReserved(true); aspectTask->setPooler(this); - m_threadPool.start(aspectTask); + m_threadPool->start(aspectTask); } } } @@ -188,7 +191,7 @@ int QThreadPooler::currentCount() const int QThreadPooler::maxThreadCount() const { - return m_threadPool.maxThreadCount(); + return m_threadPool->maxThreadCount(); } #if QT_CONFIG(qt3d_profile_jobs) diff --git a/src/core/jobs/qthreadpooler_p.h b/src/core/jobs/qthreadpooler_p.h index 65459efba..3e17cbd6d 100644 --- a/src/core/jobs/qthreadpooler_p.h +++ b/src/core/jobs/qthreadpooler_p.h @@ -103,7 +103,7 @@ private: QFutureInterface *m_futureInterface; QMutex m_mutex; QAtomicInt m_taskCount; - QThreadPool m_threadPool; + QThreadPool *m_threadPool; }; } // namespace Qt3DCore -- cgit v1.2.3