From ae765813d082d403889d2f98a9c21bd9628cdd58 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 17 May 2022 17:19:54 +0200 Subject: [PATCH] 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 Reviewed-by: Qt CI Bot --- src/corelib/kernel/qobject.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 6dfa7c3e674..3254f2a9feb 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -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",