]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | #include "common/ContextCompletion.h" | |
4 | ||
5 | namespace ceph | |
6 | { | |
7 | ||
8 | ContextCompletion::ContextCompletion(Context *ctx, bool ignore_enoent) | |
11fdf7f2 | 9 | : m_ctx(ctx), |
7c673cae FG |
10 | m_ignore_enoent(ignore_enoent), m_ret(0), m_building(true), m_current_ops(0) |
11 | { | |
12 | } | |
13 | ||
14 | void ContextCompletion::finish_adding_requests() { | |
15 | bool complete; | |
16 | { | |
11fdf7f2 | 17 | std::lock_guard l(m_lock); |
7c673cae FG |
18 | m_building = false; |
19 | complete = (m_current_ops == 0); | |
20 | } | |
21 | if (complete) { | |
22 | m_ctx->complete(m_ret); | |
23 | delete this; | |
24 | } | |
25 | } | |
26 | ||
27 | void ContextCompletion::start_op() { | |
11fdf7f2 | 28 | std::lock_guard l(m_lock); |
7c673cae FG |
29 | ++m_current_ops; |
30 | } | |
31 | ||
32 | void ContextCompletion::finish_op(int r) { | |
33 | bool complete; | |
34 | { | |
11fdf7f2 | 35 | std::lock_guard l(m_lock); |
7c673cae FG |
36 | if (r < 0 && m_ret == 0 && (!m_ignore_enoent || r != -ENOENT)) { |
37 | m_ret = r; | |
38 | } | |
39 | ||
40 | --m_current_ops; | |
41 | complete = (m_current_ops == 0 && !m_building); | |
42 | } | |
43 | if (complete) { | |
44 | m_ctx->complete(m_ret); | |
45 | delete this; | |
46 | } | |
47 | } | |
48 | ||
49 | } // namespace ceph |