Fix data race in QCoreApplicationPrivate::sendThroughApplicationEventFilters()

The assertion has the acquire fence at the wrong place:

- QThreadData::thread isn't dereferenced, so the acquire fence on its
  load() isn't needed.

- QObjectPrivate::threadData, however, _is_ dereferenced, so an
  acquire fence is needed; the relaxed load() is insufficient.

Swapping the loadAcquire() and the loadRelaxed() fixes both issues.

Change-Id: Iee964490e93ebc323c188e616bf0d448f91fb2b5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 0da17e83ec507229e3516bbdc5986ab775dc843e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2022-05-17 10:19:41 +02:00 committed by Qt Cherry-pick Bot
parent 1f3529d8e8
commit c3ad3ad419

View File

@ -1132,7 +1132,7 @@ static bool doNotify(QObject *receiver, QEvent *event)
bool QCoreApplicationPrivate::sendThroughApplicationEventFilters(QObject *receiver, QEvent *event)
{
// We can't access the application event filters outside of the main thread (race conditions)
Q_ASSERT(receiver->d_func()->threadData.loadRelaxed()->thread.loadAcquire() == mainThread());
Q_ASSERT(receiver->d_func()->threadData.loadAcquire()->thread.loadRelaxed() == mainThread());
if (extraData) {
// application event filters are only called for objects in the GUI thread