blob: dfa913ad4a3a0f5ff6bcecaa8134f4881fe071a4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
// -*- 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 "common/ceph_mutex.h"
#include "include/Context.h"
class AsyncOpTracker {
public:
AsyncOpTracker();
~AsyncOpTracker();
void start_op();
void finish_op();
void wait_for_ops(Context *on_finish);
bool empty();
private:
ceph::mutex m_lock = ceph::make_mutex("AsyncOpTracker::m_lock");
uint32_t m_pending_ops = 0;
Context *m_on_finish = nullptr;
};
class C_TrackedOp : public Context {
public:
C_TrackedOp(AsyncOpTracker& async_op_tracker, Context* on_finish)
: m_async_op_tracker(async_op_tracker), m_on_finish(on_finish) {
m_async_op_tracker.start_op();
}
void finish(int r) override {
if (m_on_finish != nullptr) {
m_on_finish->complete(r);
}
m_async_op_tracker.finish_op();
}
private:
AsyncOpTracker& m_async_op_tracker;
Context* m_on_finish;
};
#endif // CEPH_ASYNC_OP_TRACKER_H
|