]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: use atomic_t for reference count
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 1 Mar 2011 14:05:41 +0000 (06:05 -0800)
committerJosh Durgin <josh.durgin@dreamhost.com>
Fri, 4 Mar 2011 00:04:27 +0000 (16:04 -0800)
Use an use atomic_t for the reference count in IoCtxImpl.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/librados.cc

index b8bd003b4180c024fea9ab0b92925e0417c438d8..496aa3ba22678737f97c28f4ef13560c6fb2152e 100644 (file)
@@ -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;
   }
 };