From 72d8992f054a7e36f92fdd2e01278ce3b9ede2eb Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Wed, 21 Sep 2016 13:02:34 -0400 Subject: [PATCH] common: move AsyncOpTracker to common library Signed-off-by: Jason Dillaman --- src/CMakeLists.txt | 1 + src/{journal => common}/AsyncOpTracker.cc | 21 +++++---------------- src/{journal => common}/AsyncOpTracker.h | 15 ++++----------- src/journal/CMakeLists.txt | 1 - src/journal/JournalMetadata.h | 2 +- src/journal/JournalPlayer.h | 2 +- src/journal/JournalTrimmer.h | 2 +- 7 files changed, 13 insertions(+), 31 deletions(-) rename src/{journal => common}/AsyncOpTracker.cc (73%) rename src/{journal => common}/AsyncOpTracker.h (61%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9c5166a07a3..0d6586c8843 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -318,6 +318,7 @@ add_library(common_texttable_obj OBJECT set(libcommon_files ${CMAKE_BINARY_DIR}/src/include/ceph_ver.h ceph_ver.c + common/AsyncOpTracker.cc common/DecayCounter.cc common/LogClient.cc common/LogEntry.cc diff --git a/src/journal/AsyncOpTracker.cc b/src/common/AsyncOpTracker.cc similarity index 73% rename from src/journal/AsyncOpTracker.cc rename to src/common/AsyncOpTracker.cc index 13a55fa7a47..2219a7fd7f6 100644 --- a/src/journal/AsyncOpTracker.cc +++ b/src/common/AsyncOpTracker.cc @@ -1,19 +1,17 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab -#include "journal/AsyncOpTracker.h" -#include "journal/Utils.h" +#include "common/AsyncOpTracker.h" #include "include/assert.h" - -namespace journal { +#include "include/Context.h" AsyncOpTracker::AsyncOpTracker() - : m_lock(utils::unique_lock_name("AsyncOpTracker::m_lock", this)), - m_pending_ops(0) { + : m_lock("AsyncOpTracker::m_lock", false, false) { } AsyncOpTracker::~AsyncOpTracker() { - wait_for_ops(); + Mutex::Locker locker(m_lock); + assert(m_pending_ops == 0); } void AsyncOpTracker::start_op() { @@ -27,7 +25,6 @@ void AsyncOpTracker::finish_op() { Mutex::Locker locker(m_lock); assert(m_pending_ops > 0); if (--m_pending_ops == 0) { - m_cond.Signal(); std::swap(on_finish, m_on_finish); } } @@ -37,13 +34,6 @@ void AsyncOpTracker::finish_op() { } } -void AsyncOpTracker::wait_for_ops() { - Mutex::Locker locker(m_lock); - while (m_pending_ops > 0) { - m_cond.Wait(m_lock); - } -} - void AsyncOpTracker::wait_for_ops(Context *on_finish) { { Mutex::Locker locker(m_lock); @@ -61,4 +51,3 @@ bool AsyncOpTracker::empty() { return (m_pending_ops == 0); } -} // namespace journal diff --git a/src/journal/AsyncOpTracker.h b/src/common/AsyncOpTracker.h similarity index 61% rename from src/journal/AsyncOpTracker.h rename to src/common/AsyncOpTracker.h index a88cd453fe9..fccc9f91d6b 100644 --- a/src/journal/AsyncOpTracker.h +++ b/src/common/AsyncOpTracker.h @@ -1,17 +1,14 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab -#ifndef CEPH_JOURNAL_ASYNC_OP_TRACKER_H -#define CEPH_JOURNAL_ASYNC_OP_TRACKER_H +#ifndef CEPH_ASYNC_OP_TRACKER_H +#define CEPH_ASYNC_OP_TRACKER_H #include "include/int_types.h" -#include "common/Cond.h" #include "common/Mutex.h" struct Context; -namespace journal { - class AsyncOpTracker { public: AsyncOpTracker(); @@ -20,19 +17,15 @@ public: void start_op(); void finish_op(); - void wait_for_ops(); void wait_for_ops(Context *on_finish); bool empty(); private: Mutex m_lock; - Cond m_cond; - uint32_t m_pending_ops; + uint32_t m_pending_ops = 0; Context *m_on_finish = nullptr; }; -} // namespace journal - -#endif // CEPH_JOURNAL_ASYNC_OP_TRACKER_H +#endif // CEPH_ASYNC_OP_TRACKER_H diff --git a/src/journal/CMakeLists.txt b/src/journal/CMakeLists.txt index 50b8c307cb2..3632c1051ec 100644 --- a/src/journal/CMakeLists.txt +++ b/src/journal/CMakeLists.txt @@ -1,5 +1,4 @@ set(journal_srcs - AsyncOpTracker.cc Entry.cc Future.cc FutureImpl.cc diff --git a/src/journal/JournalMetadata.h b/src/journal/JournalMetadata.h index 880130126dd..969472f61f1 100644 --- a/src/journal/JournalMetadata.h +++ b/src/journal/JournalMetadata.h @@ -7,12 +7,12 @@ #include "include/int_types.h" #include "include/Context.h" #include "include/rados/librados.hpp" +#include "common/AsyncOpTracker.h" #include "common/Cond.h" #include "common/Mutex.h" #include "common/RefCountedObj.h" #include "common/WorkQueue.h" #include "cls/journal/cls_journal_types.h" -#include "journal/AsyncOpTracker.h" #include "journal/JournalMetadataListener.h" #include "journal/Settings.h" #include diff --git a/src/journal/JournalPlayer.h b/src/journal/JournalPlayer.h index 690eccdd471..ff5732bd8aa 100644 --- a/src/journal/JournalPlayer.h +++ b/src/journal/JournalPlayer.h @@ -7,8 +7,8 @@ #include "include/int_types.h" #include "include/Context.h" #include "include/rados/librados.hpp" +#include "common/AsyncOpTracker.h" #include "common/Mutex.h" -#include "journal/AsyncOpTracker.h" #include "journal/JournalMetadata.h" #include "journal/ObjectPlayer.h" #include "cls/journal/cls_journal_types.h" diff --git a/src/journal/JournalTrimmer.h b/src/journal/JournalTrimmer.h index 55379be7bbd..73641db38cc 100644 --- a/src/journal/JournalTrimmer.h +++ b/src/journal/JournalTrimmer.h @@ -7,8 +7,8 @@ #include "include/int_types.h" #include "include/rados/librados.hpp" #include "include/Context.h" +#include "common/AsyncOpTracker.h" #include "common/Mutex.h" -#include "journal/AsyncOpTracker.h" #include "journal/JournalMetadata.h" #include "cls/journal/cls_journal_types.h" #include -- 2.39.5