From: Kefu Chai Date: Sun, 7 Jul 2019 04:32:53 +0000 (+0800) Subject: common/ceph_mutex: improve ceph::shared_mutex X-Git-Tag: v15.1.0~1971^2~45 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cc67c34a9e5b32e9372f6e109549619def3b6bc4;p=ceph.git 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 --- diff --git a/src/common/ceph_mutex.h b/src/common/ceph_mutex.h index 5f340561eb23..7683aef0aa13 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 2144974372a0..58569e14f481 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();