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

index a0ddbef055c383e46273a56386d21a3a65d8e2ff..fea897fedab616f290f35b9b8845570bd2f74f4f 100644 (file)
@@ -14,7 +14,7 @@
 #include "include/rados/librados.hpp"
 #include "include/Context.h"
 #include "common/ceph_context.h"
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
 #include "common/Cond.h"
 #include "include/utime.h"
 #include "global/global_context.h"
@@ -127,9 +127,9 @@ int OmapBench::setup(int argc, const char** argv) {
 //Writer functions
 Writer::Writer(OmapBench *omap_bench) : ob(omap_bench) {
   stringstream name;
-  ob->data_lock.Lock();
+  ob->data_lock.lock();
   name << omap_bench->prefix << ++(ob->data.started_ops);
-  ob->data_lock.Unlock();
+  ob->data_lock.unlock();
   oid = name.str();
 }
 void Writer::start_time() {
@@ -168,9 +168,9 @@ void AioWriter::set_aioc(librados::callback_t complete,
 void OmapBench::aio_is_safe(rados_completion_t c, void *arg) {
   AioWriter *aiow = reinterpret_cast<AioWriter *>(arg);
   aiow->stop_time();
-  Mutex * data_lock = &aiow->ob->data_lock;
-  Mutex * thread_is_free_lock = &aiow->ob->thread_is_free_lock;
-  Cond * thread_is_free = &aiow->ob->thread_is_free;
+  ceph::mutex * data_lock = &aiow->ob->data_lock;
+  ceph::mutex * thread_is_free_lock = &aiow->ob->thread_is_free_lock;
+  ceph::condition_variable* thread_is_free = &aiow->ob->thread_is_free;
   int &busythreads_count = aiow->ob->busythreads_count;
   o_bench_data &data = aiow->ob->data;
   int INCREMENT = aiow->ob->increment;
@@ -181,7 +181,7 @@ void OmapBench::aio_is_safe(rados_completion_t c, void *arg) {
   }
   double time = aiow->get_time();
   delete aiow;
-  data_lock->Lock();
+  data_lock->lock();
   data.avg_latency = (data.avg_latency * data.completed_ops + time)
       / (data.completed_ops + 1);
   data.completed_ops++;
@@ -197,12 +197,12 @@ void OmapBench::aio_is_safe(rados_completion_t c, void *arg) {
     data.mode.first = time/INCREMENT;
     data.mode.second = data.freq_map[time/INCREMENT];
   }
-  data_lock->Unlock();
+  data_lock->unlock();
 
-  thread_is_free_lock->Lock();
+  thread_is_free_lock->lock();
   busythreads_count--;
-  thread_is_free->Signal();
-  thread_is_free_lock->Unlock();
+  thread_is_free->notify_all();
+  thread_is_free_lock->unlock();
 }
 
 string OmapBench::random_string(int len) {
@@ -369,16 +369,13 @@ int OmapBench::test_write_objects_in_parallel(omap_generator_t omap_gen) {
   comp = NULL;
   AioWriter *this_aio_writer;
 
-  Mutex::Locker l(thread_is_free_lock);
+  std::unique_lock l{thread_is_free_lock};
   for (int i = 0; i < objects; i++) {
     ceph_assert(busythreads_count <= threads);
     //wait for a writer to be free
     if (busythreads_count == threads) {
-      int err = thread_is_free.Wait(thread_is_free_lock);
+      thread_is_free.wait(l);
       ceph_assert(busythreads_count < threads);
-      if (err < 0) {
-       return err;
-      }
     }
 
     //set up the write
@@ -400,10 +397,7 @@ int OmapBench::test_write_objects_in_parallel(omap_generator_t omap_gen) {
       return err;
     }
   }
-  while(busythreads_count > 0) {
-    thread_is_free.Wait(thread_is_free_lock);
-  }
-
+  thread_is_free.wait(l, [this] { return busythreads_count <= 0;});
   return 0;
 }
 
index 45637489c9ac6f32ff0d7d88cc22d203ae7ce599..34ee7123b4a54f40667d82852edc3d16b0293645 100644 (file)
@@ -14,7 +14,7 @@
 #ifndef OMAP_BENCH_HPP_
 #define OMAP_BENCH_HPP_
 
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
 #include "common/Cond.h"
 #include "include/rados/librados.hpp"
 #include <string>
@@ -87,9 +87,11 @@ protected:
   omap_generator_t omap_generator;
 
   //aio things
-  Cond thread_is_free;
-  Mutex thread_is_free_lock;
-  Mutex  data_lock;
+  ceph::condition_variable thread_is_free;
+  ceph::mutex thread_is_free_lock =
+    ceph::make_mutex("OmapBench::thread_is_free_lock");
+  ceph::mutex data_lock =
+    ceph::make_mutex("OmapBench::data_lock");
   int busythreads_count;
   librados::callback_t comp;
   librados::callback_t safe;
@@ -111,8 +113,6 @@ public:
   OmapBench()
     : test(&OmapBench::test_write_objects_in_parallel),
       omap_generator(generate_uniform_omap),
-      thread_is_free_lock("OmapBench::thread_is_free_lock"),
-      data_lock("OmapBench::data_lock"),
       busythreads_count(0),
       comp(NULL), safe(aio_is_safe),
       pool_name("rbd"),