From 34cb0ebe5d2b4eb55e72c7e97949860cc1b8ca17 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 7 Jul 2019 12:43:32 +0800 Subject: [PATCH] test/perf_local: s/Mutex/ceph::mutex/ Signed-off-by: Kefu Chai --- src/test/perf_local.cc | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/test/perf_local.cc b/src/test/perf_local.cc index c2a2c2bcf6c9a..f386a6875b40d 100644 --- a/src/test/perf_local.cc +++ b/src/test/perf_local.cc @@ -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]); -- 2.39.5