ceph/src/common/Finisher.cc

85 lines
1.9 KiB
C++
Raw Normal View History

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 finisher
#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++) {
if (*p) {
(*p)->finish(0);
delete *p;
} else {
assert(!ls_rval.empty());
Context *c = ls_rval.front().first;
c->finish(ls_rval.front().second);
delete c;
ls_rval.pop_front();
}
}
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;
2008-02-27 17:57:29 +00:00
finisher_lock.Unlock();
return 0;
}