diff options
-rw-r--r-- | src/corelib/thread/qthreadpool.cpp | 15 | ||||
-rw-r--r-- | src/corelib/thread/qthreadpool_p.h | 1 |
2 files changed, 10 insertions, 6 deletions
diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp index 713c436371..94b0aff451 100644 --- a/src/corelib/thread/qthreadpool.cpp +++ b/src/corelib/thread/qthreadpool.cpp @@ -273,13 +273,9 @@ bool QThreadPoolPrivate::tooManyThreadsActive() const */ void QThreadPoolPrivate::startThread(QRunnable *runnable) { - Q_Q(QThreadPool); Q_ASSERT(runnable != nullptr); QScopedPointer<QThreadPoolThread> thread(new QThreadPoolThread(this)); - QString objectName; - if (QString myName = q->objectName(); !myName.isEmpty()) - objectName = myName; - else + if (objectName.isEmpty()) objectName = QLatin1String("Thread (pooled)"); thread->setObjectName(objectName); Q_ASSERT(!allThreads.contains(thread.data())); // if this assert hits, we have an ABA problem (deleted threads don't get removed here) @@ -476,7 +472,14 @@ void QThreadPoolPrivate::stealAndRunRunnable(QRunnable *runnable) */ QThreadPool::QThreadPool(QObject *parent) : QObject(*new QThreadPoolPrivate, parent) -{ } +{ + Q_D(QThreadPool); + connect(this, &QObject::objectNameChanged, this, [d](const QString &newName) { + // We keep a copy of the name under our own lock, so we can access it thread-safely. + QMutexLocker locker(&d->mutex); + d->objectName = newName; + }); +} /*! Destroys the QThreadPool. diff --git a/src/corelib/thread/qthreadpool_p.h b/src/corelib/thread/qthreadpool_p.h index 1b6a65f69d..e82e4f16e7 100644 --- a/src/corelib/thread/qthreadpool_p.h +++ b/src/corelib/thread/qthreadpool_p.h @@ -176,6 +176,7 @@ public: QQueue<QThreadPoolThread *> expiredThreads; QList<QueuePage *> queue; QWaitCondition noActiveThreads; + QString objectName; int expiryTimeout = 30000; int requestedMaxThreadCount = QThread::idealThreadCount(); // don't use this directly |