#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"
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;
// 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;
} consumer;
public:
- CondPingPong(): mutex("CondPingPong::mutex"), prod(0), cons(0), count(10000), consumer(this) {}
+ CondPingPong(): consumer(this) {}
double run() {
consumer.create("consumer");
}
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();
}
}
};
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]);