]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
SimpleLock: use MutationRef instead of raw pointers
authorGreg Farnum <greg@inktank.com>
Wed, 12 Mar 2014 03:52:21 +0000 (20:52 -0700)
committerGreg Farnum <greg@inktank.com>
Fri, 4 Apr 2014 17:40:51 +0000 (10:40 -0700)
While we're here, remove the non-const get_xlock_by() (because
we don't need it). Also note we return a full MutationRef
(instead of a ref to the stored one). It's necessary in case we
don't have a set-up more() object.

Signed-off-by: Greg Farnum <greg@inktank.com>
src/mds/SimpleLock.h

index 4b9b7f5150ff2787043fbabb20edc2139f5150e6..eac05b1dd9128864f5018f0fa04cd98df2da74f9 100644 (file)
@@ -38,7 +38,9 @@ inline const char *get_lock_type_name(int t) {
   }
 }
 
-struct Mutation;
+#include "include/memory.h"
+struct MutationImpl;
+typedef ceph::shared_ptr<MutationImpl> MutationRef;
 
 extern "C" {
 #include "locks.h"
@@ -166,7 +168,7 @@ private:
 
     // local state
     int num_wrlock, num_xlock;
-    Mutation *xlock_by;
+    MutationRef xlock_by;
     client_t xlock_by_client;
     client_t excl_client;
 
@@ -175,14 +177,14 @@ private:
        gather_set.empty() &&
        num_wrlock == 0 &&
        num_xlock == 0 &&
-       xlock_by == NULL &&
+       xlock_by.get() == NULL &&
        xlock_by_client == -1 &&
        excl_client == -1;
     }
 
     unstable_bits_t() : num_wrlock(0),
                        num_xlock(0),
-                       xlock_by(NULL),
+                       xlock_by(),
                        xlock_by_client(-1),
                        excl_client(-1) {}
   };
@@ -476,7 +478,7 @@ public:
   }
 
   // xlock
-  void get_xlock(Mutation *who, client_t client) { 
+  void get_xlock(MutationRef& who, client_t client) { 
     assert(get_xlock_by() == 0);
     assert(state == LOCK_XLOCK || is_locallock() ||
           state == LOCK_LOCK /* if we are a slave */);
@@ -491,7 +493,7 @@ public:
           state == LOCK_LOCK /* if we are a slave */);
     if (!is_locallock())
       state = LOCK_XLOCKDONE;
-    more()->xlock_by = 0;
+    more()->xlock_by.reset();
   }
   void put_xlock() {
     assert(state == LOCK_XLOCK || state == LOCK_XLOCKDONE || is_locallock() ||
@@ -499,7 +501,7 @@ public:
     --more()->num_xlock;
     parent->put(MDSCacheObject::PIN_LOCK);
     if (more()->num_xlock == 0) {
-      more()->xlock_by = 0;
+      more()->xlock_by.reset();
       more()->xlock_by_client = -1;
       try_clear_more();
     }
@@ -516,11 +518,8 @@ public:
   bool is_xlocked_by_client(client_t c) const {
     return have_more() ? more()->xlock_by_client == c : false;
   }
-  Mutation *get_xlock_by() {
-    return have_more() ? more()->xlock_by : NULL;
-  }
-  const Mutation *get_xlock_by() const {
-    return have_more() ? more()->xlock_by : NULL;
+  MutationRef get_xlock_by() const {
+    return have_more() ? more()->xlock_by : MutationRef();
   }
   
   // lease