int id;
bool recursive;
bool lockdep;
+ bool backtrace; // gather backtrace on lock acquisition
pthread_mutex_t _m;
int nlock;
id = lockdep_will_lock(name, id);
}
void _locked() { // just locked
- id = lockdep_locked(name, id);
+ id = lockdep_locked(name, id, backtrace);
}
void _unlocked() { // just unlocked
id = lockdep_unlocked(name, id);
#endif
public:
- Mutex(const char *n, bool r = false, bool ld=true) : name(n), id(-1), recursive(r), lockdep(ld), nlock(0) {
+ Mutex(const char *n, bool r = false, bool ld=true, bool bt=false) :
+ name(n), id(-1), recursive(r), lockdep(ld), backtrace(bt), nlock(0) {
if (recursive) {
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
dout(0) << "recursive lock of " << name << " (" << id << ")" << std::endl;
BackTrace *bt = new BackTrace(BACKTRACE_SKIP);
bt->print(*_dout);
- if (g_lockdep >= 2) {
+ if (p->second) {
*_dout << std::endl;
dout(0) << "previously locked at" << std::endl;
p->second->print(*_dout);
q != m.end();
q++) {
dout(0) << " " << lock_names[q->first] << " (" << q->first << ")" << std::endl;
- if (g_lockdep >= 2) {
+ if (q->second) {
q->second->print(*_dout);
*_dout << std::endl;
}
return id;
}
-int lockdep_locked(const char *name, int id)
+int lockdep_locked(const char *name, int id, bool force_backtrace)
{
pthread_t p = pthread_self();
pthread_mutex_lock(&lockdep_mutex);
dout(20) << "_locked " << name << std::endl;
- if (g_lockdep >= 2)
+ if (g_lockdep >= 2 || force_backtrace)
held[p][id] = new BackTrace(BACKTRACE_SKIP);
else
held[p][id] = 0;
extern int lockdep_register(const char *n);
extern int lockdep_will_lock(const char *n, int id);
-extern int lockdep_locked(const char *n, int id);
+extern int lockdep_locked(const char *n, int id, bool force_backtrace=false);
extern int lockdep_unlocked(const char *n, int id);
#endif