]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
lockdep: fix Mutex tests to disable lockdep properly
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 12:59:29 +0000 (08:59 -0400)
...and make g_lockdep a bool.

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

index f3700c2a07faafe8c3c919f169787bac166a499e..d7a165ff9cf1beb73ab6c0fdb79864acc3649461 100644 (file)
@@ -33,7 +33,7 @@ namespace std {
 #define BACKTRACE_SKIP 2
 
 /******* Globals **********/
-int g_lockdep = 0;
+bool g_lockdep;
 struct lockdep_stopper_t {
   // disable lockdep when this module destructs.
   ~lockdep_stopper_t() {
index 63d2f0dd68e135ec84ad858072b284a1dbabf59b..ffafc300c3a4b3332036950ce3c629b6f8afdb1c 100644 (file)
@@ -17,7 +17,7 @@
 
 class CephContext;
 
-extern int g_lockdep;
+extern bool g_lockdep;
 
 extern void lockdep_register_ceph_context(CephContext *cct);
 extern void lockdep_unregister_ceph_context(CephContext *cct);
index b62341e71422120f2b53ead160faee7946372858..a4b496103e7cc85dc3850b1f30439de64166b250 100644 (file)
@@ -24,14 +24,23 @@ namespace ceph
   }
 }
 
-void do_init() {
-  static CephContext* cct = nullptr;
+static CephContext* cct;
+
+static void do_init() {
   if (cct == nullptr) {
     cct = new CephContext(0);
     lockdep_register_ceph_context(cct);
   }
 }
 
+static void disable_lockdep() {
+  if (cct) {
+    lockdep_unregister_ceph_context(cct);
+    cct->put();
+    cct = nullptr;
+  }
+}
+
 TEST(Mutex, NormalAsserts) {
   Mutex* m = new Mutex("Normal",false);
   m->Lock();
@@ -40,7 +49,6 @@ TEST(Mutex, NormalAsserts) {
 
 TEST(Mutex, RecursiveWithLockdep) {
   do_init();
-  g_lockdep = 1;
   Mutex* m = new Mutex("Recursive1",true);
   m->Lock();
   m->Lock();
@@ -50,8 +58,7 @@ TEST(Mutex, RecursiveWithLockdep) {
 }
 
 TEST(Mutex, RecursiveWithoutLockdep) {
-  do_init();
-  g_lockdep = 0;
+  disable_lockdep();
   Mutex* m = new Mutex("Recursive2",true);
   m->Lock();
   m->Lock();