From 3429dc594d7c9b9075ec473fd45fe059a2d1cad5 Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Tue, 11 Mar 2014 20:52:21 -0700 Subject: [PATCH] SimpleLock: use MutationRef instead of raw pointers 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 --- src/mds/SimpleLock.h | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/mds/SimpleLock.h b/src/mds/SimpleLock.h index 4b9b7f5150ff2..eac05b1dd9128 100644 --- a/src/mds/SimpleLock.h +++ b/src/mds/SimpleLock.h @@ -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 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 -- 2.39.5