From b2ceb75cf52dc0b39180b82db652f15333abddf3 Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Tue, 1 Mar 2011 06:05:41 -0800 Subject: [PATCH] librados: use atomic_t for reference count Use an use atomic_t for the reference count in IoCtxImpl. Signed-off-by: Colin McCabe --- src/librados.cc | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/librados.cc b/src/librados.cc index b8bd003b4180c..496aa3ba22678 100644 --- a/src/librados.cc +++ b/src/librados.cc @@ -72,8 +72,7 @@ using namespace std; ///////////////////////////// RadosClient ////////////////////////////// struct librados::IoCtxImpl { - Mutex lock; - int ref_cnt; + atomic_t ref_cnt; RadosClient *client; int poolid; string pool_name; @@ -84,7 +83,7 @@ struct librados::IoCtxImpl { uint32_t notify_timeout; IoCtxImpl(RadosClient *c, int pid, const char *pool_name_, snapid_t s = CEPH_NOSNAP) : - lock("librados::IoCtxImpl"), ref_cnt(0), client(c), poolid(pid), + ref_cnt(0), client(c), poolid(pid), pool_name(pool_name_), snap_seq(s), assert_ver(0), notify_timeout(g_conf.client_notify_timeout) {} @@ -105,17 +104,11 @@ struct librados::IoCtxImpl { } void get() { - lock.Lock(); - ref_cnt++; - lock.Unlock(); + ref_cnt.inc(); } void put() { - lock.Lock(); - assert(ref_cnt > 0); - ref_cnt--; - lock.Unlock(); - if (!ref_cnt) + if (ref_cnt.dec() == 0) delete this; } }; -- 2.39.5