From 5aebbc81d889d82de9cb051d982af15d35ee0226 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 12 Jun 2025 21:07:58 +0200 Subject: [PATCH] QCoreApplication: fold two atomic ops into one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.8 6.5 Change-Id: I6f6804261cd56a5a8bbb276ed7a0ac360c94195e Reviewed-by: Thiago Macieira (cherry picked from commit f4e7eebd27c1fed7bbeb646b38ea020c97731466) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit 5430116ed3504aa5d44cd314bedb3441701263f2) --- src/corelib/kernel/qcoreapplication.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 24d3134a758..e3fb3819e9b 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -1863,8 +1863,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.