]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore/BlueStore: use std::atomic
authorSage Weil <sage@redhat.com>
Wed, 27 Jan 2016 19:01:03 +0000 (14:01 -0500)
committerSage Weil <sage@redhat.com>
Wed, 27 Jan 2016 19:10:22 +0000 (14:10 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h

index 8beaa8496f6b912b33f2e0ec0dd3a9af78f9f654..d4b23ebf6bab0b0c6145c4dbe0ddf63c1b887abd 100644 (file)
@@ -454,7 +454,7 @@ static void get_wal_key(uint64_t seq, string *out)
 
 void BlueStore::Enode::put()
 {
-  int final = nref.dec();
+  int final = --nref;
   if (final == 0) {
     dout(20) << __func__ << " removing self from set " << enode_set << dendl;
     enode_set->uset.erase(*this);
@@ -467,14 +467,6 @@ void BlueStore::Enode::put()
 #undef dout_prefix
 #define dout_prefix *_dout << "bluestore.onode(" << this << ") "
 
-BlueStore::Onode::Onode(const ghobject_t& o, const string& k)
-  : nref(0),
-    oid(o),
-    key(k),
-    dirty(false),
-    exists(true) {
-}
-
 void BlueStore::Onode::flush()
 {
   std::unique_lock<std::mutex> l(flush_lock);
@@ -600,7 +592,7 @@ int BlueStore::OnodeHashLRU::trim(int max)
     --p;
   while (num > 0) {
     Onode *o = &*p;
-    int refs = o->nref.read();
+    int refs = o->nref.load();
     if (refs > 1) {
       dout(20) << __func__ << "  " << o->oid << " has " << refs
               << " refs; stopping with " << num << " left to trim" << dendl;
index d994d58f4e31db8ab320294f8609ea2433591f78..46d01b6fe60e7eda15f76be45c6cadc4371489ad 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <unistd.h>
 
+#include <atomic>
 #include <mutex>
 #include <condition_variable>
 
@@ -54,7 +55,7 @@ public:
   struct EnodeSet;
 
   struct Enode : public boost::intrusive::unordered_set_base_hook<> {
-    atomic_t nref;        ///< reference count
+    std::atomic_int nref;        ///< reference count
     uint32_t hash;
     string key;           ///< key under PREFIX_OBJ where we are stored
     EnodeSet *enode_set;  ///< reference to the containing set
@@ -70,7 +71,7 @@ public:
        enode_set(s) {}
 
     void get() {
-      nref.inc();
+      ++nref;
     }
     void put();
 
@@ -109,7 +110,7 @@ public:
 
   /// an in-memory object
   struct Onode {
-    atomic_t nref;  ///< reference count
+    std::atomic_int nref;  ///< reference count
 
     ghobject_t oid;
     string key;     ///< key under PREFIX_OBJ where we are stored
@@ -128,14 +129,20 @@ public:
     uint64_t tail_offset;
     bufferlist tail_bl;
 
-    Onode(const ghobject_t& o, const string& k);
+    Onode(const ghobject_t& o, const string& k)
+      : nref(0),
+       oid(o),
+       key(k),
+       dirty(false),
+       exists(true) {
+    }
 
     void flush();
     void get() {
-      nref.inc();
+      ++nref;
     }
     void put() {
-      if (nref.dec() == 0)
+      if (--nref == 0)
        delete this;
     }