From: Jeff Layton Date: Thu, 14 Sep 2017 13:28:34 +0000 (-0400) Subject: lockdep: fix Mutex tests to disable lockdep properly X-Git-Tag: v13.0.1~856^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0cd0bd778a6149d3e2fe657060e223be3675aed7;p=ceph.git lockdep: fix Mutex tests to disable lockdep properly ...and make g_lockdep a bool. Signed-off-by: Jeff Layton --- diff --git a/src/common/lockdep.cc b/src/common/lockdep.cc index f3700c2a07fa..d7a165ff9cf1 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 63d2f0dd68e1..ffafc300c3a4 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 b62341e71422..a4b496103e7c 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();