ceph/src/common/Finisher.cc

61 lines
1.2 KiB
C++
Raw Normal View History

2008-02-27 17:57:29 +00:00
#include "config.h"
#include "Finisher.h"
void Finisher::start()
{
finisher_thread.create();
}
void Finisher::stop()
{
finisher_lock.Lock();
finisher_stop = true;
finisher_cond.Signal();
finisher_lock.Unlock();
finisher_thread.join();
}
void *Finisher::finisher_thread_entry()
{
finisher_lock.Lock();
//dout_generic(10) << "finisher_thread start" << dendl;
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);
2008-02-27 17:57:29 +00:00
finisher_lock.Unlock();
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();
}
}
ls.clear();
2008-02-27 17:57:29 +00:00
finisher_lock.Lock();
}
if (finisher_stop) break;
//dout_generic(30) << "finisher_thread sleeping" << dendl;
finisher_cond.Wait(finisher_lock);
}
//dout_generic(10) << "finisher_thread start" << dendl;
finisher_lock.Unlock();
return 0;
}