From 6e6faf080a0031825834672f348dec5ab56da5a0 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 7 Jul 2019 11:18:41 +0800 Subject: [PATCH] cls/rgw: s/Mutex/ceph::mutex/ Signed-off-by: Kefu Chai --- src/cls/rgw/cls_rgw_client.cc | 10 ++++------ src/cls/rgw/cls_rgw_client.h | 16 +++++++--------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/cls/rgw/cls_rgw_client.cc b/src/cls/rgw/cls_rgw_client.cc index 97426ed7661..cb6256d246d 100644 --- a/src/cls/rgw/cls_rgw_client.cc +++ b/src/cls/rgw/cls_rgw_client.cc @@ -40,7 +40,7 @@ public: }; void BucketIndexAioManager::do_completion(int id) { - Mutex::Locker l(lock); + std::lock_guard l{lock}; map::iterator iter = pendings.find(id); ceph_assert(iter != pendings.end()); @@ -55,20 +55,19 @@ void BucketIndexAioManager::do_completion(int id) { pending_objs.erase(miter); } - cond.Signal(); + cond.notify_all(); } bool BucketIndexAioManager::wait_for_completions(int valid_ret_code, int *num_completions, int *ret_code, map *objs) { - lock.Lock(); + std::unique_lock locker{lock}; if (pendings.empty() && completions.empty()) { - lock.Unlock(); return false; } if (completions.empty()) { // Wait for AIO completion - cond.Wait(lock); + cond.wait(locker); } // Clear the completed AIOs @@ -88,7 +87,6 @@ bool BucketIndexAioManager::wait_for_completions(int valid_ret_code, if (num_completions) (*num_completions) = completions.size(); completions.clear(); - lock.Unlock(); return true; } diff --git a/src/cls/rgw/cls_rgw_client.h b/src/cls/rgw/cls_rgw_client.h index b090fbd7478..8def8826e54 100644 --- a/src/cls/rgw/cls_rgw_client.h +++ b/src/cls/rgw/cls_rgw_client.h @@ -11,8 +11,7 @@ #include "common/RefCountedObj.h" #include "include/compat.h" #include "common/ceph_time.h" -#include "common/Mutex.h" -#include "common/Cond.h" +#include "common/ceph_mutex.h" // Forward declaration class BucketIndexAioManager; @@ -38,9 +37,9 @@ private: map completions; map pending_objs; map completion_objs; - int next; - Mutex lock; - Cond cond; + int next = 0; + ceph::mutex lock = ceph::make_mutex("BucketIndexAioManager::lock"); + ceph::condition_variable cond; /* * Callback implementation for AIO request. */ @@ -73,8 +72,7 @@ public: /* * Create a new instance. */ - BucketIndexAioManager() : next(0), lock("BucketIndexAioManager::lock") {} - + BucketIndexAioManager() = default; /* * Do completion for the given AIO request. @@ -98,7 +96,7 @@ public: * Do aio read operation. */ bool aio_operate(librados::IoCtx& io_ctx, const string& oid, librados::ObjectReadOperation *op) { - Mutex::Locker l(lock); + std::lock_guard l{lock}; BucketIndexAioArg *arg = new BucketIndexAioArg(get_next(), this); librados::AioCompletion *c = librados::Rados::aio_create_completion((void*)arg, NULL, bucket_index_op_completion_cb); int r = io_ctx.aio_operate(oid, c, (librados::ObjectReadOperation*)op, NULL); @@ -114,7 +112,7 @@ public: * Do aio write operation. */ bool aio_operate(librados::IoCtx& io_ctx, const string& oid, librados::ObjectWriteOperation *op) { - Mutex::Locker l(lock); + std::lock_guard l{lock}; BucketIndexAioArg *arg = new BucketIndexAioArg(get_next(), this); librados::AioCompletion *c = librados::Rados::aio_create_completion((void*)arg, NULL, bucket_index_op_completion_cb); int r = io_ctx.aio_operate(oid, c, (librados::ObjectWriteOperation*)op); -- 2.39.5