diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2019-11-29 11:59:26 +0100 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2019-12-02 10:01:13 +0100 |
commit | a2b5b5c8f6e09ccfaca8044b34f4d9675c3be14a (patch) | |
tree | 03f74b0ea9b4955662992b3961b612f6f9335762 /src/core/jobs | |
parent | b6923f6fa0c01fa47f99f9794a17fe99c5397680 (diff) |
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 <sean.harmer@kdab.com>
Diffstat (limited to 'src/core/jobs')
-rw-r--r-- | src/core/jobs/qthreadpooler.cpp | 13 | ||||
-rw-r--r-- | 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<RunnableInterface *> &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<void> *m_futureInterface; QMutex m_mutex; QAtomicInt m_taskCount; - QThreadPool m_threadPool; + QThreadPool *m_threadPool; }; } // namespace Qt3DCore |