]> 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)
committerKefu Chai <kchai@redhat.com>
Sat, 3 Aug 2019 03:27:19 +0000 (11:27 +0800)
add helpers for supporting `ceph_mutex_is_locked()` and
`ceph_mutex_is_wlocked()` macros

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/ceph_mutex.h
src/common/shared_mutex_debug.h

index 5f340561eb2386f77aff756fa6e668f113823d2b..7683aef0aa136274bcfaa1b98de4a765b39a728f 100644 (file)
@@ -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())
 }
 
index 2144974372a04de704115c55fcb6bde912f5df5b..58569e14f48128e80ce3223e3f2de7b99c3758f0 100644 (file)
@@ -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();