summaryrefslogtreecommitdiff
path: root/src/corelib/thread/qthreadpool.cpp
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2020-12-10 15:53:23 +0100
committerSona Kurazyan <sona.kurazyan@qt.io>2021-01-27 15:00:56 +0100
commit8f8405e04642b98663d4752d4ae76c304ae33b01 (patch)
tree1e7f93ee0230aa01591263c53376e31fd5e3bcf0 /src/corelib/thread/qthreadpool.cpp
parent6d3a886f09955fec29e541baa786633cce2b2b9e (diff)
downloadqtbase-8f8405e04642b98663d4752d4ae76c304ae33b01.tar.gz
Port QThreadPool to the new property system
Ported all properties, except activeThreadCount. Marking it dirty may cause a re-evaluation of properties depending on it, which may reault in a deadlock in case of trying to read activeThreadCount property which is being marked as dirty. Task-number: QTBUG-85520 Change-Id: Id073b0895c89a9e6b05b57ad520db994e550a1c9 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/thread/qthreadpool.cpp')
-rw-r--r--src/corelib/thread/qthreadpool.cpp37
1 files changed, 26 insertions, 11 deletions
diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp
index 6d258af9df..b1f538fa43 100644
--- a/src/corelib/thread/qthreadpool.cpp
+++ b/src/corelib/thread/qthreadpool.cpp
@@ -163,7 +163,7 @@ void QThreadPoolThread::registerThreadInactive()
/*
\internal
*/
-QThreadPoolPrivate:: QThreadPoolPrivate()
+QThreadPoolPrivate::QThreadPoolPrivate()
{ }
bool QThreadPoolPrivate::tryStart(QRunnable *task)
@@ -223,10 +223,8 @@ void QThreadPoolPrivate::enqueueTask(QRunnable *runnable, int priority)
int QThreadPoolPrivate::activeThreadCount() const
{
- return (allThreads.count()
- - expiredThreads.count()
- - waitingThreads.count()
- + reservedThreads);
+ return int(allThreads.count() - expiredThreads.count() - waitingThreads.count()
+ + reservedThreads);
}
void QThreadPoolPrivate::tryToStartMoreThreads()
@@ -605,11 +603,15 @@ int QThreadPool::expiryTimeout() const
void QThreadPool::setExpiryTimeout(int expiryTimeout)
{
Q_D(QThreadPool);
- if (d->expiryTimeout == expiryTimeout)
- return;
d->expiryTimeout = expiryTimeout;
}
+QBindable<int> QThreadPool::bindableExpiryTimeout()
+{
+ Q_D(QThreadPool);
+ return &d->expiryTimeout;
+}
+
/*! \property QThreadPool::maxThreadCount
\brief the maximum number of threads used by the thread pool.
@@ -631,11 +633,18 @@ void QThreadPool::setMaxThreadCount(int maxThreadCount)
Q_D(QThreadPool);
QMutexLocker locker(&d->mutex);
- if (maxThreadCount == d->maxThreadCount)
- return;
-
+ const auto maxThreadCountChanged = maxThreadCount != d->maxThreadCount;
+ // Rewrite the value in any case, to make sure the binding is cleared.
d->maxThreadCount = maxThreadCount;
- d->tryToStartMoreThreads();
+
+ if (maxThreadCountChanged)
+ d->tryToStartMoreThreads();
+}
+
+QBindable<int> QThreadPool::bindableMaxThreadCount()
+{
+ Q_D(QThreadPool);
+ return &d->maxThreadCount;
}
/*! \property QThreadPool::activeThreadCount
@@ -698,6 +707,12 @@ uint QThreadPool::stackSize() const
return d->stackSize;
}
+QBindable<uint> QThreadPool::bindableStackSize()
+{
+ Q_D(QThreadPool);
+ return &d->stackSize;
+}
+
/*!
Releases a thread previously reserved by a call to reserveThread().