diff --git a/src/common/lockdep.cc b/src/common/lockdep.cc index f3700c2a07faa..d7a165ff9cf1b 100644 --- a/src/common/lockdep.cc +++ b/src/common/lockdep.cc @@ -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() { diff --git a/src/common/lockdep.h b/src/common/lockdep.h index 63d2f0dd68e13..ffafc300c3a4b 100644 --- a/src/common/lockdep.h +++ b/src/common/lockdep.h @@ -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); diff --git a/src/test/common/test_mutex.cc b/src/test/common/test_mutex.cc index b62341e714221..a4b496103e7cc 100644 --- a/src/test/common/test_mutex.cc +++ b/src/test/common/test_mutex.cc @@ -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();