From: Sage Weil Date: Wed, 27 Jan 2016 19:01:03 +0000 (-0500) Subject: os/bluestore/BlueStore: use std::atomic X-Git-Tag: v10.0.4~101^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4db22fdd6447145be5ce6713747469528f2181d3;p=ceph.git os/bluestore/BlueStore: use std::atomic Signed-off-by: Sage Weil --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 8beaa8496f6b..d4b23ebf6bab 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -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 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; diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index d994d58f4e31..46d01b6fe60e 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -19,6 +19,7 @@ #include +#include #include #include @@ -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; }