bool released;
AioCompletion() : lock("AioCompletion::lock", true), done(false), rval(0), complete_cb(NULL), complete_arg(NULL),
- rbd_comp(NULL), pending_count(0), ref(1), released(false) {
+ rbd_comp(NULL), pending_count(1), ref(1), released(false) {
dout(20) << "AioCompletion::AioCompletion() this=" << (void *)this << dendl;
}
~AioCompletion() {
dout(20) << "AioCompletion::~AioCompletion() this=" << (void *)this << dendl;
}
+
int wait_for_complete() {
dout(20) << "AioCompletion::wait_for_complete() this=" << (void *)this << dendl;
lock.Lock();
get();
}
+ void finish_adding_completions() {
+ dout(20) << "AioCompletion::finish_adding_completions() this=" << (void *)this << dendl;
+ lock.Lock();
+ assert(pending_count);
+ int count = --pending_count;
+ if (!count) {
+ complete();
+ }
+ lock.Unlock();
+ }
+
+ void complete() {
+ dout(20) << "AioCompletion::complete() this=" << (void *)this << dendl;
+ assert(lock.is_locked());
+ if (complete_cb) {
+ complete_cb(rbd_comp, complete_arg);
+ }
+ done = true;
+ cond.Signal();
+ }
+
void set_complete_cb(void *cb_arg, callback_t cb) {
complete_cb = cb;
complete_arg = cb_arg;
assert(pending_count);
int count = --pending_count;
if (!count) {
- if (complete_cb)
- complete_cb(rbd_comp, complete_arg);
- done = true;
- cond.Signal();
+ complete();
}
put_unlock();
}
}
r = 0;
done:
+ c->finish_adding_completions();
c->put();
/* FIXME: cleanup all the allocated stuff */
return r;
}
ret = total_read;
done:
+ c->finish_adding_completions();
c->put();
return ret;
}