summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qthreadpool.cpp
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2024-10-04 15:55:38 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2024-11-18 18:33:17 +0100
commite58d714c4750b49bf255a0f42b63118534df8a24 (patch)
treefd4b8531098fa462ee18e67f56715339a6798050 /src/corelib/thread/qthreadpool.cpp
parent35066b28c86cb0eb8880b6a4af84f8d02ff7aff0 (diff)
QThreadPool: Add Quality of Service API
Same limitation as setting priority; it only applies to threads that start after the call. Change-Id: I0f77467a76ce2f4e7743d04fde344ef08cd8dbb8 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/corelib/thread/qthreadpool.cpp')
-rw-r--r--src/corelib/thread/qthreadpool.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp
index 55f13a6b02a..62e3773af95 100644
--- a/src/corelib/thread/qthreadpool.cpp
+++ b/src/corelib/thread/qthreadpool.cpp
@@ -249,6 +249,7 @@ void QThreadPoolPrivate::startThread(QRunnable *runnable)
if (objectName.isEmpty())
objectName = u"Thread (pooled)"_s;
thread->setObjectName(objectName);
+ thread->setServiceLevel(serviceLevel);
Q_ASSERT(!allThreads.contains(thread.get())); // if this assert hits, we have an ABA problem (deleted threads don't get removed here)
allThreads.insert(thread.get());
++activeThreads;
@@ -765,6 +766,38 @@ void QThreadPool::releaseThread()
}
/*!
+ \since 6.9
+
+ Sets the Quality of Service level of thread objects created after the call
+ to this setter to \a serviceLevel.
+
+ Support is not available on every platform. Consult
+ QThread::setServiceLevel() for details.
+
+ \sa serviceLevel(), QThread::serviceLevel()
+*/
+void QThreadPool::setServiceLevel(QThread::QualityOfService serviceLevel)
+{
+ Q_D(QThreadPool);
+ QMutexLocker locker(&d->mutex);
+ d->serviceLevel = serviceLevel;
+}
+
+/*!
+ \since 6.9
+
+ Returns the current Quality of Service level of the thread.
+
+ \sa setServiceLevel(), QThread::serviceLevel()
+*/
+QThread::QualityOfService QThreadPool::serviceLevel() const
+{
+ Q_D(const QThreadPool);
+ QMutexLocker locker(&d->mutex);
+ return d->serviceLevel;
+}
+
+/*!
Releases a thread previously reserved with reserveThread() and uses it
to run \a runnable.