Skip to content

Commit

Permalink
journal: s/Mutex/ceph::mutex/
Browse files Browse the repository at this point in the history
* FutureImpl::m_lock is an exception. as, before this change, the lock
  was initialized like `m_lock("FutureImpl::m_lock", false, false)`, see
  the declaration of
  `Mutex(const std::string &n, bool r = false, bool ld=true, bool bt=false)`
  so `m_lock` is actually not using the extra features offered by
  `Mutex` like runtime lockdeps check. and `mutex_debugging_base` does
  not allow us to disable lockdeps individually. but it does use the `is_locked()`
  method. so instead of using `ceph::mutex` directly, a cutomized
  `ceph::mutex` is added for `CEPH_DEBUG_MUTEX` build.

Signed-off-by: Kefu Chai <[email protected]>
  • Loading branch information
tchaikov committed Aug 3, 2019
1 parent 2dbd31e commit f39b32e
Show file tree
Hide file tree
Showing 16 changed files with 224 additions and 229 deletions.
30 changes: 15 additions & 15 deletions src/journal/FutureImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ FutureImpl::FutureImpl(uint64_t tag_tid, uint64_t entry_tid,
uint64_t commit_tid)
: RefCountedObject(NULL, 0), m_tag_tid(tag_tid), m_entry_tid(entry_tid),
m_commit_tid(commit_tid),
m_lock("FutureImpl::m_lock", false, false), m_safe(false),
m_safe(false),
m_consistent(false), m_return_value(0), m_flush_state(FLUSH_STATE_NONE),
m_consistent_ack(this) {
}
Expand All @@ -32,7 +32,7 @@ void FutureImpl::flush(Context *on_safe) {
FlushHandlers flush_handlers;
FutureImplPtr prev_future;
{
Mutex::Locker locker(m_lock);
std::lock_guard locker{m_lock};
complete = (m_safe && m_consistent);
if (!complete) {
if (on_safe != nullptr) {
Expand Down Expand Up @@ -61,13 +61,13 @@ void FutureImpl::flush(Context *on_safe) {
}

FutureImplPtr FutureImpl::prepare_flush(FlushHandlers *flush_handlers) {
Mutex::Locker locker(m_lock);
std::lock_guard locker{m_lock};
return prepare_flush(flush_handlers, m_lock);
}

FutureImplPtr FutureImpl::prepare_flush(FlushHandlers *flush_handlers,
Mutex &lock) {
ceph_assert(m_lock.is_locked());
ceph::mutex &lock) {
ceph_assert(ceph_mutex_is_locked(m_lock));

if (m_flush_state == FLUSH_STATE_NONE) {
m_flush_state = FLUSH_STATE_REQUESTED;
Expand All @@ -82,7 +82,7 @@ FutureImplPtr FutureImpl::prepare_flush(FlushHandlers *flush_handlers,
void FutureImpl::wait(Context *on_safe) {
ceph_assert(on_safe != NULL);
{
Mutex::Locker locker(m_lock);
std::lock_guard locker{m_lock};
if (!m_safe || !m_consistent) {
m_contexts.push_back(on_safe);
return;
Expand All @@ -93,25 +93,25 @@ void FutureImpl::wait(Context *on_safe) {
}

bool FutureImpl::is_complete() const {
Mutex::Locker locker(m_lock);
std::lock_guard locker{m_lock};
return m_safe && m_consistent;
}

int FutureImpl::get_return_value() const {
Mutex::Locker locker(m_lock);
std::lock_guard locker{m_lock};
ceph_assert(m_safe && m_consistent);
return m_return_value;
}

bool FutureImpl::attach(const FlushHandlerPtr &flush_handler) {
Mutex::Locker locker(m_lock);
std::lock_guard locker{m_lock};
ceph_assert(!m_flush_handler);
m_flush_handler = flush_handler;
return m_flush_state != FLUSH_STATE_NONE;
}

void FutureImpl::safe(int r) {
m_lock.Lock();
m_lock.lock();
ceph_assert(!m_safe);
m_safe = true;
if (m_return_value == 0) {
Expand All @@ -122,12 +122,12 @@ void FutureImpl::safe(int r) {
if (m_consistent) {
finish_unlock();
} else {
m_lock.Unlock();
m_lock.unlock();
}
}

void FutureImpl::consistent(int r) {
m_lock.Lock();
m_lock.lock();
ceph_assert(!m_consistent);
m_consistent = true;
m_prev_future.reset();
Expand All @@ -138,18 +138,18 @@ void FutureImpl::consistent(int r) {
if (m_safe) {
finish_unlock();
} else {
m_lock.Unlock();
m_lock.unlock();
}
}

void FutureImpl::finish_unlock() {
ceph_assert(m_lock.is_locked());
ceph_assert(ceph_mutex_is_locked(m_lock));
ceph_assert(m_safe && m_consistent);

Contexts contexts;
contexts.swap(m_contexts);

m_lock.Unlock();
m_lock.unlock();
for (Contexts::iterator it = contexts.begin();
it != contexts.end(); ++it) {
(*it)->complete(m_return_value);
Expand Down
13 changes: 6 additions & 7 deletions src/journal/FutureImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#define CEPH_JOURNAL_FUTURE_IMPL_H

#include "include/int_types.h"
#include "common/Mutex.h"
#include "common/RefCountedObj.h"
#include "include/Context.h"
#include "journal/Future.h"
Expand Down Expand Up @@ -53,23 +52,23 @@ class FutureImpl : public RefCountedObject, boost::noncopyable {
int get_return_value() const;

inline bool is_flush_in_progress() const {
Mutex::Locker locker(m_lock);
std::lock_guard locker{m_lock};
return (m_flush_state == FLUSH_STATE_IN_PROGRESS);
}
inline void set_flush_in_progress() {
Mutex::Locker locker(m_lock);
std::lock_guard locker{m_lock};
ceph_assert(m_flush_handler);
m_flush_handler.reset();
m_flush_state = FLUSH_STATE_IN_PROGRESS;
}

bool attach(const FlushHandlerPtr &flush_handler);
inline void detach() {
Mutex::Locker locker(m_lock);
std::lock_guard locker{m_lock};
m_flush_handler.reset();
}
inline FlushHandlerPtr get_flush_handler() const {
Mutex::Locker locker(m_lock);
std::lock_guard locker{m_lock};
return m_flush_handler;
}

Expand Down Expand Up @@ -101,7 +100,7 @@ class FutureImpl : public RefCountedObject, boost::noncopyable {
uint64_t m_entry_tid;
uint64_t m_commit_tid;

mutable Mutex m_lock;
mutable ceph::mutex m_lock = ceph::make_mutex("FutureImpl::m_lock", false);
FutureImplPtr m_prev_future;
bool m_safe;
bool m_consistent;
Expand All @@ -114,7 +113,7 @@ class FutureImpl : public RefCountedObject, boost::noncopyable {
Contexts m_contexts;

FutureImplPtr prepare_flush(FlushHandlers *flush_handlers);
FutureImplPtr prepare_flush(FlushHandlers *flush_handlers, Mutex &lock);
FutureImplPtr prepare_flush(FlushHandlers *flush_handlers, ceph::mutex &lock);

void consistent(int r);
void finish_unlock();
Expand Down
Loading

0 comments on commit f39b32e

Please sign in to comment.