]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: use atomic variable to track reference of MetaRequeset
authorYan, Zheng <zyan@redhat.com>
Thu, 9 Oct 2014 05:16:18 +0000 (13:16 +0800)
committerGreg Farnum <gfarnum@redhat.com>
Fri, 13 Feb 2015 22:41:09 +0000 (14:41 -0800)
this allow us to increase reference count of MetaRequest while not holding
the client_lock

Signed-off-by: Yan, Zheng <zyan@redhat.com>
(cherry picked from commit e464a7765230c504b3e3b88bcb1106f67b7c3eb9)

src/client/Client.cc
src/client/MetaRequest.h

index 26e6410aaf02a01937a08073b321db17780c6d91..216e58192666ed8f61b6accbe54391593f6aea47 100644 (file)
@@ -1438,15 +1438,15 @@ int Client::make_request(MetaRequest *request,
 
 void Client::put_request(MetaRequest *request)
 {
-  if (request->get_num_ref() == 1) {
+  if (request->_put()) {
     if (request->inode())
       put_inode(request->take_inode());
     if (request->old_inode())
       put_inode(request->take_old_inode());
     if (request->other_inode())
       put_inode(request->take_other_inode());
+    delete request;
   }
-  request->_put();
 }
 
 int Client::encode_inode_release(Inode *in, MetaRequest *req,
index 45a90dc02083c96fb289f57e22408a0b8bb6ad59..6f82b5c832f3e24be868477df5730d8ea2420f6d 100644 (file)
@@ -9,6 +9,7 @@
 #include "msg/msg_types.h"
 #include "include/xlist.h"
 #include "include/filepath.h"
+#include "include/atomic.h"
 #include "mds/mdstypes.h"
 
 #include "common/Mutex.h"
@@ -47,7 +48,7 @@ public:
   __u32    sent_on_mseq;       // mseq at last submission of this request
   int      num_fwd;            // # of times i've been forwarded
   int      retry_attempt;
-  int      ref;
+  atomic_t ref;
   
   MClientReply *reply;         // the reply
   bool kick;
@@ -126,17 +127,14 @@ public:
   Dentry *old_dentry();
 
   MetaRequest* get() {
-    ++ref;
+    ref.inc();
     return this;
   }
 
   /// psuedo-private put method; use Client::put_request()
-  void _put() {
-    if (--ref == 0)
-      delete this;
-  }
-  int get_num_ref() {
-    return ref;
+  bool _put() {
+    int v = ref.dec();
+    return v == 0;
   }
 
   // normal fields