]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/RWLock: alloc lockdep to be disabled
authorSage Weil <sage@redhat.com>
Sat, 30 Jan 2016 14:29:07 +0000 (09:29 -0500)
committerSage Weil <sage@redhat.com>
Mon, 1 Feb 2016 20:02:37 +0000 (15:02 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/RWLock.h

index 282b69bdfe6f9075e34de5351e0e032b67b37519..e93b0691b35e541f3007ec64359218d671a36807 100644 (file)
@@ -30,7 +30,7 @@ class RWLock
   std::string name;
   mutable int id;
   mutable atomic_t nrlock, nwlock;
-  bool track;
+  bool track, lockdep;
 
   std::string unique_name(const char* name) const;
 
@@ -38,12 +38,14 @@ public:
   RWLock(const RWLock& other);
   const RWLock& operator=(const RWLock& other);
 
-  RWLock(const std::string &n, bool track_lock=true) : name(n), id(-1), nrlock(0), nwlock(0), track(track_lock) {
+  RWLock(const std::string &n, bool track_lock=true, bool ld=true)
+    : name(n), id(-1), nrlock(0), nwlock(0), track(track_lock),
+      lockdep(ld) {
     pthread_rwlock_init(&L, NULL);
     ANNOTATE_BENIGN_RACE_SIZED(&id, sizeof(id), "RWLock lockdep id");
     ANNOTATE_BENIGN_RACE_SIZED(&nrlock, sizeof(nrlock), "RWlock nrlock");
     ANNOTATE_BENIGN_RACE_SIZED(&nwlock, sizeof(nwlock), "RWlock nwlock");
-    if (g_lockdep) id = lockdep_register(name.c_str());
+    if (lockdep && g_lockdep) id = lockdep_register(name.c_str());
   }
 
   bool is_locked() const {
@@ -61,7 +63,7 @@ public:
     if (track)
       assert(!is_locked());
     pthread_rwlock_destroy(&L);
-    if (g_lockdep) {
+    if (lockdep && g_lockdep) {
       lockdep_unregister(id);
     }
   }
@@ -75,17 +77,18 @@ public:
         nrlock.dec();
       }
     }
-    if (lockdep && g_lockdep) id = lockdep_will_unlock(name.c_str(), id);
+    if (lockdep && this->lockdep && g_lockdep)
+      id = lockdep_will_unlock(name.c_str(), id);
     int r = pthread_rwlock_unlock(&L);
     assert(r == 0);
   }
 
   // read
   void get_read() const {
-    if (g_lockdep) id = lockdep_will_lock(name.c_str(), id);
+    if (lockdep && g_lockdep) id = lockdep_will_lock(name.c_str(), id);
     int r = pthread_rwlock_rdlock(&L);
     assert(r == 0);
-    if (g_lockdep) id = lockdep_locked(name.c_str(), id);
+    if (lockdep && g_lockdep) id = lockdep_locked(name.c_str(), id);
     if (track)
       nrlock.inc();
   }
@@ -93,7 +96,7 @@ public:
     if (pthread_rwlock_tryrdlock(&L) == 0) {
       if (track)
          nrlock.inc();
-      if (g_lockdep) id = lockdep_locked(name.c_str(), id);
+      if (lockdep && g_lockdep) id = lockdep_locked(name.c_str(), id);
       return true;
     }
     return false;
@@ -104,17 +107,20 @@ public:
 
   // write
   void get_write(bool lockdep=true) {
-    if (lockdep && g_lockdep) id = lockdep_will_lock(name.c_str(), id);
+    if (lockdep && this->lockdep && g_lockdep)
+      id = lockdep_will_lock(name.c_str(), id);
     int r = pthread_rwlock_wrlock(&L);
     assert(r == 0);
-    if (g_lockdep) id = lockdep_locked(name.c_str(), id);
+    if (lockdep && this->lockdep && g_lockdep)
+      id = lockdep_locked(name.c_str(), id);
     if (track)
       nwlock.inc();
 
   }
   bool try_get_write(bool lockdep=true) {
     if (pthread_rwlock_trywrlock(&L) == 0) {
-      if (lockdep && g_lockdep) id = lockdep_locked(name.c_str(), id);
+      if (lockdep && this->lockdep && g_lockdep)
+       id = lockdep_locked(name.c_str(), id);
       if (track)
          nwlock.inc();
       return true;