diff options
author | Kefu Chai <kchai@redhat.com> | 2019-07-07 05:14:32 +0200 |
---|---|---|
committer | Kefu Chai <kchai@redhat.com> | 2019-08-03 03:34:50 +0200 |
commit | ed75406c4f04a0aad3a99e57bd50e5bb3352b4ad (patch) | |
tree | d964f42b385c3e2758b570985ce5174a5b8e1996 /src/libradosstriper | |
parent | include/utime: add utime_t<>(duration) (diff) | |
download | ceph-ed75406c4f04a0aad3a99e57bd50e5bb3352b4ad.tar.xz ceph-ed75406c4f04a0aad3a99e57bd50e5bb3352b4ad.zip |
librados: s/Mutex/ceph::mutex/
Signed-off-by: Kefu Chai <kchai@redhat.com>
Diffstat (limited to 'src/libradosstriper')
-rw-r--r-- | src/libradosstriper/MultiAioCompletionImpl.cc | 7 | ||||
-rw-r--r-- | src/libradosstriper/MultiAioCompletionImpl.h | 97 | ||||
-rw-r--r-- | src/libradosstriper/RadosStriperImpl.cc | 8 | ||||
-rw-r--r-- | src/libradosstriper/RadosStriperImpl.h | 13 |
4 files changed, 49 insertions, 76 deletions
diff --git a/src/libradosstriper/MultiAioCompletionImpl.cc b/src/libradosstriper/MultiAioCompletionImpl.cc index f13d2c9525b..901bb136664 100644 --- a/src/libradosstriper/MultiAioCompletionImpl.cc +++ b/src/libradosstriper/MultiAioCompletionImpl.cc @@ -18,7 +18,7 @@ void libradosstriper::MultiAioCompletionImpl::complete_request(ssize_t r) { - lock.Lock(); + lock.lock(); if (rval >= 0) { if (r < 0 && r != -EEXIST) rval = r; @@ -35,7 +35,7 @@ void libradosstriper::MultiAioCompletionImpl::complete_request(ssize_t r) void libradosstriper::MultiAioCompletionImpl::safe_request(ssize_t r) { - lock.Lock(); + lock.lock(); if (rval >= 0) { if (r < 0 && r != -EEXIST) rval = r; @@ -50,14 +50,13 @@ void libradosstriper::MultiAioCompletionImpl::safe_request(ssize_t r) void libradosstriper::MultiAioCompletionImpl::finish_adding_requests() { - lock.Lock(); + std::scoped_lock l{lock}; ceph_assert(building); building = false; if (!pending_complete) complete(); if (!pending_safe) safe(); - lock.Unlock(); } void intrusive_ptr_add_ref(libradosstriper::MultiAioCompletionImpl* ptr) diff --git a/src/libradosstriper/MultiAioCompletionImpl.h b/src/libradosstriper/MultiAioCompletionImpl.h index 24188ab6e7d..32f7b9a84cf 100644 --- a/src/libradosstriper/MultiAioCompletionImpl.h +++ b/src/libradosstriper/MultiAioCompletionImpl.h @@ -15,15 +15,15 @@ #ifndef CEPH_LIBRADOSSTRIPERSTRIPER_MULTIAIOCOMPLETIONIMPL_H #define CEPH_LIBRADOSSTRIPERSTRIPER_MULTIAIOCOMPLETIONIMPL_H -#include "common/Cond.h" -#include "common/Mutex.h" - +#include <list> +#include <mutex> +#include "common/ceph_mutex.h" #include "include/radosstriper/libradosstriper.hpp" struct libradosstriper::MultiAioCompletionImpl { - Mutex lock; - Cond cond; + ceph::mutex lock = ceph::make_mutex("MultiAioCompletionImpl lock", false); + ceph::condition_variable cond; int ref, rval; int pending_complete, pending_safe; rados_callback_t callback_complete, callback_safe; @@ -32,8 +32,8 @@ struct libradosstriper::MultiAioCompletionImpl { bufferlist bl; /// only used for read case in C api of rados striper std::list<bufferlist*> bllist; /// keep temporary buffer lists used for destriping - MultiAioCompletionImpl() : lock("MultiAioCompletionImpl lock", false, false), - ref(1), rval(0), + MultiAioCompletionImpl() + : ref(1), rval(0), pending_complete(0), pending_safe(0), callback_complete(0), callback_safe(0), callback_complete_arg(0), callback_safe_arg(0), @@ -50,125 +50,102 @@ struct libradosstriper::MultiAioCompletionImpl { } int set_complete_callback(void *cb_arg, rados_callback_t cb) { - lock.Lock(); + std::scoped_lock l{lock}; callback_complete = cb; callback_complete_arg = cb_arg; - lock.Unlock(); return 0; } int set_safe_callback(void *cb_arg, rados_callback_t cb) { - lock.Lock(); + std::scoped_lock l{lock}; callback_safe = cb; callback_safe_arg = cb_arg; - lock.Unlock(); return 0; } int wait_for_complete() { - lock.Lock(); - while (pending_complete) - cond.Wait(lock); - lock.Unlock(); + std::unique_lock l{lock}; + cond.wait(l, [this] { return !pending_complete; }); return 0; } int wait_for_safe() { - lock.Lock(); - while (pending_safe) - cond.Wait(lock); - lock.Unlock(); + std::unique_lock l{lock}; + cond.wait(l, [this] { return !pending_safe; }); return 0; } bool is_complete() { - lock.Lock(); - int r = pending_complete; - lock.Unlock(); - return 0 == r; + std::scoped_lock l{lock}; + return pending_complete == 0; } bool is_safe() { - lock.Lock(); - int r = pending_safe; - lock.Unlock(); - return r == 0; + std::scoped_lock l{lock}; + return pending_safe == 0; } void wait_for_complete_and_cb() { - lock.Lock(); - while (pending_complete || callback_complete) - cond.Wait(lock); - lock.Unlock(); + std::unique_lock l{lock}; + cond.wait(l, [this] { return !pending_complete && !callback_complete; }); } void wait_for_safe_and_cb() { - lock.Lock(); - while (pending_safe || callback_safe) - cond.Wait(lock); - lock.Unlock(); + std::unique_lock l{lock}; + cond.wait(l, [this] { return !pending_safe && !callback_safe; }); } bool is_complete_and_cb() { - lock.Lock(); - bool r = ((0 == pending_complete) && !callback_complete); - lock.Unlock(); - return r; + std::scoped_lock l{lock}; + return ((0 == pending_complete) && !callback_complete); } bool is_safe_and_cb() { - lock.Lock(); - int r = ((0 == pending_safe) && !callback_safe); - lock.Unlock(); - return r; + std::scoped_lock l{lock}; + return ((0 == pending_safe) && !callback_safe); } int get_return_value() { - lock.Lock(); - int r = rval; - lock.Unlock(); - return r; + std::scoped_lock l{lock}; + return rval; } void get() { - lock.Lock(); + std::scoped_lock l{lock}; _get(); - lock.Unlock(); } void _get() { - ceph_assert(lock.is_locked()); + ceph_assert(ceph_mutex_is_locked(lock)); ceph_assert(ref > 0); ++ref; } void put() { - lock.Lock(); + lock.lock(); put_unlock(); } void put_unlock() { ceph_assert(ref > 0); int n = --ref; - lock.Unlock(); + lock.unlock(); if (!n) delete this; } void add_request() { - lock.Lock(); + std::scoped_lock l{lock}; pending_complete++; _get(); pending_safe++; _get(); - lock.Unlock(); } void add_safe_request() { - lock.Lock(); + std::scoped_lock l{lock}; pending_complete++; _get(); - lock.Unlock(); } void complete() { - ceph_assert(lock.is_locked()); + ceph_assert(ceph_mutex_is_locked(lock)); if (callback_complete) { callback_complete(this, callback_complete_arg); callback_complete = 0; } - cond.Signal(); + cond.notify_all(); } void safe() { - ceph_assert(lock.is_locked()); + ceph_assert(ceph_mutex_is_locked(lock)); if (callback_safe) { callback_safe(this, callback_safe_arg); callback_safe = 0; } - cond.Signal(); + cond.notify_all(); }; void complete_request(ssize_t r); diff --git a/src/libradosstriper/RadosStriperImpl.cc b/src/libradosstriper/RadosStriperImpl.cc index 1a3eb99f860..d2af7875848 100644 --- a/src/libradosstriper/RadosStriperImpl.cc +++ b/src/libradosstriper/RadosStriperImpl.cc @@ -438,7 +438,7 @@ struct RadosRemoveCompletionData : RefCountedObject { ///////////////////////// constructor ///////////////////////////// libradosstriper::RadosStriperImpl::RadosStriperImpl(librados::IoCtx& ioctx, librados::IoCtxImpl *ioctx_impl) : - m_refCnt(0),lock("RadosStriper Refcont", false, false), m_radosCluster(ioctx), m_ioCtx(ioctx), m_ioCtxImpl(ioctx_impl), + m_refCnt(0), m_radosCluster(ioctx), m_ioCtx(ioctx), m_ioCtxImpl(ioctx_impl), m_layout(default_file_layout) {} ///////////////////////// layout ///////////////////////////// @@ -771,10 +771,8 @@ int libradosstriper::RadosStriperImpl::aio_flush() if (ret < 0) return ret; //wait all CompletionData are released - lock.Lock(); - while (m_refCnt > 1) - cond.Wait(lock); - lock.Unlock(); + std::unique_lock l{lock}; + cond.wait(l, [this] {return m_refCnt <= 1;}); return ret; } diff --git a/src/libradosstriper/RadosStriperImpl.h b/src/libradosstriper/RadosStriperImpl.h index 6622471ed48..160db7b6f8d 100644 --- a/src/libradosstriper/RadosStriperImpl.h +++ b/src/libradosstriper/RadosStriperImpl.h @@ -111,18 +111,17 @@ struct RadosStriperImpl { // reference counting void get() { - lock.Lock(); + std::lock_guard l{lock}; m_refCnt ++ ; - lock.Unlock(); } void put() { bool deleteme = false; - lock.Lock(); + lock.lock(); m_refCnt --; if (m_refCnt == 0) deleteme = true; - cond.Signal(); - lock.Unlock(); + cond.notify_all(); + lock.unlock(); if (deleteme) delete this; } @@ -257,9 +256,9 @@ struct RadosStriperImpl { } // reference counting - Cond cond; + std::condition_variable cond; int m_refCnt; - Mutex lock; + std::mutex lock; // Context |