ceph/src/common/Finisher.cc

88 lines
2.1 KiB
C++
Raw Normal View History

// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
2008-02-27 17:57:29 +00:00
#include "common/config.h"
2008-02-27 17:57:29 +00:00
#include "Finisher.h"
2010-01-28 18:33:04 +00:00
#include "common/debug.h"
#define dout_subsys ceph_subsys_finisher
2010-01-28 18:33:04 +00:00
#undef dout_prefix
#define dout_prefix *_dout << "finisher(" << this << ") "
2010-01-28 18:33:04 +00:00
2008-02-27 17:57:29 +00:00
void Finisher::start()
{
finisher_thread.create();
}
void Finisher::stop()
{
finisher_lock.Lock();
finisher_stop = true;
finisher_cond.Signal();
finisher_lock.Unlock();
finisher_thread.join();
}
2010-01-26 00:24:25 +00:00
void Finisher::wait_for_empty()
{
finisher_lock.Lock();
2010-01-28 18:33:04 +00:00
while (!finisher_queue.empty() || finisher_running) {
ldout(cct, 10) << "wait_for_empty waiting" << dendl;
2010-01-28 18:33:04 +00:00
finisher_empty_cond.Wait(finisher_lock);
}
ldout(cct, 10) << "wait_for_empty empty" << dendl;
2010-01-26 00:24:25 +00:00
finisher_lock.Unlock();
}
2008-02-27 17:57:29 +00:00
void *Finisher::finisher_thread_entry()
{
finisher_lock.Lock();
ldout(cct, 10) << "finisher_thread start" << dendl;
2008-02-27 17:57:29 +00:00
while (!finisher_stop) {
while (!finisher_queue.empty()) {
vector<Context*> ls;
2009-12-16 23:39:48 +00:00
list<pair<Context*,int> > ls_rval;
2008-02-27 17:57:29 +00:00
ls.swap(finisher_queue);
2009-12-16 23:39:48 +00:00
ls_rval.swap(finisher_queue_rval);
2010-01-28 18:33:04 +00:00
finisher_running = true;
2008-02-27 17:57:29 +00:00
finisher_lock.Unlock();
ldout(cct, 10) << "finisher_thread doing " << ls << dendl;
2008-02-27 17:57:29 +00:00
2009-12-16 23:39:48 +00:00
for (vector<Context*>::iterator p = ls.begin();
p != ls.end();
++p) {
2009-12-16 23:39:48 +00:00
if (*p) {
(*p)->complete(0);
2009-12-16 23:39:48 +00:00
} else {
assert(!ls_rval.empty());
Context *c = ls_rval.front().first;
c->complete(ls_rval.front().second);
2009-12-16 23:39:48 +00:00
ls_rval.pop_front();
}
if (logger)
logger->dec(l_finisher_queue_len);
2009-12-16 23:39:48 +00:00
}
ldout(cct, 10) << "finisher_thread done with " << ls << dendl;
2009-12-16 23:39:48 +00:00
ls.clear();
2008-02-27 17:57:29 +00:00
finisher_lock.Lock();
2010-01-28 18:33:04 +00:00
finisher_running = false;
2008-02-27 17:57:29 +00:00
}
ldout(cct, 10) << "finisher_thread empty" << dendl;
2010-01-28 18:33:04 +00:00
finisher_empty_cond.Signal();
if (finisher_stop)
break;
2008-02-27 17:57:29 +00:00
ldout(cct, 10) << "finisher_thread sleeping" << dendl;
2008-02-27 17:57:29 +00:00
finisher_cond.Wait(finisher_lock);
}
2010-01-28 18:33:04 +00:00
finisher_empty_cond.Signal();
2008-02-27 17:57:29 +00:00
ldout(cct, 10) << "finisher_thread stop" << dendl;
finisher_stop = false;
2008-02-27 17:57:29 +00:00
finisher_lock.Unlock();
return 0;
}