QThreadPool: Protect the access to internal data with mutex
The class claims to be thread safe, however, when e.g. one thread is calling setMaxThreadCount() and the second is calling maxThreadCount() at the same time for the same thread pool instance, the latter may receive rubbish data. Protect all public setters/getters with a mutex. Pick-to: 6.5 6.4 Change-Id: Ief29d017d4f80443fa1ae06f6b20872f07588768 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
3ad9f94ff2
commit
0627ab1727
@ -590,12 +590,14 @@ bool QThreadPool::tryStart(std::function<void()> functionToRun)
|
|||||||
int QThreadPool::expiryTimeout() const
|
int QThreadPool::expiryTimeout() const
|
||||||
{
|
{
|
||||||
Q_D(const QThreadPool);
|
Q_D(const QThreadPool);
|
||||||
|
QMutexLocker locker(&d->mutex);
|
||||||
return d->expiryTimeout;
|
return d->expiryTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QThreadPool::setExpiryTimeout(int expiryTimeout)
|
void QThreadPool::setExpiryTimeout(int expiryTimeout)
|
||||||
{
|
{
|
||||||
Q_D(QThreadPool);
|
Q_D(QThreadPool);
|
||||||
|
QMutexLocker locker(&d->mutex);
|
||||||
if (d->expiryTimeout == expiryTimeout)
|
if (d->expiryTimeout == expiryTimeout)
|
||||||
return;
|
return;
|
||||||
d->expiryTimeout = expiryTimeout;
|
d->expiryTimeout = expiryTimeout;
|
||||||
@ -616,6 +618,7 @@ void QThreadPool::setExpiryTimeout(int expiryTimeout)
|
|||||||
int QThreadPool::maxThreadCount() const
|
int QThreadPool::maxThreadCount() const
|
||||||
{
|
{
|
||||||
Q_D(const QThreadPool);
|
Q_D(const QThreadPool);
|
||||||
|
QMutexLocker locker(&d->mutex);
|
||||||
return d->requestedMaxThreadCount;
|
return d->requestedMaxThreadCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -685,12 +688,14 @@ void QThreadPool::reserveThread()
|
|||||||
void QThreadPool::setStackSize(uint stackSize)
|
void QThreadPool::setStackSize(uint stackSize)
|
||||||
{
|
{
|
||||||
Q_D(QThreadPool);
|
Q_D(QThreadPool);
|
||||||
|
QMutexLocker locker(&d->mutex);
|
||||||
d->stackSize = stackSize;
|
d->stackSize = stackSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint QThreadPool::stackSize() const
|
uint QThreadPool::stackSize() const
|
||||||
{
|
{
|
||||||
Q_D(const QThreadPool);
|
Q_D(const QThreadPool);
|
||||||
|
QMutexLocker locker(&d->mutex);
|
||||||
return d->stackSize;
|
return d->stackSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -711,12 +716,14 @@ uint QThreadPool::stackSize() const
|
|||||||
void QThreadPool::setThreadPriority(QThread::Priority priority)
|
void QThreadPool::setThreadPriority(QThread::Priority priority)
|
||||||
{
|
{
|
||||||
Q_D(QThreadPool);
|
Q_D(QThreadPool);
|
||||||
|
QMutexLocker locker(&d->mutex);
|
||||||
d->threadPriority = priority;
|
d->threadPriority = priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
QThread::Priority QThreadPool::threadPriority() const
|
QThread::Priority QThreadPool::threadPriority() const
|
||||||
{
|
{
|
||||||
Q_D(const QThreadPool);
|
Q_D(const QThreadPool);
|
||||||
|
QMutexLocker locker(&d->mutex);
|
||||||
return d->threadPriority;
|
return d->threadPriority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user