]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
test/perf_local: s/Mutex/ceph::mutex/
authorKefu Chai <kchai@redhat.com>
Sun, 7 Jul 2019 04:43:32 +0000 (12:43 +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/perf_local.cc

index c2a2c2bcf6c9ad2a2b18379750eb8b80099f8df9..f386a6875b40d4628b98e6a6fdc3ce454514ac6a 100644 (file)
@@ -48,7 +48,7 @@
 #include "common/ceph_argparse.h"
 #include "common/Cycles.h"
 #include "common/Cond.h"
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
 #include "common/Thread.h"
 #include "common/Timer.h"
 #include "msg/async/Event.h"
@@ -159,11 +159,11 @@ double atomic_int_set()
 double mutex_nonblock()
 {
   int count = 1000000;
-  Mutex m("mutex_nonblock::m");
+  ceph::mutex m = ceph::make_mutex("mutex_nonblock::m");
   uint64_t start = Cycles::rdtsc();
   for (int i = 0; i < count; i++) {
-    m.Lock();
-    m.Unlock();
+    m.lock();
+    m.unlock();
   }
   uint64_t stop = Cycles::rdtsc();
   return Cycles::to_seconds(stop - start)/count;
@@ -305,11 +305,11 @@ double buffer_iterator()
 
 // Implements the CondPingPong test.
 class CondPingPong {
-  Mutex mutex;
-  Cond cond;
-  int prod;
-  int cons;
-  const int count;
+  ceph::mutex mutex = ceph::make_mutex("CondPingPong::mutex");
+  ceph::condition_variable cond;
+  int prod = 0;
+  int cons = 0;
+  const int count = 10000;
 
   class Consumer : public Thread {
     CondPingPong *p;
@@ -322,7 +322,7 @@ class CondPingPong {
   } consumer;
 
  public:
-  CondPingPong(): mutex("CondPingPong::mutex"), prod(0), cons(0), count(10000), consumer(this) {}
+  CondPingPong(): consumer(this) {}
 
   double run() {
     consumer.create("consumer");
@@ -334,22 +334,20 @@ class CondPingPong {
   }
 
   void produce() {
-    Mutex::Locker l(mutex);
+    std::unique_lock l{mutex};
     while (cons < count) {
-      while (cons < prod)
-        cond.Wait(mutex);
+      cond.wait(l, [this] { return cons >= prod; });
       ++prod;
-      cond.Signal();
+      cond.notify_all();
     }
   }
 
   void consume() {
-    Mutex::Locker l(mutex);
+    std::unique_lock l{mutex};
     while (cons < count) {
-      while (cons == prod)
-        cond.Wait(mutex);
+      cond.wait(l, [this] { return cons != prod; });
       ++cons;
-      cond.Signal();
+      cond.notify_all();
     }
   }
 };
@@ -759,14 +757,14 @@ class FakeContext : public Context {
 double perf_timer()
 {
   int count = 1000000;
-  Mutex lock("perf_timer::lock");
+  ceph::mutex lock = ceph::make_mutex("perf_timer::lock");
   SafeTimer timer(g_ceph_context, lock);
   FakeContext **c = new FakeContext*[count];
   for (int i = 0; i < count; i++) {
     c[i] = new FakeContext();
   }
   uint64_t start = Cycles::rdtsc();
-  Mutex::Locker l(lock);
+  std::lock_guard l{lock};
   for (int i = 0; i < count; i++) {
     if (timer.add_event_after(12345, c[i])) {
       timer.cancel_event(c[i]);