QThread::requestInterruption(): move qWarning() out of critical section

We do not touch anything mutex-protected in the path towards the qWarning(), so
the mutex lock is not needed. It may actually be harmful, since a message handler
may check isInterruptionRequested(), which would then deadlock.

Otherwise, we're just decreasing the size of the critical section — always a
worthwhile goal.

Change-Id: I26aa7e3dc087ff7efaccff1d4dc788ba00ba183f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2017-11-21 10:10:48 +01:00
parent 4d80d634a6
commit 7967c40303

View File

@ -844,14 +844,14 @@ bool QThread::event(QEvent *event)
void QThread::requestInterruption()
{
Q_D(QThread);
QMutexLocker locker(&d->mutex);
if (!d->running || d->finished || d->isInFinish)
return;
if (this == QCoreApplicationPrivate::theMainThread) {
qWarning("QThread::requestInterruption has no effect on the main thread");
return;
}
Q_D(QThread);
QMutexLocker locker(&d->mutex);
if (!d->running || d->finished || d->isInFinish)
return;
d->interruptionRequested = true;
}