]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/ceph_mutex: improve ceph::shared_mutex
authorKefu Chai <kchai@redhat.com>
Sun, 7 Jul 2019 04:32:53 +0000 (12:32 +0800)
committerNathan Cutler <ncutler@suse.com>
Thu, 4 Jun 2020 13:46:12 +0000 (15:46 +0200)
add helpers for supporting `ceph_mutex_is_locked()` and
`ceph_mutex_is_wlocked()` macros

Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit cc67c34a9e5b32e9372f6e109549619def3b6bc4)

src/common/ceph_mutex.h
src/common/shared_mutex_debug.h

index aac1bccdf0554bcb7176713e53d75c347a2d45e4..bb1088f9069e1a2950011d31a60fd0bc5f842ed3 100644 (file)
@@ -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())
 }
 
index 7a453ca119867de8951be6a27dc447c6d9aed924..e6071e9de2983bad3dc5b7d9d078830e6c02f8cf 100644 (file)
@@ -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();