From: Jason Dillaman Date: Wed, 21 Sep 2016 17:02:34 +0000 (-0400) Subject: common: move AsyncOpTracker to common library X-Git-Tag: v10.2.4~61^2~11 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2460a3dbe7d04f1a4daa44d7367d24d47fa070fb;p=ceph.git common: move AsyncOpTracker to common library Signed-off-by: Jason Dillaman (cherry picked from commit 72d8992f054a7e36f92fdd2e01278ce3b9ede2eb) Conflicts: src/journal/CMakeLists.txt: doesn't exist in Jewel --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 103e68a14c60..1bfc031c9d90 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -212,6 +212,7 @@ endif(HAVE_GOOD_YASM_ELF64) 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/common/AsyncOpTracker.cc b/src/common/AsyncOpTracker.cc new file mode 100644 index 000000000000..2219a7fd7f61 --- /dev/null +++ b/src/common/AsyncOpTracker.cc @@ -0,0 +1,53 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "common/AsyncOpTracker.h" +#include "include/assert.h" +#include "include/Context.h" + +AsyncOpTracker::AsyncOpTracker() + : m_lock("AsyncOpTracker::m_lock", false, false) { +} + +AsyncOpTracker::~AsyncOpTracker() { + Mutex::Locker locker(m_lock); + assert(m_pending_ops == 0); +} + +void AsyncOpTracker::start_op() { + Mutex::Locker locker(m_lock); + ++m_pending_ops; +} + +void AsyncOpTracker::finish_op() { + Context *on_finish = nullptr; + { + Mutex::Locker locker(m_lock); + assert(m_pending_ops > 0); + if (--m_pending_ops == 0) { + std::swap(on_finish, m_on_finish); + } + } + + if (on_finish != nullptr) { + on_finish->complete(0); + } +} + +void AsyncOpTracker::wait_for_ops(Context *on_finish) { + { + Mutex::Locker locker(m_lock); + assert(m_on_finish == nullptr); + if (m_pending_ops > 0) { + m_on_finish = on_finish; + return; + } + } + on_finish->complete(0); +} + +bool AsyncOpTracker::empty() { + Mutex::Locker locker(m_lock); + return (m_pending_ops == 0); +} + diff --git a/src/common/AsyncOpTracker.h b/src/common/AsyncOpTracker.h new file mode 100644 index 000000000000..fccc9f91d6bd --- /dev/null +++ b/src/common/AsyncOpTracker.h @@ -0,0 +1,31 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef CEPH_ASYNC_OP_TRACKER_H +#define CEPH_ASYNC_OP_TRACKER_H + +#include "include/int_types.h" +#include "common/Mutex.h" + +struct Context; + +class AsyncOpTracker { +public: + AsyncOpTracker(); + ~AsyncOpTracker(); + + void start_op(); + void finish_op(); + + void wait_for_ops(Context *on_finish); + + bool empty(); + +private: + Mutex m_lock; + uint32_t m_pending_ops = 0; + Context *m_on_finish = nullptr; + +}; + +#endif // CEPH_ASYNC_OP_TRACKER_H diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 8b30eeadec17..0a3a4ae96106 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -1,5 +1,6 @@ libcommon_internal_la_SOURCES = \ ceph_ver.c \ + common/AsyncOpTracker.cc \ common/DecayCounter.cc \ common/LogClient.cc \ common/LogEntry.cc \ @@ -178,6 +179,7 @@ libcommon_la_LIBADD = $(LIBCOMMON_DEPS) noinst_LTLIBRARIES += libcommon.la noinst_HEADERS += \ + common/AsyncOpTracker.h \ common/BackTrace.h \ common/RefCountedObj.h \ common/HeartbeatMap.h \ diff --git a/src/journal/AsyncOpTracker.cc b/src/journal/AsyncOpTracker.cc deleted file mode 100644 index 13a55fa7a47c..000000000000 --- a/src/journal/AsyncOpTracker.cc +++ /dev/null @@ -1,64 +0,0 @@ -// -*- 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 "include/assert.h" - -namespace journal { - -AsyncOpTracker::AsyncOpTracker() - : m_lock(utils::unique_lock_name("AsyncOpTracker::m_lock", this)), - m_pending_ops(0) { -} - -AsyncOpTracker::~AsyncOpTracker() { - wait_for_ops(); -} - -void AsyncOpTracker::start_op() { - Mutex::Locker locker(m_lock); - ++m_pending_ops; -} - -void AsyncOpTracker::finish_op() { - Context *on_finish = nullptr; - { - 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); - } - } - - if (on_finish != nullptr) { - on_finish->complete(0); - } -} - -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); - assert(m_on_finish == nullptr); - if (m_pending_ops > 0) { - m_on_finish = on_finish; - return; - } - } - on_finish->complete(0); -} - -bool AsyncOpTracker::empty() { - Mutex::Locker locker(m_lock); - return (m_pending_ops == 0); -} - -} // namespace journal diff --git a/src/journal/AsyncOpTracker.h b/src/journal/AsyncOpTracker.h deleted file mode 100644 index a88cd453fe91..000000000000 --- a/src/journal/AsyncOpTracker.h +++ /dev/null @@ -1,38 +0,0 @@ -// -*- 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 - -#include "include/int_types.h" -#include "common/Cond.h" -#include "common/Mutex.h" - -struct Context; - -namespace journal { - -class AsyncOpTracker { -public: - AsyncOpTracker(); - ~AsyncOpTracker(); - - 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; - Context *m_on_finish = nullptr; - -}; - -} // namespace journal - -#endif // CEPH_JOURNAL_ASYNC_OP_TRACKER_H diff --git a/src/journal/JournalMetadata.h b/src/journal/JournalMetadata.h index d28710b3c15d..61b16967d4d6 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 690eccdd4719..ff5732bd8aa7 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 ec76d722cac5..9aefb879ea75 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 diff --git a/src/journal/Makefile.am b/src/journal/Makefile.am index ad4d54dc4885..676997aed3d6 100644 --- a/src/journal/Makefile.am +++ b/src/journal/Makefile.am @@ -2,7 +2,6 @@ if ENABLE_CLIENT if WITH_RADOS libjournal_la_SOURCES = \ - journal/AsyncOpTracker.cc \ journal/Entry.cc \ journal/Future.cc \ journal/FutureImpl.cc \ @@ -17,7 +16,6 @@ libjournal_la_SOURCES = \ noinst_LTLIBRARIES += libjournal.la noinst_HEADERS += \ - journal/AsyncOpTracker.h \ journal/Entry.h \ journal/Future.h \ journal/FutureImpl.h \