]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
test/test_snap_mapper: s/Mutex/ceph::mutex/
authorKefu Chai <kchai@redhat.com>
Wed, 17 Jul 2019 08:29:36 +0000 (16:29 +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/test_snap_mapper.cc

index f7224cbdb116336f3cba7b4754c0a9a7daaa3e41..9b6dbdd2b0c59db43f956656624755cb25aced15 100644 (file)
@@ -89,36 +89,37 @@ public:
   };
 private:
 
-  Mutex lock;
+  ceph::mutex lock = ceph::make_mutex("PausyAsyncMap");
   map<string, bufferlist> store;
 
   class Doer : public Thread {
     static const size_t MAX_SIZE = 100;
     PausyAsyncMap *parent;
-    Mutex lock;
-    Cond cond;
+    ceph::mutex lock = ceph::make_mutex("Doer lock");
+    ceph::condition_variable cond;
     int stopping;
     bool paused;
     list<Op> queue;
   public:
     explicit Doer(PausyAsyncMap *parent) :
-      parent(parent), lock("Doer lock"), stopping(0), paused(false) {}
+      parent(parent), stopping(0), paused(false) {}
     void *entry() override {
       while (1) {
        list<Op> ops;
        {
-         Mutex::Locker l(lock);
-         while (!stopping && (queue.empty() || paused))
-           cond.Wait(lock);
+         std::unique_lock l{lock};
+         cond.wait(l, [this] {
+            return stopping || (!queue.empty() && !paused);
+         });
          if (stopping && queue.empty()) {
            stopping = 2;
-           cond.Signal();
+           cond.notify_all();
            return 0;
          }
          ceph_assert(!queue.empty());
          ceph_assert(!paused);
          ops.swap(queue);
-         cond.Signal();
+         cond.notify_all();
        }
        ceph_assert(!ops.empty());
 
@@ -127,44 +128,42 @@ private:
             ops.erase(i++)) {
          if (!(rand()%3))
            usleep(1+(rand() % 5000));
-         Mutex::Locker l(parent->lock);
+         std::lock_guard l{parent->lock};
          (*i)->operate(&(parent->store));
        }
       }
     }
 
     void pause() {
-      Mutex::Locker l(lock);
+      std::lock_guard l{lock};
       paused = true;
-      cond.Signal();
+      cond.notify_all();
     }
 
     void resume() {
-      Mutex::Locker l(lock);
+      std::lock_guard l{lock};
       paused = false;
-      cond.Signal();
+      cond.notify_all();
     }
 
     void submit(list<Op> &in) {
-      Mutex::Locker l(lock);
-      while (queue.size() >= MAX_SIZE)
-       cond.Wait(lock);
+      std::unique_lock l{lock};
+      cond.wait(l, [this] { return queue.size() < MAX_SIZE;});
       queue.splice(queue.end(), in, in.begin(), in.end());
-      cond.Signal();
+      cond.notify_all();
     }
 
     void stop() {
-      Mutex::Locker l(lock);
+      std::unique_lock l{lock};
       stopping = 1;
-      cond.Signal();
-      while (stopping != 2)
-       cond.Wait(lock);
-      cond.Signal();
+      cond.notify_all();
+      cond.wait(l, [this] { return stopping == 2; });
+      cond.notify_all();
     }
   } doer;
 
 public:
-  PausyAsyncMap() : lock("PausyAsyncMap"), doer(this) {
+  PausyAsyncMap() : doer(this) {
     doer.create("doer");
   }
   ~PausyAsyncMap() override {
@@ -173,7 +172,7 @@ public:
   int get_keys(
     const set<string> &keys,
     map<string, bufferlist> *out) override {
-    Mutex::Locker l(lock);
+    std::lock_guard l{lock};
     for (set<string>::const_iterator i = keys.begin();
         i != keys.end();
         ++i) {
@@ -186,7 +185,7 @@ public:
   int get_next(
     const string &key,
     pair<string, bufferlist> *next) override {
-    Mutex::Locker l(lock);
+    std::lock_guard l{lock};
     map<string, bufferlist>::iterator j = store.upper_bound(key);
     if (j != store.end()) {
       if (next)
@@ -202,30 +201,29 @@ public:
   }
 
   void flush() {
-    Mutex lock("flush lock");
-    Cond cond;
+    ceph::mutex lock = ceph::make_mutex("flush lock");
+    ceph::condition_variable cond;
     bool done = false;
 
     class OnFinish : public Context {
-      Mutex *lock;
-      Cond *cond;
+      ceph::mutex *lock;
+      ceph::condition_variable *cond;
       bool *done;
     public:
-      OnFinish(Mutex *lock, Cond *cond, bool *done)
+      OnFinish(ceph::mutex *lock, ceph::condition_variable *cond, bool *done)
        : lock(lock), cond(cond), done(done) {}
       void finish(int) override {
-       Mutex::Locker l(*lock);
+       std::lock_guard l{*lock};
        *done = true;
-       cond->Signal();
+       cond->notify_all();
       }
     };
     Transaction t;
     t.add_callback(new OnFinish(&lock, &cond, &done));
     submit(&t);
     {
-      Mutex::Locker l(lock);
-      while (!done)
-       cond.Wait(lock);
+      std::unique_lock l{lock};
+      cond.wait(l, [&] { return done; });
     }
   }
 
@@ -443,7 +441,7 @@ class MapperVerifier {
   snapid_t next;
   uint32_t mask;
   uint32_t bits;
-  Mutex lock;
+  ceph::mutex lock = ceph::make_mutex("lock");
 public:
 
   MapperVerifier(
@@ -452,8 +450,7 @@ public:
     uint32_t bits)
     : driver(driver),
       mapper(new SnapMapper(g_ceph_context, driver, mask, bits, 0, shard_id_t(1))),
-             mask(mask), bits(bits),
-      lock("lock") {}
+             mask(mask), bits(bits) {}
 
   hobject_t random_hobject() {
     return hobject_t(
@@ -478,7 +475,7 @@ public:
   }
 
   void create_object() {
-    Mutex::Locker l(lock);
+    std::lock_guard l{lock};
     if (snap_to_hobject.empty())
       return;
     hobject_t obj;
@@ -503,7 +500,7 @@ public:
   }
 
   void trim_snap() {
-    Mutex::Locker l(lock);
+    std::lock_guard l{lock};
     if (snap_to_hobject.empty())
       return;
     map<snapid_t, set<hobject_t> >::iterator snap =
@@ -545,7 +542,7 @@ public:
   }
 
   void remove_oid() {
-    Mutex::Locker l(lock);
+    std::lock_guard l{lock};
     if (hobject_to_snap.empty())
       return;
     map<hobject_t, set<snapid_t>>::iterator obj =
@@ -569,7 +566,7 @@ public:
   }
 
   void check_oid() {
-    Mutex::Locker l(lock);
+    std::lock_guard l{lock};
     if (hobject_to_snap.empty())
       return;
     map<hobject_t, set<snapid_t>>::iterator obj =