QCoreApplication: fold two atomic ops into one

The old code performed a fetchAndSubAcquire() followed by an implicit
loadAcquire() in the Q_ASSERT(). But fetchAndSub() returns the old
value, so we don't need to re-load it; we just need to store the
result of fetchAndSub().

We need to adjust the assertion, of course, since we're now checking
the old value, which is one more than a load would show, so replace ≥
0 with > 0.

Amends the start of the public history.

Pick-to: 6.10 6.9 6.8 6.5
Change-Id: I6f6804261cd56a5a8bbb276ed7a0ac360c94195e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2025-06-12 21:07:58 +02:00
parent 96dfe0373c
commit f4e7eebd27

View File

@ -1873,8 +1873,9 @@ void QCoreApplicationPrivate::sendPostedEvents(QObject *receiver, int event_type
QEvent *e = pe.event;
QObject * r = pe.receiver;
r->d_func()->postedEvents.fetchAndSubAcquire(1);
Q_ASSERT(r->d_func()->postedEvents >= 0);
[[maybe_unused]]
const auto previous = r->d_func()->postedEvents.fetchAndSubAcquire(1);
Q_ASSERT(previous > 0);
// next, update the data structure so that we're ready
// for the next event.