]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: close very small race condition
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 1 Jul 2011 07:18:42 +0000 (00:18 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 1 Jul 2011 07:23:39 +0000 (00:23 -0700)
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/include/atomic.h
src/librados.cc

index 2dc66cc64dc7181ca65cfb72367a4495316852ab..54d5b983f84cf8c7be7e065116f864dc4502e881 100644 (file)
@@ -29,8 +29,8 @@ namespace ceph {
     AO_t val;
   public:
     atomic_t(AO_t i=0) : val(i) {}
-    void inc() {
-      AO_fetch_and_add1(&val);
+    AO_t inc() {
+      return AO_fetch_and_add1(&val) + 1;
     }
     AO_t dec() {
       return AO_fetch_and_sub1_write(&val) - 1;
index 54af457e1a1c7b817d45e81a4750cb6b6b4cfdee..40d5df09eac6da1c99eb8ec95fec7b0b0a96e388 100644 (file)
@@ -850,8 +850,7 @@ connect()
 
   messenger->add_dispatcher_head(this);
 
-  rados_instance.inc();
-  nonce = getpid() + (1000000 * (uint64_t)rados_instance.read());
+  nonce = getpid() + (1000000 * (uint64_t)rados_instance.inc());
 
   messenger->start_with_nonce(nonce);
   messenger->add_dispatcher_head(this);