From: Kefu Chai Date: Sun, 7 Jul 2019 04:32:53 +0000 (+0800) Subject: common/ceph_mutex: improve ceph::shared_mutex X-Git-Tag: v14.2.10~7^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4f340eef1ccedb67eb3be4ec28b3b5b68c23bf90;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 (cherry picked from commit cc67c34a9e5b32e9372f6e109549619def3b6bc4) --- diff --git a/src/common/ceph_mutex.h b/src/common/ceph_mutex.h index aac1bccdf0554..bb1088f9069e1 100644 --- a/src/common/ceph_mutex.h +++ b/src/common/ceph_mutex.h @@ -21,6 +21,8 @@ namespace ceph { return true; } void unlock() {} + void lock_shared() {} + void unlock_shared() {} }; using mutex = dummy_mutex; @@ -84,6 +86,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 7a453ca119867..e6071e9de2983 100644 --- a/src/common/shared_mutex_debug.h +++ b/src/common/shared_mutex_debug.h @@ -31,11 +31,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();