]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
memstore: use intrusive_ptr instead of shared_ptr
authorCasey Bodley <cbodley@redhat.com>
Tue, 11 Aug 2015 18:38:06 +0000 (14:38 -0400)
committerCasey Bodley <cbodley@redhat.com>
Wed, 26 Aug 2015 21:49:46 +0000 (17:49 -0400)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/os/MemStore.h

index 477e8fde63ed1ea1a564600efa85704d33dccc90..a3bed1cbad1be0a0765c9aa045bc5def86092014 100644 (file)
 #ifndef CEPH_MEMSTORE_H
 #define CEPH_MEMSTORE_H
 
+#include <boost/intrusive_ptr.hpp>
+
 #include "include/assert.h"
 #include "include/unordered_map.h"
 #include "include/memory.h"
 #include "common/Finisher.h"
+#include "common/RefCountedObj.h"
 #include "common/RWLock.h"
 #include "ObjectStore.h"
 
 class MemStore : public ObjectStore {
 public:
-  struct Object {
+  struct Object : public RefCountedObject {
     bufferlist data;
     map<string,bufferptr> xattr;
     bufferlist omap_header;
     map<string,bufferlist> omap;
 
+    typedef boost::intrusive_ptr<Object> Ref;
+    friend void intrusive_ptr_add_ref(Object *o) { o->get(); }
+    friend void intrusive_ptr_release(Object *o) { o->put(); }
+
     void encode(bufferlist& bl) const {
       ENCODE_START(1, 1, bl);
       ::encode(data, bl);
@@ -74,14 +81,18 @@ public:
       f->close_section();
     }
   };
-  typedef ceph::shared_ptr<Object> ObjectRef;
+  typedef Object::Ref ObjectRef;
 
-  struct Collection {
+  struct Collection : public RefCountedObject {
     ceph::unordered_map<ghobject_t, ObjectRef> object_hash;  ///< for lookup
     map<ghobject_t, ObjectRef,ghobject_t::BitwiseComparator> object_map;        ///< for iteration
     map<string,bufferptr> xattr;
     RWLock lock;   ///< for object_{map,hash}
 
+    typedef boost::intrusive_ptr<Collection> Ref;
+    friend void intrusive_ptr_add_ref(Collection *c) { c->get(); }
+    friend void intrusive_ptr_release(Collection *c) { c->put(); }
+
     // NOTE: The lock only needs to protect the object_map/hash, not the
     // contents of individual objects.  The osd is already sequencing
     // reads and writes, so we will never see them concurrently at this
@@ -136,7 +147,7 @@ public:
 
     Collection() : lock("MemStore::Collection::lock") {}
   };
-  typedef ceph::shared_ptr<Collection> CollectionRef;
+  typedef Collection::Ref CollectionRef;
 
 private:
   class OmapIteratorImpl : public ObjectMap::ObjectMapIteratorImpl {