Optimize atomics in QObject::moveToThread() [2/2]: de-duplicate loads

We don't need to reload d->threadData, as we've already loaded it into
a register three lines above, so use the already-loaded value.

We don't care whether we might have read a different value the second
time around, because that would mean we had a race condition elsewhere
in the program (e.g. concurrent moveToThread() calls).

Pick-to: 6.3
Change-Id: I29a27ca23302288b5900ac6b45b8690a80e85680
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2022-05-17 17:19:54 +02:00
parent adb4a3beb7
commit ae765813d0

View File

@ -1820,7 +1820,7 @@ void QObject::moveToThread(QThread *targetThread)
QThreadData *thisThreadData = d->threadData.loadAcquire();
if (!thisThreadData->thread.loadRelaxed() && currentData == targetData) {
// one exception to the rule: we allow moving objects with no thread affinity to the current thread
currentData = d->threadData;
currentData = thisThreadData;
} else if (thisThreadData != currentData) {
qWarning("QObject::moveToThread: Current thread (%p) is not the object's thread (%p).\n"
"Cannot move to target thread (%p)\n",