#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);
--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;
#include <unistd.h>
+#include <atomic>
+
#include "include/assert.h"
#include "include/unordered_map.h"
#include "include/memory.h"
/// 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
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;
}