From fc48d88c766e536e7926a3c5dd163289f0d723a9 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 30 Oct 2024 08:02:39 +0100 Subject: [PATCH] mds/SimpleLock: add has_xlock_by() This replaces get_xlock_by() in cases where only a not-nullptr check is needed; this eliminates costly implicit reference counter manipulations. Signed-off-by: Max Kellermann --- src/mds/LocalLockC.h | 2 +- src/mds/SimpleLock.h | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/mds/LocalLockC.h b/src/mds/LocalLockC.h index a4df37bbcfed5..cea832204c059 100644 --- a/src/mds/LocalLockC.h +++ b/src/mds/LocalLockC.h @@ -30,7 +30,7 @@ public: } bool can_xlock_local() const { - return !is_wrlocked() && (get_xlock_by() == MutationRef()); + return !is_wrlocked() && !has_xlock_by(); } bool can_wrlock() const { diff --git a/src/mds/SimpleLock.h b/src/mds/SimpleLock.h index 55621549a8ff7..8ce8970b560af 100644 --- a/src/mds/SimpleLock.h +++ b/src/mds/SimpleLock.h @@ -420,7 +420,7 @@ public: // xlock void get_xlock(MutationRef who, client_t client) { - ceph_assert(get_xlock_by() == MutationRef()); + ceph_assert(!has_xlock_by()); ceph_assert(state == LOCK_XLOCK || is_locallock() || state == LOCK_LOCK /* if we are a peer */); parent->get(MDSCacheObject::PIN_LOCK); @@ -465,6 +465,9 @@ public: MutationRef get_xlock_by() const { return have_more() ? more()->xlock_by : MutationRef(); } + bool has_xlock_by() const noexcept { + return have_more() && more()->xlock_by; + } // lease bool is_leased() const { -- 2.39.5