From 51bc150382ade63d91f150168a4c757d63510bc3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 13 Feb 2025 16:33:28 -0800 Subject: [PATCH] QMutex: mark the uncontended paths as Q_LIKELY Change-Id: I72ae8d8975c26d1f2e81fffd5839a2500f5edcb6 Reviewed-by: Allan Sandfeld Jensen --- src/corelib/thread/qmutex.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h index 5753d9faafa..a92fdc79c56 100644 --- a/src/corelib/thread/qmutex.h +++ b/src/corelib/thread/qmutex.h @@ -55,7 +55,7 @@ public: if constexpr (FutexAlwaysAvailable) { // we always unlock if we have futexes - if (QMutexPrivate *d = d_ptr.fetchAndStoreRelease(nullptr); d != dummyLocked()) + if (QMutexPrivate *d = d_ptr.fetchAndStoreRelease(nullptr); Q_UNLIKELY(d != dummyLocked())) unlockInternalFutex(d); // was contended } else { // if we don't have futexes, we can only unlock if not contended @@ -85,7 +85,7 @@ public: private: inline bool fastTryLock() noexcept { - if (d_ptr.loadRelaxed() != nullptr) + if (Q_UNLIKELY(d_ptr.loadRelaxed() != nullptr)) return false; return d_ptr.testAndSetAcquire(nullptr, dummyLocked()); }