]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/RefCountedObject: allow refs to const objects
authorSage Weil <sage@redhat.com>
Sat, 18 Feb 2017 21:15:33 +0000 (16:15 -0500)
committerSage Weil <sage@redhat.com>
Mon, 20 Feb 2017 19:13:03 +0000 (14:13 -0500)
Make nref mutable, and make a const and non-const get() variant.

Signed-off-by: Sage Weil <sage@redhat.com>
src/common/RefCountedObj.cc
src/common/RefCountedObj.h

index 236a2b11ffd2c4195019ddba7af2405bd0bb0918..058a18b339998786c41033f6f9aa802500fac553 100644 (file)
 
 #include "common/RefCountedObj.h"
 
-void intrusive_ptr_add_ref(RefCountedObject *p) {
+void intrusive_ptr_add_ref(const RefCountedObject *p) {
   p->get();
 }
-void intrusive_ptr_release(RefCountedObject *p) {
+void intrusive_ptr_release(const RefCountedObject *p) {
   p->put();
 }
 
index cd886f66f3757c25935ae0014162aa08ec49ce7d..2da83d1a760afeb4a2f778cd6156873f70459531 100644 (file)
@@ -23,7 +23,7 @@
 
 struct RefCountedObject {
 private:
-  atomic_t nref;
+  mutable atomic_t nref;
   CephContext *cct;
 public:
   RefCountedObject(CephContext *c = NULL, int n=1) : nref(n), cct(c) {}
@@ -31,6 +31,14 @@ public:
     assert(nref.read() == 0);
   }
   
+  const RefCountedObject *get() const {
+    int v = nref.inc();
+    if (cct)
+      lsubdout(cct, refs, 1) << "RefCountedObject::get " << this << " "
+                            << (v - 1) << " -> " << v
+                            << dendl;
+    return this;
+  }
   RefCountedObject *get() {
     int v = nref.inc();
     if (cct)
@@ -39,7 +47,7 @@ public:
                             << dendl;
     return this;
   }
-  void put() {
+  void put() const {
     CephContext *local_cct = cct;
     int v = nref.dec();
     if (v == 0) {
@@ -151,7 +159,7 @@ struct RefCountedWaitObject {
   }
 };
 
-void intrusive_ptr_add_ref(RefCountedObject *p);
-void intrusive_ptr_release(RefCountedObject *p);
+void intrusive_ptr_add_ref(const RefCountedObject *p);
+void intrusive_ptr_release(const RefCountedObject *p);
 
 #endif