l_mutex_last
};
-mutex_debugging_base::mutex_debugging_base(std::string group, bool bt)
+mutex_debugging_base::mutex_debugging_base(std::string group, bool ld, bool bt)
: group(std::move(group)),
- id(-1),
- backtrace(bt),
- nlock(0),
- locked_by(thread::id())
+ lockdep(ld),
+ backtrace(bt)
{
- if (g_lockdep)
+ if (_enable_lockdep()) {
_register();
+ }
}
mutex_debugging_base::~mutex_debugging_base() {
ceph_assert(nlock == 0);
- if (g_lockdep) {
+ if (_enable_lockdep()) {
lockdep_unregister(id);
}
}
{
protected:
std::string group;
- int id;
+ int id = -1;
+ bool lockdep; // track this mutex using lockdep_*
bool backtrace; // gather backtrace on lock acquisition
- int nlock;
- std::thread::id locked_by;
-
+ int nlock = 0;
+ std::thread::id locked_by = {};
+ bool _enable_lockdep() const {
+ return lockdep && g_lockdep;
+ }
void _register();
void _will_lock(bool recursive=false); // about to lock
void _locked(); // just locked
void _will_unlock(); // about to unlock
- mutex_debugging_base(std::string group, bool bt = false);
+ mutex_debugging_base(std::string group, bool ld = true, bool bt = false);
~mutex_debugging_base();
public:
} else if (no_lockdep) {
return false;
} else {
- return g_lockdep;
+ return _enable_lockdep();
}
}
public:
static constexpr bool recursive = Recursive;
- mutex_debug_impl(std::string group, bool bt = false)
- : mutex_debugging_base(group, bt) {
+ mutex_debug_impl(std::string group, bool ld = true, bool bt = false)
+ : mutex_debugging_base(group, ld, bt) {
_init();
}
bool track_lock,
bool enable_lock_dep,
bool prioritize_write)
- : mutex_debugging_base{std::move(group), false /* backtrace */},
- track(track_lock),
- lockdep(enable_lock_dep)
+ : mutex_debugging_base{std::move(group),
+ enable_lock_dep,
+ false /* backtrace */},
+ track(track_lock)
{
#ifdef HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP
if (prioritize_write) {
// exclusive
void shared_mutex_debug::lock()
{
- if (g_lockdep && lockdep) {
+ if (_enable_lockdep()) {
_will_lock();
}
if (int r = pthread_rwlock_wrlock(&rwlock); r != 0) {
throw std::system_error(r, std::generic_category());
}
- if (lockdep && g_lockdep) {
+ if (_enable_lockdep()) {
_locked();
}
_post_lock();
int r = pthread_rwlock_trywrlock(&rwlock);
switch (r) {
case 0:
- if (lockdep && g_lockdep) {
+ if (_enable_lockdep()) {
_locked();
}
_post_lock();
void shared_mutex_debug::unlock()
{
_pre_unlock();
- if (lockdep && g_lockdep) {
+ if (_enable_lockdep()) {
_will_unlock();
}
if (int r = pthread_rwlock_unlock(&rwlock); r != 0) {
// shared locking
void shared_mutex_debug::lock_shared()
{
- if (lockdep && g_lockdep) {
+ if (_enable_lockdep()) {
_will_lock();
}
if (int r = pthread_rwlock_rdlock(&rwlock); r != 0) {
throw std::system_error(r, std::generic_category());
}
- if (lockdep && g_lockdep) {
+ if (_enable_lockdep()) {
_locked();
}
_post_lock_shared();
bool shared_mutex_debug::try_lock_shared()
{
- if (lockdep && g_lockdep) {
+ if (_enable_lockdep()) {
_will_unlock();
}
switch (int r = pthread_rwlock_rdlock(&rwlock); r) {
case 0:
- if (lockdep && g_lockdep) {
+ if (_enable_lockdep()) {
_locked();
}
_post_lock_shared();
void shared_mutex_debug::unlock_shared()
{
_pre_unlock_shared();
- if (lockdep && g_lockdep) {
+ if (_enable_lockdep()) {
_will_unlock();
}
if (int r = pthread_rwlock_unlock(&rwlock); r != 0) {