]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common: refactor handling of lockdep's group name in debug locks.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Sat, 13 Jul 2019 00:00:27 +0000 (20:00 -0400)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Mon, 15 Jul 2019 14:53:45 +0000 (10:53 -0400)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/common/lockdep.h
src/common/mutex_debug.cc
src/common/mutex_debug.h
src/common/shared_mutex_debug.cc
src/common/shared_mutex_debug.h

index 1c854a9eaec7cbac374eaee9a7462a1b611787fb..11f21f56045b9bf8866a82ff34c0174989d2fb12 100644 (file)
@@ -21,6 +21,9 @@ extern bool g_lockdep;
 
 extern void lockdep_register_ceph_context(CephContext *cct);
 extern void lockdep_unregister_ceph_context(CephContext *cct);
+// lockdep tracks dependencies between multiple and different instances
+// of locks within a class denoted by `n`.
+// Caller is obliged to guarantee name uniqueness.
 extern int lockdep_register(const char *n);
 extern void lockdep_unregister(int id);
 extern int lockdep_will_lock(const char *n, int id, bool force_backtrace=false,
index 5660826ef2cf6d99bfc8cc19a29fae98c2d98f4e..e6b77c1424dc29691bb3c247969d5ad865749569 100644 (file)
@@ -25,14 +25,12 @@ enum {
   l_mutex_last
 };
 
-mutex_debugging_base::mutex_debugging_base(const std::string &n, bool bt)
-  : name(n), id(-1), backtrace(bt), nlock(0), locked_by(thread::id())
-{
-  if (g_lockdep)
-    _register();
-}
-mutex_debugging_base::mutex_debugging_base(const char *n, bool bt)
-  : name(n), id(-1), backtrace(bt), nlock(0), locked_by(thread::id())
+mutex_debugging_base::mutex_debugging_base(std::string group, bool bt)
+  : group(std::move(group)),
+    id(-1),
+    backtrace(bt),
+    nlock(0),
+    locked_by(thread::id())
 {
   if (g_lockdep)
     _register();
@@ -46,16 +44,16 @@ mutex_debugging_base::~mutex_debugging_base() {
 }
 
 void mutex_debugging_base::_register() {
-  id = lockdep_register(name.c_str());
+  id = lockdep_register(group.c_str());
 }
 void mutex_debugging_base::_will_lock(bool recursive) { // about to lock
-  id = lockdep_will_lock(name.c_str(), id, backtrace, recursive);
+  id = lockdep_will_lock(group.c_str(), id, backtrace, recursive);
 }
 void mutex_debugging_base::_locked() {    // just locked
-  id = lockdep_locked(name.c_str(), id, backtrace);
+  id = lockdep_locked(group.c_str(), id, backtrace);
 }
 void mutex_debugging_base::_will_unlock() {  // about to unlock
-  id = lockdep_will_unlock(name.c_str(), id);
+  id = lockdep_will_unlock(group.c_str(), id);
 }
 
 } // namespace mutex_debug_detail
index 247233fd9999d343c6731d77b63379bf3fd0d778..57e1a69bd2036556c18c2930aff2cd8daeffd085 100644 (file)
@@ -35,7 +35,7 @@ namespace mutex_debug_detail {
 class mutex_debugging_base
 {
 protected:
-  std::string name;
+  std::string group;
   int id;
   bool backtrace; // gather backtrace on lock acquisition
 
@@ -48,8 +48,7 @@ protected:
   void _locked(); // just locked
   void _will_unlock(); // about to unlock
 
-  mutex_debugging_base(const std::string &n, bool bt = false);
-  mutex_debugging_base(const char *n, bool bt = false);
+  mutex_debugging_base(std::string group, bool bt = false);
   ~mutex_debugging_base();
 
 public:
@@ -98,13 +97,8 @@ private:
 public:
   static constexpr bool recursive = Recursive;
 
-  // Mutex concept is DefaultConstructible
-  mutex_debug_impl(const std::string &n, bool bt = false)
-    : mutex_debugging_base(n, bt) {
-    _init();
-  }
-  mutex_debug_impl(const char *n, bool bt = false)
-    : mutex_debugging_base(n, bt) {
+  mutex_debug_impl(std::string group, bool bt = false)
+    : mutex_debugging_base(group, bt) {
     _init();
   }
 
index c0a031a42d596748fd87278acad8ac714064467d..3dd3814edb677c1dfd5cc83d1f8db24368cd9581 100644 (file)
@@ -7,11 +7,11 @@
 
 namespace ceph {
 
-shared_mutex_debug::shared_mutex_debug(const std::string& n,
+shared_mutex_debug::shared_mutex_debug(std::string group,
                                        bool track_lock,
                                        bool enable_lock_dep,
                                        bool prioritize_write)
-  : mutex_debugging_base{n, false /* backtrace */},
+  : mutex_debugging_base{std::move(group), false /* backtrace */},
     track(track_lock),
     lockdep(enable_lock_dep)
 {
index c0abf54b515655162cf2fce558fab5b662be6543..2144974372a04de704115c55fcb6bde912f5df5b 100644 (file)
@@ -19,7 +19,7 @@ class shared_mutex_debug :
   std::atomic<unsigned> nrlock{0};
 
 public:
-  shared_mutex_debug(const std::string& n,
+  shared_mutex_debug(std::string group,
                     bool track_lock=true,
                     bool enable_lock_dep=true,
                     bool prioritize_write=false);