]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
lockdep: disable on per-mutex basis (and do so for atomic_t)
authorSage Weil <sage@newdream.net>
Sat, 1 Nov 2008 00:05:08 +0000 (17:05 -0700)
committerSage Weil <sage@newdream.net>
Sat, 1 Nov 2008 00:05:08 +0000 (17:05 -0700)
You should disable it if you _know_ you are an inner mutex, and
will never try to acquire another lock while you are held.

src/common/Mutex.h
src/include/atomic.h

index 9a32e2ba04abbcaf7b4691fbd0254c52f2073e14..d88ad1eac4a9707eef245ab31356ba1d2e552e10 100755 (executable)
@@ -26,20 +26,22 @@ extern int g_lockdep;
 class Mutex {
 private:
   const char *name;
+  bool recursive;
+  bool lockdep;
+
   pthread_mutex_t _m;
   int nlock;
-  bool recursive;
 
   // don't allow copying.
   void operator=(Mutex &M) {}
   Mutex( const Mutex &M ) {}
 
 public:
-  Mutex(const char *n, bool r = true) : name(n), nlock(0), recursive(r) {
+  Mutex(const char *n, bool r = true, bool ld=true) : name(n), recursive(r), lockdep(ld), nlock(0) {
     if (recursive) {
       pthread_mutexattr_t attr;
       pthread_mutexattr_init(&attr);
-      pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE);
+      pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
       pthread_mutex_init(&_m,&attr);
       pthread_mutexattr_destroy(&attr);
     } else {
@@ -68,7 +70,7 @@ public:
   bool TryLock() {
     int r = pthread_mutex_trylock(&_m);
     if (r == 0) {
-      if (g_lockdep) _locked();
+      if (lockdep && g_lockdep) _locked();
       nlock++;
       assert(nlock == 1 || recursive);
     }
@@ -76,9 +78,9 @@ public:
   }
 
   void Lock() {
-    if (g_lockdep) _will_lock();
+    if (lockdep && g_lockdep) _will_lock();
     int r = pthread_mutex_lock(&_m);
-    if (g_lockdep) _locked();
+    if (lockdep && g_lockdep) _locked();
     assert(r == 0);
     nlock++;
     assert(nlock == 1 || recursive);
@@ -89,7 +91,7 @@ public:
     --nlock;
     int r = pthread_mutex_unlock(&_m);
     assert(r == 0);
-    if (g_lockdep) _unlocked();
+    if (lockdep && g_lockdep) _unlocked();
   }
 
   friend class Cond;
index 359da65dde7ef1d121ddf646c4c3fe168eeb340c..f4f085a9ca5262fdecf5edc25694d77ad446eb1b 100644 (file)
@@ -46,7 +46,7 @@ class atomic_t {
   Mutex lock;
   long nref;
 public:
-  atomic_t(int i=0) : lock("atomic_t::lock", false), nref(i) {}
+  atomic_t(int i=0) : lock("atomic_t::lock", false, false /* no lockdep */), nref(i) {}
   atomic_t(const atomic_t& other);
   void inc() { 
     lock.Lock();