Skip to content

Commit

Permalink
Merge pull request #3963 from dachary/wip-10153-firefly
Browse files Browse the repository at this point in the history
Rados.shutdown() dies with Illegal instruction (core dumped)

Reviewed-by: Yehuda Sadeh <yehuda@redhat.com>
  • Loading branch information
Loic Dachary committed Apr 27, 2015
2 parents 51ff2b6 + 5404fbf commit dd15e54
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/common/RWLock.h
Expand Up @@ -19,28 +19,44 @@

#include <pthread.h>
#include "lockdep.h"
#include "include/atomic.h"

class RWLock
{
mutable pthread_rwlock_t L;
const char *name;
mutable int id;
mutable atomic_t nrlock, nwlock;

public:
RWLock(const RWLock& other);
const RWLock& operator=(const RWLock& other);

RWLock(const char *n) : name(n), id(-1) {
RWLock(const char *n) : name(n), id(-1), nrlock(0), nwlock(0) {
pthread_rwlock_init(&L, NULL);
if (g_lockdep) id = lockdep_register(name);
}

bool is_locked() const {
return (nrlock.read() > 0) || (nwlock.read() > 0);
}

bool is_wlocked() const {
return (nwlock.read() > 0);
}
virtual ~RWLock() {
pthread_rwlock_unlock(&L);
// The following check is racy but we are about to destroy
// the object and we assume that there are no other users.
assert(!is_locked());
pthread_rwlock_destroy(&L);
}

void unlock() const {
if (nwlock.read() > 0) {
nwlock.dec();
} else {
nrlock.dec();
}
if (g_lockdep) id = lockdep_will_unlock(name, id);
pthread_rwlock_unlock(&L);
}
Expand All @@ -50,9 +66,11 @@ class RWLock
if (g_lockdep) id = lockdep_will_lock(name, id);
pthread_rwlock_rdlock(&L);
if (g_lockdep) id = lockdep_locked(name, id);
nrlock.inc();
}
bool try_get_read() const {
if (pthread_rwlock_tryrdlock(&L) == 0) {
nrlock.inc();
if (g_lockdep) id = lockdep_locked(name, id);
return true;
}
Expand All @@ -67,10 +85,12 @@ class RWLock
if (g_lockdep) id = lockdep_will_lock(name, id);
pthread_rwlock_wrlock(&L);
if (g_lockdep) id = lockdep_locked(name, id);
nwlock.inc();
}
bool try_get_write() {
if (pthread_rwlock_trywrlock(&L) == 0) {
if (g_lockdep) id = lockdep_locked(name, id);
nwlock.inc();
return true;
}
return false;
Expand Down

0 comments on commit dd15e54

Please sign in to comment.