extern void lockdep_register_ceph_context(CephContext *cct);
extern void lockdep_unregister_ceph_context(CephContext *cct);
+// lockdep tracks dependencies between multiple and different instances
+// of locks within a class denoted by `n`.
+// Caller is obliged to guarantee name uniqueness.
extern int lockdep_register(const char *n);
extern void lockdep_unregister(int id);
extern int lockdep_will_lock(const char *n, int id, bool force_backtrace=false,
l_mutex_last
};
-mutex_debugging_base::mutex_debugging_base(const std::string &n, bool bt)
- : name(n), id(-1), backtrace(bt), nlock(0), locked_by(thread::id())
-{
- if (g_lockdep)
- _register();
-}
-mutex_debugging_base::mutex_debugging_base(const char *n, bool bt)
- : name(n), id(-1), backtrace(bt), nlock(0), locked_by(thread::id())
+mutex_debugging_base::mutex_debugging_base(std::string group, bool bt)
+ : group(std::move(group)),
+ id(-1),
+ backtrace(bt),
+ nlock(0),
+ locked_by(thread::id())
{
if (g_lockdep)
_register();
}
void mutex_debugging_base::_register() {
- id = lockdep_register(name.c_str());
+ id = lockdep_register(group.c_str());
}
void mutex_debugging_base::_will_lock(bool recursive) { // about to lock
- id = lockdep_will_lock(name.c_str(), id, backtrace, recursive);
+ id = lockdep_will_lock(group.c_str(), id, backtrace, recursive);
}
void mutex_debugging_base::_locked() { // just locked
- id = lockdep_locked(name.c_str(), id, backtrace);
+ id = lockdep_locked(group.c_str(), id, backtrace);
}
void mutex_debugging_base::_will_unlock() { // about to unlock
- id = lockdep_will_unlock(name.c_str(), id);
+ id = lockdep_will_unlock(group.c_str(), id);
}
} // namespace mutex_debug_detail
class mutex_debugging_base
{
protected:
- std::string name;
+ std::string group;
int id;
bool backtrace; // gather backtrace on lock acquisition
void _locked(); // just locked
void _will_unlock(); // about to unlock
- mutex_debugging_base(const std::string &n, bool bt = false);
- mutex_debugging_base(const char *n, bool bt = false);
+ mutex_debugging_base(std::string group, bool bt = false);
~mutex_debugging_base();
public:
public:
static constexpr bool recursive = Recursive;
- // Mutex concept is DefaultConstructible
- mutex_debug_impl(const std::string &n, bool bt = false)
- : mutex_debugging_base(n, bt) {
- _init();
- }
- mutex_debug_impl(const char *n, bool bt = false)
- : mutex_debugging_base(n, bt) {
+ mutex_debug_impl(std::string group, bool bt = false)
+ : mutex_debugging_base(group, bt) {
_init();
}
namespace ceph {
-shared_mutex_debug::shared_mutex_debug(const std::string& n,
+shared_mutex_debug::shared_mutex_debug(std::string group,
bool track_lock,
bool enable_lock_dep,
bool prioritize_write)
- : mutex_debugging_base{n, false /* backtrace */},
+ : mutex_debugging_base{std::move(group), false /* backtrace */},
track(track_lock),
lockdep(enable_lock_dep)
{
std::atomic<unsigned> nrlock{0};
public:
- shared_mutex_debug(const std::string& n,
+ shared_mutex_debug(std::string group,
bool track_lock=true,
bool enable_lock_dep=true,
bool prioritize_write=false);