]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
RWLock: make read locking methods const
authorJosh Durgin <josh.durgin@inktank.com>
Wed, 9 Apr 2014 20:15:32 +0000 (13:15 -0700)
committerJosh Durgin <josh.durgin@inktank.com>
Wed, 9 Apr 2014 21:31:35 +0000 (14:31 -0700)
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 <josh.durgin@inktank.com>
src/common/RWLock.h

index b3f7cb03cb28b2cdb9548f097ec55758060c018d..cef5b0c64d2b98d5bfd848433a34fec234cea2fe 100644 (file)
@@ -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() {