diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2020-12-10 15:53:23 +0100 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2021-01-27 15:00:56 +0100 |
commit | 8f8405e04642b98663d4752d4ae76c304ae33b01 (patch) | |
tree | 1e7f93ee0230aa01591263c53376e31fd5e3bcf0 /src/corelib/thread | |
parent | 6d3a886f09955fec29e541baa786633cce2b2b9e (diff) |
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')
-rw-r--r-- | src/corelib/thread/qthreadpool.cpp | 37 | ||||
-rw-r--r-- | src/corelib/thread/qthreadpool.h | 9 | ||||
-rw-r--r-- | src/corelib/thread/qthreadpool_p.h | 13 |
3 files changed, 42 insertions, 17 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(). diff --git a/src/corelib/thread/qthreadpool.h b/src/corelib/thread/qthreadpool.h index a559eff49a..3e601dd963 100644 --- a/src/corelib/thread/qthreadpool.h +++ b/src/corelib/thread/qthreadpool.h @@ -56,10 +56,10 @@ class Q_CORE_EXPORT QThreadPool : public QObject { Q_OBJECT Q_DECLARE_PRIVATE(QThreadPool) - Q_PROPERTY(int expiryTimeout READ expiryTimeout WRITE setExpiryTimeout) - Q_PROPERTY(int maxThreadCount READ maxThreadCount WRITE setMaxThreadCount) + Q_PROPERTY(int expiryTimeout READ expiryTimeout WRITE setExpiryTimeout BINDABLE bindableExpiryTimeout) + Q_PROPERTY(int maxThreadCount READ maxThreadCount WRITE setMaxThreadCount BINDABLE bindableMaxThreadCount) Q_PROPERTY(int activeThreadCount READ activeThreadCount) - Q_PROPERTY(uint stackSize READ stackSize WRITE setStackSize) + Q_PROPERTY(uint stackSize READ stackSize WRITE setStackSize BINDABLE bindableStackSize) friend class QFutureInterfaceBase; public: @@ -76,14 +76,17 @@ public: int expiryTimeout() const; void setExpiryTimeout(int expiryTimeout); + QBindable<int> bindableExpiryTimeout(); int maxThreadCount() const; void setMaxThreadCount(int maxThreadCount); + QBindable<int> bindableMaxThreadCount(); int activeThreadCount() const; void setStackSize(uint stackSize); uint stackSize() const; + QBindable<uint> bindableStackSize(); void reserveThread(); void releaseThread(); diff --git a/src/corelib/thread/qthreadpool_p.h b/src/corelib/thread/qthreadpool_p.h index 4d73a480b5..019f24ce4d 100644 --- a/src/corelib/thread/qthreadpool_p.h +++ b/src/corelib/thread/qthreadpool_p.h @@ -58,6 +58,7 @@ #include "QtCore/qset.h" #include "QtCore/qqueue.h" #include "private/qobject_p.h" +#include "private/qproperty_p.h" QT_REQUIRE_CONFIG(thread); @@ -173,11 +174,17 @@ public: QList<QueuePage *> queue; QWaitCondition noActiveThreads; - int expiryTimeout = 30000; - int maxThreadCount = QThread::idealThreadCount(); + Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QThreadPoolPrivate, int, expiryTimeout, 30000) + + void setMaxThreadCount(int count) { q_func()->setMaxThreadCount(count); } + Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QThreadPoolPrivate, int, maxThreadCount, + &QThreadPoolPrivate::setMaxThreadCount, + QThread::idealThreadCount()) + int reservedThreads = 0; int activeThreads = 0; - uint stackSize = 0; + + Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QThreadPoolPrivate, uint, stackSize, 0) }; QT_END_NAMESPACE |