]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
include/Context: s/Mutex/ceph::mutex/
authorKefu Chai <kchai@redhat.com>
Sun, 7 Jul 2019 04:34:19 +0000 (12:34 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 3 Aug 2019 03:27:19 +0000 (11:27 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/include/Context.h

index 3d85283815a8673b139a9b60fd48ec295a82e300..8a1d8e8516be7761df892703a8ad3c7c17287d7d 100644 (file)
@@ -24,7 +24,7 @@
 #include <memory>
 
 #include "include/ceph_assert.h"
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
 
 #define mydout(cct, v) lgeneric_subdout(cct, context, v)
 
@@ -263,18 +263,19 @@ template <class ContextType, class ContextInstanceType>
 class C_GatherBase {
 private:
   CephContext *cct;
-  int result;
+  int result = 0;
   ContextType *onfinish;
 #ifdef DEBUG_GATHER
   std::set<ContextType*> waitfor;
 #endif
-  int sub_created_count;
-  int sub_existing_count;
-  mutable Mutex lock;
-  bool activated;
+  int sub_created_count = 0;
+  int sub_existing_count = 0;
+  mutable ceph::recursive_mutex lock =
+    ceph::make_recursive_mutex("C_GatherBase::lock"); // disable lockdep
+  bool activated = false;
 
   void sub_finish(ContextType* sub, int r) {
-    lock.Lock();
+    lock.lock();
 #ifdef DEBUG_GATHER
     ceph_assert(waitfor.count(sub));
     waitfor.erase(sub);
@@ -288,10 +289,10 @@ private:
     if (r < 0 && result == 0)
       result = r;
     if ((activated == false) || (sub_existing_count != 0)) {
-      lock.Unlock();
+      lock.unlock();
       return;
     }
-    lock.Unlock();
+    lock.unlock();
     delete_me();
   }
 
@@ -326,10 +327,7 @@ private:
 
 public:
   C_GatherBase(CephContext *cct_, ContextType *onfinish_)
-    : cct(cct_), result(0), onfinish(onfinish_),
-      sub_created_count(0), sub_existing_count(0),
-      lock("C_GatherBase::lock", true, false), //disable lockdep
-      activated(false)
+    : cct(cct_), onfinish(onfinish_)
   {
     mydout(cct,10) << "C_GatherBase " << this << ".new" << dendl;
   }
@@ -337,23 +335,23 @@ public:
     mydout(cct,10) << "C_GatherBase " << this << ".delete" << dendl;
   }
   void set_finisher(ContextType *onfinish_) {
-    Mutex::Locker l(lock);
+    std::lock_guard l{lock};
     ceph_assert(!onfinish);
     onfinish = onfinish_;
   }
   void activate() {
-    lock.Lock();
+    lock.lock();
     ceph_assert(activated == false);
     activated = true;
     if (sub_existing_count != 0) {
-      lock.Unlock();
+      lock.unlock();
       return;
     }
-    lock.Unlock();
+    lock.unlock();
     delete_me();
   }
   ContextType *new_sub() {
-    Mutex::Locker l(lock);
+    std::lock_guard l{lock};
     ceph_assert(activated == false);
     sub_created_count++;
     sub_existing_count++;
@@ -366,12 +364,12 @@ public:
   }
 
   inline int get_sub_existing_count() const {
-    Mutex::Locker l(lock);
+    std::lock_guard l{lock};
     return sub_existing_count;
   }
 
   inline int get_sub_created_count() const {
-    Mutex::Locker l(lock);
+    std::lock_guard l{lock};
     return sub_created_count;
   }
 };