summaryrefslogtreecommitdiffstats
path: root/src/common/AsyncOpTracker.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/common/AsyncOpTracker.cc
parentInitial commit. (diff)
downloadceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.tar.xz
ceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/common/AsyncOpTracker.cc')
-rw-r--r--src/common/AsyncOpTracker.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/common/AsyncOpTracker.cc b/src/common/AsyncOpTracker.cc
new file mode 100644
index 000000000..fb6439d38
--- /dev/null
+++ b/src/common/AsyncOpTracker.cc
@@ -0,0 +1,52 @@
+// -*- 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/Context.h"
+
+AsyncOpTracker::AsyncOpTracker()
+{
+}
+
+AsyncOpTracker::~AsyncOpTracker() {
+ std::lock_guard locker(m_lock);
+ ceph_assert(m_pending_ops == 0);
+}
+
+void AsyncOpTracker::start_op() {
+ std::lock_guard locker(m_lock);
+ ++m_pending_ops;
+}
+
+void AsyncOpTracker::finish_op() {
+ Context *on_finish = nullptr;
+ {
+ std::lock_guard locker(m_lock);
+ ceph_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) {
+ {
+ std::lock_guard locker(m_lock);
+ ceph_assert(m_on_finish == nullptr);
+ if (m_pending_ops > 0) {
+ m_on_finish = on_finish;
+ return;
+ }
+ }
+ on_finish->complete(0);
+}
+
+bool AsyncOpTracker::empty() {
+ std::lock_guard locker(m_lock);
+ return (m_pending_ops == 0);
+}
+