From cc67c34a9e5b32e9372f6e109549619def3b6bc4 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 7 Jul 2019 12:32:53 +0800 Subject: [PATCH] common/ceph_mutex: improve ceph::shared_mutex add helpers for supporting `ceph_mutex_is_locked()` and `ceph_mutex_is_wlocked()` macros Signed-off-by: Kefu Chai --- src/common/ceph_mutex.h | 3 +++ src/common/shared_mutex_debug.h | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/common/ceph_mutex.h b/src/common/ceph_mutex.h index 5f340561eb2..7683aef0aa1 100644 --- a/src/common/ceph_mutex.h +++ b/src/common/ceph_mutex.h @@ -24,6 +24,8 @@ namespace ceph { return true; } void unlock() {} + void lock_shared() {} + void unlock_shared() {} }; struct dummy_shared_mutex : dummy_mutex { @@ -98,6 +100,7 @@ namespace ceph { // debug methods #define ceph_mutex_is_locked(m) ((m).is_locked()) + #define ceph_mutex_is_wlocked(m) ((m).is_wlocked()) #define ceph_mutex_is_locked_by_me(m) ((m).is_locked_by_me()) } diff --git a/src/common/shared_mutex_debug.h b/src/common/shared_mutex_debug.h index 2144974372a..58569e14f48 100644 --- a/src/common/shared_mutex_debug.h +++ b/src/common/shared_mutex_debug.h @@ -27,11 +27,18 @@ public: void lock(); bool try_lock(); void unlock(); + bool is_wlocked() const { + return nlock > 0; + } // shared locking void lock_shared(); bool try_lock_shared(); void unlock_shared(); + // either of them + bool is_locked() const { + return nlock > 0 || nrlock > 0; + } private: // exclusive locking void _pre_unlock(); -- 2.39.5