]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
test/osd: s/Mutex/ceph::mutex/
authorKefu Chai <kchai@redhat.com>
Wed, 17 Jul 2019 08:28:43 +0000 (16:28 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 3 Aug 2019 03:27:20 +0000 (11:27 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/test/osd/RadosModel.h
src/test/osd/TestOpStat.cc
src/test/osd/TestOpStat.h
src/test/osd/TestRados.cc

index b773cf38030adcec94b58a3d17c7313857c75b3c..16302d2606799ed22b6b8cdfe9d9162b29ea4dd1 100644 (file)
@@ -2,8 +2,7 @@
 // vim: ts=8 sw=2 smarttab
 #include "include/int_types.h"
 
-#include "common/Mutex.h"
-#include "common/Cond.h"
+#include "common/ceph_mutex.h"
 #include "include/rados/librados.hpp"
 
 #include <iostream>
@@ -74,31 +73,29 @@ enum TestOpType {
 class TestWatchContext : public librados::WatchCtx2 {
   TestWatchContext(const TestWatchContext&);
 public:
-  Cond cond;
-  uint64_t handle;
-  bool waiting;
-  Mutex lock;
-  TestWatchContext() : handle(0), waiting(false),
-                      lock("watch lock") {}
+  ceph::condition_variable cond;
+  uint64_t handle = 0;
+  bool waiting = false;
+  ceph::mutex lock = ceph::make_mutex("watch lock");
+  TestWatchContext() = default;
   void handle_notify(uint64_t notify_id, uint64_t cookie,
                     uint64_t notifier_id,
                     bufferlist &bl) override {
-    Mutex::Locker l(lock);
+    std::lock_guard l{lock};
     waiting = false;
-    cond.SignalAll();
+    cond.notify_all();
   }
   void handle_error(uint64_t cookie, int err) override {
-    Mutex::Locker l(lock);
+    std::lock_guard l{lock};
     cout << "watch handle_error " << err << std::endl;
   }
   void start() {
-    Mutex::Locker l(lock);
+    std::lock_guard l{lock};
     waiting = true;
   }
   void wait() {
-    Mutex::Locker l(lock);
-    while (waiting)
-      cond.Wait(lock);
+    std::unique_lock l{lock};
+    cond.wait(l, [this] { return !waiting; });
   }
   uint64_t &get_handle() {
     return handle;
@@ -163,8 +160,8 @@ public:
 
 class RadosTestContext {
 public:
-  Mutex state_lock;
-  Cond wait_cond;
+  ceph::mutex state_lock = ceph::make_mutex("Context Lock");
+  ceph::condition_variable wait_cond;
   map<int, map<string,ObjectDesc> > pool_obj_cont;
   set<string> oid_in_use;
   set<string> oid_not_in_use;
@@ -213,7 +210,6 @@ public:
                   const string &low_tier_pool_name,
                   bool enable_dedup,
                   const char *id = 0) :
-    state_lock("Context Lock"),
     pool_obj_cont(),
     current_snap(0),
     pool_name(pool_name),
@@ -302,7 +298,7 @@ public:
   {
     ceph_assert(initialized);
     list<TestOp*> inflight;
-    state_lock.Lock();
+    std::unique_lock state_locker{state_lock};
 
     TestOp *next = gen->next(*this);
     TestOp *waiting = NULL;
@@ -315,11 +311,11 @@ public:
       if (next) {
        inflight.push_back(next);
       }
-      state_lock.Unlock();
+      state_lock.unlock();
       if (next) {
        (*inflight.rbegin())->begin();
       }
-      state_lock.Lock();
+      state_lock.lock();
       while (1) {
        for (list<TestOp*>::iterator i = inflight.begin();
             i != inflight.end();) {
@@ -334,7 +330,7 @@ public:
        
        if (inflight.size() >= (unsigned) max_in_flight || (!next && !inflight.empty())) {
          cout << " waiting on " << inflight.size() << std::endl;
-         wait();
+         wait_cond.wait(state_locker);
        } else {
          break;
        }
@@ -346,17 +342,11 @@ public:
        next = gen->next(*this);
       }
     }
-    state_lock.Unlock();
-  }
-
-  void wait()
-  {
-    wait_cond.Wait(state_lock);
   }
 
   void kick()
   {
-    wait_cond.Signal();
+    wait_cond.notify_all();
   }
 
   TestWatchContext *get_watch_context(const string &oid) {
@@ -594,7 +584,7 @@ public:
     ContDesc cont;
     set<string> to_remove;
     {
-      Mutex::Locker l(context->state_lock);
+      std::lock_guard l{context->state_lock};
       ObjectDesc obj;
       if (!context->find_object(oid, &obj)) {
        context->kick();
@@ -651,7 +641,7 @@ public:
 
   void _finish(CallbackInfo *info) override
   {
-    Mutex::Locker l(context->state_lock);
+    std::lock_guard l{context->state_lock};
     done = true;
     context->update_object_version(oid, comp->get_version64());
     context->oid_in_use.erase(oid);
@@ -687,7 +677,7 @@ public:
   {
     ContDesc cont;
     {
-      Mutex::Locker l(context->state_lock);
+      std::lock_guard l{context->state_lock};
       cont = ContDesc(context->seq_num, context->current_snap,
                      context->seq_num, "");
       context->oid_in_use.insert(oid);
@@ -726,7 +716,7 @@ public:
     }
 
     {
-      Mutex::Locker l(context->state_lock);
+      std::lock_guard l{context->state_lock};
       context->update_object_header(oid, header);
       context->update_object_attrs(oid, omap);
     }
@@ -741,7 +731,7 @@ public:
 
   void _finish(CallbackInfo *info) override
   {
-    Mutex::Locker l(context->state_lock);
+    std::lock_guard l{context->state_lock};
     int r;
     if ((r = comp->get_return_value())) {
       cerr << "err " << r << std::endl;
@@ -795,7 +785,7 @@ public:
                
   void _begin() override
   {
-    context->state_lock.Lock();
+    std::lock_guard state_locker{context->state_lock};
     done = 0;
     stringstream acc;
     acc << context->prefix << "OID: " << oid << " snap " << context->current_snap << std::endl;
@@ -903,13 +893,12 @@ public:
       &read_op,
       librados::OPERATION_ORDER_READS_WRITES,  // order wrt previous write/update
       0);
-    context->state_lock.Unlock();
   }
 
   void _finish(CallbackInfo *info) override
   {
     ceph_assert(info);
-    context->state_lock.Lock();
+    std::lock_guard state_locker{context->state_lock};
     uint64_t tid = info->id;
 
     cout << num << ":  finishing write tid " << tid << " to " << context->prefix + oid << std::endl;
@@ -963,7 +952,6 @@ public:
       context->kick();
       done = true;
     }
-    context->state_lock.Unlock();
   }
 
   bool finished() override
@@ -1001,7 +989,7 @@ public:
 
   void _begin() override
   {
-    context->state_lock.Lock();
+    std::lock_guard state_locker{context->state_lock};
     done = 0;
     stringstream acc;
     acc << context->prefix << "OID: " << oid << " snap " << context->current_snap << std::endl;
@@ -1080,13 +1068,12 @@ public:
       &read_op,
       librados::OPERATION_ORDER_READS_WRITES,  // order wrt previous write/update
       0);
-    context->state_lock.Unlock();
   }
 
   void _finish(CallbackInfo *info) override
   {
     ceph_assert(info);
-    context->state_lock.Lock();
+    std::lock_guard state_locker{context->state_lock};
     uint64_t tid = info->id;
 
     cout << num << ":  finishing writesame tid " << tid << " to " << context->prefix + oid << std::endl;
@@ -1140,7 +1127,6 @@ public:
       context->kick();
       done = true;
     }
-    context->state_lock.Unlock();
   }
 
   bool finished() override
@@ -1167,10 +1153,9 @@ public:
 
   void _begin() override
   {
-    context->state_lock.Lock();
+    std::unique_lock state_locker{context->state_lock};
     if (context->get_watch_context(oid)) {
       context->kick();
-      context->state_lock.Unlock();
       return;
     }
 
@@ -1185,7 +1170,7 @@ public:
     context->remove_object(oid);
 
     interval_set<uint64_t> ranges;
-    context->state_lock.Unlock();
+    state_locker.unlock();
 
     int r = 0;
     if (rand() % 2) {
@@ -1201,11 +1186,10 @@ public:
       ceph_abort();
     }
 
-    context->state_lock.Lock();
+    state_locker.lock();
     context->oid_in_use.erase(oid);
     context->oid_not_in_use.insert(oid);
     context->kick();
-    context->state_lock.Unlock();
   }
 
   string getType() override
@@ -1290,7 +1274,7 @@ public:
 
   void _begin() override
   {
-    context->state_lock.Lock();
+    std::unique_lock state_locker{context->state_lock};
     if (!(rand() % 4) && !context->snaps.empty()) {
       snap = rand_choose(context->snaps)->first;
       in_use = context->snaps_in_use.lookup_or_create(snap, snap);
@@ -1312,7 +1296,7 @@ public:
       std::cout << num << ":  expect " << old_value.most_recent() << std::endl;
 
     TestWatchContext *ctx = context->get_watch_context(oid);
-    context->state_lock.Unlock();
+    state_locker.unlock();
     if (ctx) {
       ceph_assert(old_value.exists);
       TestAlarm alarm;
@@ -1329,7 +1313,7 @@ public:
       std::cerr << num << ":  notified, waiting" << std::endl;
       ctx->wait();
     }
-    context->state_lock.Lock();
+    state_locker.lock();
     if (snap >= 0) {
       context->io_ctx.snap_set_read(context->snaps[snap]);
     }
@@ -1374,12 +1358,11 @@ public:
     if (snap >= 0) {
       context->io_ctx.snap_set_read(0);
     }
-    context->state_lock.Unlock();
   }
 
   void _finish(CallbackInfo *info) override
   {
-    Mutex::Locker l(context->state_lock);
+    std::unique_lock state_locker{context->state_lock};
     ceph_assert(!done);
     ceph_assert(waiting_on > 0);
     if (--waiting_on) {
@@ -1592,12 +1575,10 @@ public:
       ceph_assert(!context->io_ctx.selfmanaged_snap_create(&snap));
     }
 
-    context->state_lock.Lock();
+    std::unique_lock state_locker{context->state_lock};
     context->add_snap(snap);
 
-    if (context->pool_snaps) {
-      context->state_lock.Unlock();
-    } else {
+    if (!context->pool_snaps) {
       vector<uint64_t> snapset(context->snaps.size());
 
       int j = 0;
@@ -1607,7 +1588,7 @@ public:
        snapset[j] = i->second;
       }
 
-      context->state_lock.Unlock();
+      state_locker.unlock();
 
       int r = context->io_ctx.selfmanaged_snap_set_write_ctx(context->seq, snapset);
       if (r) {
@@ -1636,7 +1617,7 @@ public:
 
   void _begin() override
   {
-    context->state_lock.Lock();
+    std::unique_lock state_locker{context->state_lock};
     uint64_t snap = context->snaps[to_remove];
     context->remove_snap(to_remove);
 
@@ -1662,7 +1643,6 @@ public:
        ceph_abort();
       }
     }
-    context->state_lock.Unlock();
   }
 
   string getType() override
@@ -1684,23 +1664,22 @@ public:
 
   void _begin() override
   {
-    context->state_lock.Lock();
+    std::unique_lock state_locker{context->state_lock};
     ObjectDesc contents;
     context->find_object(oid, &contents);
     if (contents.deleted()) {
       context->kick();
-      context->state_lock.Unlock();
       return;
     }
     context->oid_in_use.insert(oid);
     context->oid_not_in_use.erase(oid);
 
     TestWatchContext *ctx = context->get_watch_context(oid);
-    context->state_lock.Unlock();
+    state_locker.unlock();
     int r;
     if (!ctx) {
       {
-       Mutex::Locker l(context->state_lock);
+       std::lock_guard l{context->state_lock};
        ctx = context->watch(oid);
       }
 
@@ -1710,7 +1689,7 @@ public:
     } else {
       r = context->io_ctx.unwatch2(ctx->get_handle());
       {
-       Mutex::Locker l(context->state_lock);
+       std::lock_guard l{context->state_lock};
        context->unwatch(oid);
       }
     }
@@ -1721,7 +1700,7 @@ public:
     }
 
     {
-      Mutex::Locker l(context->state_lock);
+      std::lock_guard l{context->state_lock};
       context->oid_in_use.erase(oid);
       context->oid_not_in_use.insert(oid);
     }
@@ -1757,16 +1736,16 @@ public:
 
   void _begin() override
   {
-    context->state_lock.Lock();
+    context->state_lock.lock();
     if (context->get_watch_context(oid)) {
       context->kick();
-      context->state_lock.Unlock();
+      context->state_lock.unlock();
       return;
     }
 
     if (context->snaps.empty()) {
       context->kick();
-      context->state_lock.Unlock();
+      context->state_lock.unlock();
       done = true;
       return;
     }
@@ -1790,7 +1769,7 @@ public:
 
     outstanding -= (!existed_before) + (!existed_after);
 
-    context->state_lock.Unlock();
+    context->state_lock.unlock();
 
     bufferlist bl, bl2;
     zero_write_op1.append(bl);
@@ -1836,7 +1815,7 @@ public:
 
   void _finish(CallbackInfo *info) override
   {
-    Mutex::Locker l(context->state_lock);
+    std::lock_guard l{context->state_lock};
     uint64_t tid = info->id;
     cout << num << ":  finishing rollback tid " << tid
         << " to " << context->prefix + oid << std::endl;
@@ -1897,7 +1876,7 @@ public:
   {
     ContDesc cont;
     {
-      Mutex::Locker l(context->state_lock);
+      std::lock_guard l{context->state_lock};
       cont = ContDesc(context->seq_num, context->current_snap,
                      context->seq_num, "");
       context->oid_in_use.insert(oid);
@@ -1941,7 +1920,7 @@ public:
 
   void _finish(CallbackInfo *info) override
   {
-    Mutex::Locker l(context->state_lock);
+    std::lock_guard l{context->state_lock};
 
     // note that the read can (and atm will) come back before the
     // write reply, but will reflect the update and the versions will
@@ -2059,7 +2038,7 @@ public:
 
   void _begin() override
   {
-    context->state_lock.Lock();
+    context->state_lock.lock();
     std::cout << num << ": chunk read oid " << oid << " snap " << snap << std::endl;
     done = 0;
     for (uint32_t i = 0; i < 2; i++) {
@@ -2071,7 +2050,7 @@ public:
     if (old_value.chunk_info.size() == 0) {
       std::cout << ":  no chunks" << std::endl;
       context->kick();
-      context->state_lock.Unlock();
+      context->state_lock.unlock();
       done = true;
       return;
     }
@@ -2105,7 +2084,7 @@ public:
              << " tgt_oid " << tgt_oid << std::endl;
 
     TestWatchContext *ctx = context->get_watch_context(oid);
-    context->state_lock.Unlock();
+    context->state_lock.unlock();
     if (ctx) {
       ceph_assert(old_value.exists);
       TestAlarm alarm;
@@ -2122,7 +2101,7 @@ public:
       std::cerr << num << ":  notified, waiting" << std::endl;
       ctx->wait();
     }
-    context->state_lock.Lock();
+    std::lock_guard state_locker{context->state_lock};
 
     _do_read(op, offset, length, 0);
 
@@ -2139,12 +2118,11 @@ public:
                                        flags, NULL));
 
     waiting_on++;
-    context->state_lock.Unlock();
   }
 
   void _finish(CallbackInfo *info) override
   {
-    Mutex::Locker l(context->state_lock);
+    std::lock_guard l{context->state_lock};
     ceph_assert(!done);
     ceph_assert(waiting_on > 0);
     if (--waiting_on) {
@@ -2253,7 +2231,7 @@ public:
 
   void _begin() override
   {
-    Mutex::Locker l(context->state_lock);
+    std::lock_guard l{context->state_lock};
     context->oid_in_use.insert(oid_src);
     context->oid_not_in_use.erase(oid_src);
 
@@ -2277,7 +2255,7 @@ public:
 
   void _finish(CallbackInfo *info) override
   {
-    Mutex::Locker l(context->state_lock);
+    std::lock_guard l{context->state_lock};
 
     if (info->id == 0) {
       ceph_assert(comp->is_complete());
@@ -2340,7 +2318,7 @@ public:
 
   void _begin() override
   {
-    Mutex::Locker l(context->state_lock);
+    std::lock_guard l{context->state_lock};
     context->oid_in_use.insert(oid);
     context->oid_not_in_use.erase(oid);
 
@@ -2370,7 +2348,7 @@ public:
 
   void _finish(CallbackInfo *info) override
   {
-    Mutex::Locker l(context->state_lock);
+    std::lock_guard l{context->state_lock};
 
     if (info->id == 0) {
       ceph_assert(comp->is_complete());
@@ -2452,7 +2430,7 @@ public:
 
   void _begin() override
   {
-    Mutex::Locker l(context->state_lock);
+    std::lock_guard l{context->state_lock};
     context->oid_in_use.insert(oid);
     context->oid_not_in_use.erase(oid);
     context->oid_redirect_in_use.insert(oid_tgt);
@@ -2545,7 +2523,7 @@ public:
 
   void _finish(CallbackInfo *info) override
   {
-    Mutex::Locker l(context->state_lock);
+    std::lock_guard l{context->state_lock};
 
     if (info->id == 0) {
       ceph_assert(comp->is_complete());
@@ -2597,10 +2575,9 @@ public:
 
   void _begin() override
   {
-    context->state_lock.Lock();
+    std::unique_lock state_locker{context->state_lock};
     if (context->get_watch_context(oid)) {
       context->kick();
-      context->state_lock.Unlock();
       return;
     }
 
@@ -2614,7 +2591,7 @@ public:
 
     context->remove_object(oid);
 
-    context->state_lock.Unlock();
+    state_locker.unlock();
 
     comp = context->rados.aio_create_completion();
     op.remove();
@@ -2627,8 +2604,7 @@ public:
       cerr << "r is " << r << " while deleting " << oid << " and present is " << present << std::endl;
       ceph_abort();
     }
-
-    context->state_lock.Lock();
+    state_locker.lock();
     context->oid_in_use.erase(oid);
     context->oid_not_in_use.insert(oid);
     if(!context->redirect_objs[oid].empty()) {
@@ -2637,7 +2613,6 @@ public:
       context->update_object_redirect_target(oid, string());
     }
     context->kick();
-    context->state_lock.Unlock();
   }
 
   string getType() override
@@ -2664,7 +2639,7 @@ public:
 
   void _begin() override
   {
-    context->state_lock.Lock();
+    context->state_lock.lock();
 
     context->oid_in_use.insert(oid);
     context->oid_not_in_use.erase(oid);
@@ -2674,7 +2649,7 @@ public:
                                               new TestOp::CallbackInfo(0));
     completion = context->rados.aio_create_completion((void *) cb_arg, NULL,
                                                      &write_callback);
-    context->state_lock.Unlock();
+    context->state_lock.unlock();
 
     op.tier_promote();
     int r = context->io_ctx.aio_operate(context->prefix+oid, completion,
@@ -2684,7 +2659,7 @@ public:
 
   void _finish(CallbackInfo *info) override
   {
-    context->state_lock.Lock();
+    std::lock_guard l{context->state_lock};
     ceph_assert(!done);
     ceph_assert(completion->is_complete());
 
@@ -2703,7 +2678,6 @@ public:
     context->oid_not_in_use.insert(oid);
     context->kick();
     done = true;
-    context->state_lock.Unlock();
   }
 
   bool finished() override
@@ -2735,7 +2709,7 @@ public:
 
   void _begin() override
   {
-    context->state_lock.Lock();
+    context->state_lock.lock();
 
     context->oid_in_use.insert(oid);
     context->oid_not_in_use.erase(oid);
@@ -2745,7 +2719,7 @@ public:
                                               new TestOp::CallbackInfo(0));
     completion = context->rados.aio_create_completion((void *) cb_arg, NULL,
                                                      &write_callback);
-    context->state_lock.Unlock();
+    context->state_lock.unlock();
 
     op.tier_flush();
     int r = context->io_ctx.aio_operate(context->prefix+oid, completion,
@@ -2755,7 +2729,7 @@ public:
 
   void _finish(CallbackInfo *info) override
   {
-    context->state_lock.Lock();
+    context->state_lock.lock();
     ceph_assert(!done);
     ceph_assert(completion->is_complete());
 
@@ -2771,7 +2745,7 @@ public:
     context->oid_not_in_use.insert(oid);
     context->kick();
     done = true;
-    context->state_lock.Unlock();
+    context->state_lock.unlock();
   }
 
   bool finished() override
@@ -2813,7 +2787,7 @@ public:
   }
 
   void _finish(CallbackInfo *info) override {
-    Mutex::Locker l(context->state_lock);
+    std::lock_guard l{context->state_lock};
     if (!comp2) {
       if (ls.empty()) {
        cerr << num << ": no hitsets" << std::endl;
@@ -2877,7 +2851,7 @@ public:
 
   void _begin() override
   {
-    context->state_lock.Lock();
+    context->state_lock.lock();
     pair<TestOp*, TestOp::CallbackInfo*> *cb_arg =
       new pair<TestOp*, TestOp::CallbackInfo*>(this,
                                               new TestOp::CallbackInfo(0));
@@ -2887,7 +2861,7 @@ public:
     context->oid_in_use.insert(oid);
     context->oid_not_in_use.erase(oid);
     context->update_object_undirty(oid);
-    context->state_lock.Unlock();
+    context->state_lock.unlock();
 
     op.undirty();
     int r = context->io_ctx.aio_operate(context->prefix+oid, completion,
@@ -2897,7 +2871,7 @@ public:
 
   void _finish(CallbackInfo *info) override
   {
-    context->state_lock.Lock();
+    std::lock_guard state_locker{context->state_lock};
     ceph_assert(!done);
     ceph_assert(completion->is_complete());
     context->oid_in_use.erase(oid);
@@ -2905,7 +2879,6 @@ public:
     context->update_object_version(oid, completion->get_version64());
     context->kick();
     done = true;
-    context->state_lock.Unlock();
   }
 
   bool finished() override
@@ -2941,7 +2914,7 @@ public:
 
   void _begin() override
   {
-    context->state_lock.Lock();
+    context->state_lock.lock();
 
     if (!(rand() % 4) && !context->snaps.empty()) {
       snap = rand_choose(context->snaps)->first;
@@ -2960,7 +2933,7 @@ public:
 
     context->oid_in_use.insert(oid);
     context->oid_not_in_use.erase(oid);
-    context->state_lock.Unlock();
+    context->state_lock.unlock();
 
     if (snap >= 0) {
       context->io_ctx.snap_set_read(context->snaps[snap]);
@@ -2978,7 +2951,7 @@ public:
 
   void _finish(CallbackInfo *info) override
   {
-    context->state_lock.Lock();
+    std::lock_guard state_locker{context->state_lock};
     ceph_assert(!done);
     ceph_assert(completion->is_complete());
     context->oid_in_use.erase(oid);
@@ -2998,7 +2971,6 @@ public:
     }
     context->kick();
     done = true;
-    context->state_lock.Unlock();
   }
 
   bool finished() override
@@ -3039,7 +3011,7 @@ public:
 
   void _begin() override
   {
-    context->state_lock.Lock();
+    context->state_lock.lock();
 
     if (!(rand() % 4) && !context->snaps.empty()) {
       snap = rand_choose(context->snaps)->first;
@@ -3067,7 +3039,7 @@ public:
                                                      &write_callback);
     context->oid_flushing.insert(oid);
     context->oid_not_flushing.erase(oid);
-    context->state_lock.Unlock();
+    context->state_lock.unlock();
 
     unsigned flags = librados::OPERATION_IGNORE_CACHE;
     if (blocking) {
@@ -3087,7 +3059,7 @@ public:
 
   void _finish(CallbackInfo *info) override
   {
-    context->state_lock.Lock();
+    std::lock_guard state_locker{context->state_lock};
     ceph_assert(!done);
     ceph_assert(completion->is_complete());
     context->oid_flushing.erase(oid);
@@ -3107,7 +3079,6 @@ public:
     }
     context->kick();
     done = true;
-    context->state_lock.Unlock();
   }
 
   bool finished() override
@@ -3139,7 +3110,7 @@ public:
 
   void _begin() override
   {
-    context->state_lock.Lock();
+    context->state_lock.lock();
 
     int snap;
     if (!(rand() % 4) && !context->snaps.empty()) {
@@ -3159,7 +3130,7 @@ public:
                                               new TestOp::CallbackInfo(0));
     completion = context->rados.aio_create_completion((void *) cb_arg, NULL,
                                                      &write_callback);
-    context->state_lock.Unlock();
+    context->state_lock.unlock();
 
     op.cache_evict();
     int r = context->io_ctx.aio_operate(context->prefix+oid, completion,
@@ -3174,7 +3145,7 @@ public:
 
   void _finish(CallbackInfo *info) override
   {
-    context->state_lock.Lock();
+    std::lock_guard state_locker{context->state_lock};
     ceph_assert(!done);
     ceph_assert(completion->is_complete());
 
@@ -3193,7 +3164,6 @@ public:
     }
     context->kick();
     done = true;
-    context->state_lock.Unlock();
   }
 
   bool finished() override
index e8045fa43fbef34b692e538c7b37ff5a6644823f..48b87b885b0ea6eb216fda75de0b3ef74703a672 100644 (file)
@@ -8,15 +8,13 @@
 #include "TestOpStat.h"
 
 void TestOpStat::begin(TestOp *in) {
-  stat_lock.Lock();
+  std::lock_guard l{stat_lock};
   stats[in->getType()].begin(in);
-  stat_lock.Unlock();
 }
 
 void TestOpStat::end(TestOp *in) {
-  stat_lock.Lock();
+  std::lock_guard l{stat_lock};
   stats[in->getType()].end(in);
-  stat_lock.Unlock();
 }
 
 void TestOpStat::TypeStatus::export_latencies(map<double,uint64_t> &in) const
@@ -36,7 +34,7 @@ void TestOpStat::TypeStatus::export_latencies(map<double,uint64_t> &in) const
   
 std::ostream & operator<<(std::ostream &out, const TestOpStat &rhs)
 {
-  rhs.stat_lock.Lock();
+  std::lock_guard l{rhs.stat_lock};
   for (auto i = rhs.stats.begin();
        i != rhs.stats.end();
        ++i) {
@@ -56,6 +54,5 @@ std::ostream & operator<<(std::ostream &out, const TestOpStat &rhs)
          << j->second / 1000 << "ms" << std::endl;
     }
   }
-  rhs.stat_lock.Unlock();
   return out;
 }
index 314bb66c781b69eab445697a40fbfdd1db296a61..a279287fde646ff1a85a1839eb1631bd772687c5 100644 (file)
@@ -1,5 +1,5 @@
 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
 #include "common/Cond.h"
 #include "include/rados/librados.hpp"
 
@@ -10,9 +10,9 @@ class TestOp;
 
 class TestOpStat {
 public:
-  mutable Mutex stat_lock;
+  mutable ceph::mutex stat_lock = ceph::make_mutex("TestOpStat lock");
 
-  TestOpStat() : stat_lock("TestOpStat lock") {}
+  TestOpStat() = default;
     
   static uint64_t gettime()
   {
index 100eb5cb45a52d2db607ef71f54ea24c21494967..dc6b42c80bad3f29cc1eed5d42485dd7d1a5b955 100644 (file)
@@ -1,6 +1,5 @@
 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 // vim: ts=8 sw=2 smarttab
-#include "common/Mutex.h"
 #include "common/Cond.h"
 #include "common/errno.h"
 #include "common/version.h"