]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/kstore: use std::atomic
authorJianjian Huo <samuel.huo@gmail.com>
Wed, 17 Feb 2016 05:36:21 +0000 (00:36 -0500)
committerJianjian Huo <samuel.huo@gmail.com>
Wed, 17 Feb 2016 05:36:21 +0000 (00:36 -0500)
Signed-off-by: Jianjian Huo <samuel.huo@gmail.com>
src/os/kstore/KStore.cc
src/os/kstore/KStore.h

index 8ada042c8dfb0c8c50ef26d26e7807ff9118792b..219150aa5a5ab983d586d37c5a58a4845ca44ed3 100644 (file)
@@ -403,15 +403,6 @@ static void get_omap_tail(uint64_t id, string *out)
 #undef dout_prefix
 #define dout_prefix *_dout << "kstore.onode(" << this << ") "
 
-KStore::Onode::Onode(const ghobject_t& o, const string& k)
-  : nref(0),
-    oid(o),
-    key(k),
-    dirty(false),
-    exists(true),
-    flush_lock("KStore::Onode::flush_lock") {
-}
-
 void KStore::Onode::flush()
 {
   Mutex::Locker l(flush_lock);
@@ -552,7 +543,7 @@ int KStore::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 ecddae5cfa7ab7684591b7bacbcc4a830a00e3a0..1bc857b2c2ab1e8452bc5f8a5b9f05511193cda6 100644 (file)
@@ -19,6 +19,8 @@
 
 #include <unistd.h>
 
+#include <atomic>
+
 #include "include/assert.h"
 #include "include/unordered_map.h"
 #include "include/memory.h"
@@ -42,7 +44,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
@@ -61,14 +63,21 @@ public:
 
     map<uint64_t,bufferlist> pending_stripes;  ///< unwritten stripes
 
-    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),
+       flush_lock("KStore::Onode::flush_lock") {
+    }
 
     void flush();
     void get() {
-      nref.inc();
+      ++nref;
     }
     void put() {
-      if (nref.dec() == 0)
+      if (--nref == 0)
        delete this;
     }