]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/AsyncOpTracker.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "common/AsyncOpTracker.h"
5 #include "include/Context.h"
7 AsyncOpTracker::AsyncOpTracker()
11 AsyncOpTracker::~AsyncOpTracker() {
12 std::lock_guard
locker(m_lock
);
13 ceph_assert(m_pending_ops
== 0);
16 void AsyncOpTracker::start_op() {
17 std::lock_guard
locker(m_lock
);
21 void AsyncOpTracker::finish_op() {
22 Context
*on_finish
= nullptr;
24 std::lock_guard
locker(m_lock
);
25 ceph_assert(m_pending_ops
> 0);
26 if (--m_pending_ops
== 0) {
27 std::swap(on_finish
, m_on_finish
);
31 if (on_finish
!= nullptr) {
32 on_finish
->complete(0);
36 void AsyncOpTracker::wait_for_ops(Context
*on_finish
) {
38 std::lock_guard
locker(m_lock
);
39 ceph_assert(m_on_finish
== nullptr);
40 if (m_pending_ops
> 0) {
41 m_on_finish
= on_finish
;
45 on_finish
->complete(0);
48 bool AsyncOpTracker::empty() {
49 std::lock_guard
locker(m_lock
);
50 return (m_pending_ops
== 0);