mirror of
https://github.com/ceph/ceph
synced 2025-04-01 23:02:17 +00:00
common/RWLock: alloc lockdep to be disabled
Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
parent
ada41f469e
commit
622ed5ad17
@ -30,7 +30,7 @@ class RWLock
|
||||
std::string name;
|
||||
mutable int id;
|
||||
mutable atomic_t nrlock, nwlock;
|
||||
bool track;
|
||||
bool track, lockdep;
|
||||
|
||||
std::string unique_name(const char* name) const;
|
||||
|
||||
@ -38,12 +38,14 @@ public:
|
||||
RWLock(const RWLock& other);
|
||||
const RWLock& operator=(const RWLock& other);
|
||||
|
||||
RWLock(const std::string &n, bool track_lock=true) : name(n), id(-1), nrlock(0), nwlock(0), track(track_lock) {
|
||||
RWLock(const std::string &n, bool track_lock=true, bool ld=true)
|
||||
: name(n), id(-1), nrlock(0), nwlock(0), track(track_lock),
|
||||
lockdep(ld) {
|
||||
pthread_rwlock_init(&L, NULL);
|
||||
ANNOTATE_BENIGN_RACE_SIZED(&id, sizeof(id), "RWLock lockdep id");
|
||||
ANNOTATE_BENIGN_RACE_SIZED(&nrlock, sizeof(nrlock), "RWlock nrlock");
|
||||
ANNOTATE_BENIGN_RACE_SIZED(&nwlock, sizeof(nwlock), "RWlock nwlock");
|
||||
if (g_lockdep) id = lockdep_register(name.c_str());
|
||||
if (lockdep && g_lockdep) id = lockdep_register(name.c_str());
|
||||
}
|
||||
|
||||
bool is_locked() const {
|
||||
@ -61,7 +63,7 @@ public:
|
||||
if (track)
|
||||
assert(!is_locked());
|
||||
pthread_rwlock_destroy(&L);
|
||||
if (g_lockdep) {
|
||||
if (lockdep && g_lockdep) {
|
||||
lockdep_unregister(id);
|
||||
}
|
||||
}
|
||||
@ -75,17 +77,18 @@ public:
|
||||
nrlock.dec();
|
||||
}
|
||||
}
|
||||
if (lockdep && g_lockdep) id = lockdep_will_unlock(name.c_str(), id);
|
||||
if (lockdep && this->lockdep && g_lockdep)
|
||||
id = lockdep_will_unlock(name.c_str(), id);
|
||||
int r = pthread_rwlock_unlock(&L);
|
||||
assert(r == 0);
|
||||
}
|
||||
|
||||
// read
|
||||
void get_read() const {
|
||||
if (g_lockdep) id = lockdep_will_lock(name.c_str(), id);
|
||||
if (lockdep && g_lockdep) id = lockdep_will_lock(name.c_str(), id);
|
||||
int r = pthread_rwlock_rdlock(&L);
|
||||
assert(r == 0);
|
||||
if (g_lockdep) id = lockdep_locked(name.c_str(), id);
|
||||
if (lockdep && g_lockdep) id = lockdep_locked(name.c_str(), id);
|
||||
if (track)
|
||||
nrlock.inc();
|
||||
}
|
||||
@ -93,7 +96,7 @@ public:
|
||||
if (pthread_rwlock_tryrdlock(&L) == 0) {
|
||||
if (track)
|
||||
nrlock.inc();
|
||||
if (g_lockdep) id = lockdep_locked(name.c_str(), id);
|
||||
if (lockdep && g_lockdep) id = lockdep_locked(name.c_str(), id);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -104,17 +107,20 @@ public:
|
||||
|
||||
// write
|
||||
void get_write(bool lockdep=true) {
|
||||
if (lockdep && g_lockdep) id = lockdep_will_lock(name.c_str(), id);
|
||||
if (lockdep && this->lockdep && g_lockdep)
|
||||
id = lockdep_will_lock(name.c_str(), id);
|
||||
int r = pthread_rwlock_wrlock(&L);
|
||||
assert(r == 0);
|
||||
if (g_lockdep) id = lockdep_locked(name.c_str(), id);
|
||||
if (lockdep && this->lockdep && g_lockdep)
|
||||
id = lockdep_locked(name.c_str(), id);
|
||||
if (track)
|
||||
nwlock.inc();
|
||||
|
||||
}
|
||||
bool try_get_write(bool lockdep=true) {
|
||||
if (pthread_rwlock_trywrlock(&L) == 0) {
|
||||
if (lockdep && g_lockdep) id = lockdep_locked(name.c_str(), id);
|
||||
if (lockdep && this->lockdep && g_lockdep)
|
||||
id = lockdep_locked(name.c_str(), id);
|
||||
if (track)
|
||||
nwlock.inc();
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user