summaryrefslogtreecommitdiffstats
path: root/src/test/perf_local.cc
diff options
context:
space:
mode:
authorKefu Chai <kchai@redhat.com>2019-07-07 06:43:32 +0200
committerKefu Chai <kchai@redhat.com>2019-08-03 05:27:20 +0200
commit34cb0ebe5d2b4eb55e72c7e97949860cc1b8ca17 (patch)
tree0779763744df483cbf1736ebad60e9d5099caf3c /src/test/perf_local.cc
parenttest/osdc: s/Mutex/ceph::mutex/ (diff)
downloadceph-34cb0ebe5d2b4eb55e72c7e97949860cc1b8ca17.tar.xz
ceph-34cb0ebe5d2b4eb55e72c7e97949860cc1b8ca17.zip
test/perf_local: s/Mutex/ceph::mutex/
Signed-off-by: Kefu Chai <kchai@redhat.com>
Diffstat (limited to 'src/test/perf_local.cc')
-rw-r--r--src/test/perf_local.cc38
1 files changed, 18 insertions, 20 deletions
diff --git a/src/test/perf_local.cc b/src/test/perf_local.cc
index c2a2c2bcf6c..f386a6875b4 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]);