Skip to content

Commit

Permalink
lockdep: fix Mutex tests to disable lockdep properly
Browse files Browse the repository at this point in the history
...and make g_lockdep a bool.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
  • Loading branch information
jtlayton committed Sep 16, 2017
1 parent 75f41a9 commit 0cd0bd7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/common/lockdep.cc
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/common/lockdep.h
Expand Up @@ -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);
Expand Down
17 changes: 12 additions & 5 deletions src/test/common/test_mutex.cc
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 0cd0bd7

Please sign in to comment.