From: Sage Weil Date: Sat, 1 Nov 2008 00:05:08 +0000 (-0700) Subject: lockdep: disable on per-mutex basis (and do so for atomic_t) X-Git-Tag: v0.5~121 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9a7d25c84cce412c696150ae61d93abdb1b93d33;p=ceph.git lockdep: disable on per-mutex basis (and do so for atomic_t) You should disable it if you _know_ you are an inner mutex, and will never try to acquire another lock while you are held. --- diff --git a/src/common/Mutex.h b/src/common/Mutex.h index 9a32e2ba04ab..d88ad1eac4a9 100755 --- a/src/common/Mutex.h +++ b/src/common/Mutex.h @@ -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; diff --git a/src/include/atomic.h b/src/include/atomic.h index 359da65dde7e..f4f085a9ca52 100644 --- a/src/include/atomic.h +++ b/src/include/atomic.h @@ -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();