]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/RWLock: allow disable lockdep on calls
authorJohn Spray <john.spray@redhat.com>
Fri, 22 Aug 2014 14:19:08 +0000 (15:19 +0100)
committerJohn Spray <john.spray@redhat.com>
Mon, 25 Aug 2014 00:34:19 +0000 (01:34 +0100)
To support callers with special cases where they
know they can safely take two locks with the
same name at the same time.

Signed-off-by: John Spray <john.spray@redhat.com>
src/common/RWLock.h

index 2bffa3e7b47f3dace45bf4f909341244e91e5875..e647e179cc475d976de7c6d2aba03fcf68523c4c 100644 (file)
@@ -50,14 +50,14 @@ public:
     pthread_rwlock_destroy(&L);
   }
 
-  void unlock() const {
+  void unlock(bool lockdep=true) const {
     if (nwlock.read() > 0) {
       nwlock.dec();
     } else {
       assert(nrlock.read() > 0);
       nrlock.dec();
     }
-    if (g_lockdep) id = lockdep_will_unlock(name, id);
+    if (lockdep && g_lockdep) id = lockdep_will_unlock(name, id);
     int r = pthread_rwlock_unlock(&L);
     assert(r == 0);
   }
@@ -83,17 +83,17 @@ public:
   }
 
   // write
-  void get_write() {
-    if (g_lockdep) id = lockdep_will_lock(name, id);
+  void get_write(bool lockdep=true) {
+    if (lockdep && g_lockdep) id = lockdep_will_lock(name, id);
     int r = pthread_rwlock_wrlock(&L);
     assert(r == 0);
     if (g_lockdep) id = lockdep_locked(name, id);
     nwlock.inc();
 
   }
-  bool try_get_write() {
+  bool try_get_write(bool lockdep=true) {
     if (pthread_rwlock_trywrlock(&L) == 0) {
-      if (g_lockdep) id = lockdep_locked(name, id);
+      if (lockdep && g_lockdep) id = lockdep_locked(name, id);
       nwlock.inc();
       return true;
     }