diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/common/ContextCompletion.cc | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/common/ContextCompletion.cc')
-rw-r--r-- | src/common/ContextCompletion.cc | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/common/ContextCompletion.cc b/src/common/ContextCompletion.cc new file mode 100644 index 000000000..a4f816834 --- /dev/null +++ b/src/common/ContextCompletion.cc @@ -0,0 +1,49 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +#include "common/ContextCompletion.h" + +namespace ceph +{ + +ContextCompletion::ContextCompletion(Context *ctx, bool ignore_enoent) + : m_ctx(ctx), + m_ignore_enoent(ignore_enoent), m_ret(0), m_building(true), m_current_ops(0) +{ +} + +void ContextCompletion::finish_adding_requests() { + bool complete; + { + std::lock_guard l(m_lock); + m_building = false; + complete = (m_current_ops == 0); + } + if (complete) { + m_ctx->complete(m_ret); + delete this; + } +} + +void ContextCompletion::start_op() { + std::lock_guard l(m_lock); + ++m_current_ops; +} + +void ContextCompletion::finish_op(int r) { + bool complete; + { + std::lock_guard l(m_lock); + if (r < 0 && m_ret == 0 && (!m_ignore_enoent || r != -ENOENT)) { + m_ret = r; + } + + --m_current_ops; + complete = (m_current_ops == 0 && !m_building); + } + if (complete) { + m_ctx->complete(m_ret); + delete this; + } +} + +} // namespace ceph |