]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
lockdep: don't take lockdep_mutex twice for new lock registrations
authorJeff Layton <jlayton@redhat.com>
Thu, 14 Sep 2017 13:28:34 +0000 (09:28 -0400)
committerJeff Layton <jlayton@redhat.com>
Sat, 16 Sep 2017 11:57:04 +0000 (07:57 -0400)
We can do it under the same mutex, which should be more efficient.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
src/common/lockdep.cc

index 5e4283e289eac62be16d7317ad4150258560cca8..1fc564c9fd167111c83d278ac74f77d651497416 100644 (file)
@@ -163,11 +163,10 @@ int lockdep_get_free_id(void)
   return -1;
 }
 
-int lockdep_register(const char *name)
+static int _lockdep_register(const char *name)
 {
   int id;
 
-  pthread_mutex_lock(&lockdep_mutex);
   ceph::unordered_map<std::string, int>::iterator p = lock_ids.find(name);
   if (p == lock_ids.end()) {
     id = lockdep_get_free_id();
@@ -191,11 +190,20 @@ int lockdep_register(const char *name)
   }
 
   ++lock_refs[id];
-  pthread_mutex_unlock(&lockdep_mutex);
 
   return id;
 }
 
+int lockdep_register(const char *name)
+{
+  int id;
+
+  pthread_mutex_lock(&lockdep_mutex);
+  id = _lockdep_register(name);
+  pthread_mutex_unlock(&lockdep_mutex);
+  return id;
+}
+
 void lockdep_unregister(int id)
 {
   if (id < 0) {
@@ -269,9 +277,10 @@ static bool does_follow(int a, int b)
 int lockdep_will_lock(const char *name, int id, bool force_backtrace)
 {
   pthread_t p = pthread_self();
-  if (id < 0) id = lockdep_register(name);
 
   pthread_mutex_lock(&lockdep_mutex);
+  if (id < 0)
+    id = _lockdep_register(name);
   lockdep_dout(20) << "_will_lock " << name << " (" << id << ")" << dendl;
 
   // check dependency graph
@@ -343,9 +352,10 @@ int lockdep_locked(const char *name, int id, bool force_backtrace)
 {
   pthread_t p = pthread_self();
 
-  if (id < 0) id = lockdep_register(name);
-
   pthread_mutex_lock(&lockdep_mutex);
+  if (id < 0)
+    id = _lockdep_register(name);
+
   lockdep_dout(20) << "_locked " << name << dendl;
   if (force_backtrace || lockdep_force_backtrace())
     held[p][id] = new BackTrace(BACKTRACE_SKIP);