From: Josh Durgin Date: Wed, 9 Apr 2014 20:15:32 +0000 (-0700) Subject: RWLock: make read locking methods const X-Git-Tag: v0.80-rc1~70^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=970d53fc0fefc89ffe7550880a4aaa36bd534955;p=ceph.git RWLock: make read locking methods const This allows methods using RWLock for reading to be declared const. There might be cases where we'd want to take a write lock in a const method, but right now that's unnecessary, and I'd rather get a compile error. Signed-off-by: Josh Durgin --- diff --git a/src/common/RWLock.h b/src/common/RWLock.h index b3f7cb03cb2..cef5b0c64d2 100644 --- a/src/common/RWLock.h +++ b/src/common/RWLock.h @@ -40,25 +40,25 @@ public: pthread_rwlock_destroy(&L); } - void unlock() { + void unlock() const { if (g_lockdep) lockdep_will_unlock(name, id); pthread_rwlock_unlock(&L); } // read - void get_read() { + void get_read() const { if (g_lockdep) lockdep_will_lock(name, id); pthread_rwlock_rdlock(&L); if (g_lockdep) lockdep_locked(name, id); } - bool try_get_read() { + bool try_get_read() const { if (pthread_rwlock_tryrdlock(&L) == 0) { if (g_lockdep) lockdep_locked(name, id); return true; } return false; } - void put_read() { + void put_read() const { unlock(); } @@ -81,10 +81,10 @@ public: public: class RLocker { - RWLock &m_lock; + const RWLock &m_lock; public: - RLocker(RWLock& lock) : m_lock(lock) { + RLocker(const RWLock& lock) : m_lock(lock) { m_lock.get_read(); } ~RLocker() {