~mathiaz/+junk/ceph-new-pkg-review

« back to all changes in this revision

Viewing changes to src/common/Finisher.cc

  • Committer: Mathias Gug
  • Date: 2010-07-29 03:10:42 UTC
  • Revision ID: mathias.gug@canonical.com-20100729031042-n9n8kky962qb4onb
Import ceph_0.21-0ubuntu1 from https://launchpad.net/~clint-fewbar/+archive/ceph/+packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include "config.h"
 
3
#include "Finisher.h"
 
4
 
 
5
#include "common/debug.h"
 
6
#define DOUT_SUBSYS finisher
 
7
#undef dout_prefix
 
8
#define dout_prefix *_dout << dbeginl << "finisher(" << this << ") "
 
9
 
 
10
void Finisher::start()
 
11
{
 
12
  finisher_thread.create();
 
13
}
 
14
 
 
15
void Finisher::stop()
 
16
{
 
17
  finisher_lock.Lock();
 
18
  finisher_stop = true;
 
19
  finisher_cond.Signal();
 
20
  finisher_lock.Unlock();
 
21
  finisher_thread.join();
 
22
}
 
23
 
 
24
void Finisher::wait_for_empty()
 
25
{
 
26
  finisher_lock.Lock();
 
27
  while (!finisher_queue.empty() || finisher_running) {
 
28
    dout(10) << "wait_for_empty waiting" << dendl;
 
29
    finisher_empty_cond.Wait(finisher_lock);
 
30
  }
 
31
  dout(10) << "wait_for_empty empty" << dendl;
 
32
  finisher_lock.Unlock();
 
33
}
 
34
 
 
35
void *Finisher::finisher_thread_entry()
 
36
{
 
37
  finisher_lock.Lock();
 
38
  dout(10) << "finisher_thread start" << dendl;
 
39
 
 
40
  while (!finisher_stop) {
 
41
    while (!finisher_queue.empty()) {
 
42
      vector<Context*> ls;
 
43
      list<pair<Context*,int> > ls_rval;
 
44
      ls.swap(finisher_queue);
 
45
      ls_rval.swap(finisher_queue_rval);
 
46
      finisher_running = true;
 
47
      finisher_lock.Unlock();
 
48
      dout(10) << "finisher_thread doing " << ls << dendl;
 
49
 
 
50
      for (vector<Context*>::iterator p = ls.begin();
 
51
           p != ls.end();
 
52
           p++) {
 
53
        if (*p) {
 
54
          (*p)->finish(0);
 
55
          delete *p;
 
56
        } else {
 
57
          assert(!ls_rval.empty());
 
58
          Context *c = ls_rval.front().first;
 
59
          c->finish(ls_rval.front().second);
 
60
          delete c;
 
61
          ls_rval.pop_front();
 
62
        }
 
63
      }
 
64
      dout(10) << "finisher_thread done with " << ls << dendl;
 
65
      ls.clear();
 
66
 
 
67
      finisher_lock.Lock();
 
68
      finisher_running = false;
 
69
    }
 
70
    dout(10) << "finisher_thread empty" << dendl;
 
71
    finisher_empty_cond.Signal();
 
72
    if (finisher_stop)
 
73
      break;
 
74
    
 
75
    dout(10) << "finisher_thread sleeping" << dendl;
 
76
    finisher_cond.Wait(finisher_lock);
 
77
  }
 
78
  finisher_empty_cond.Signal();
 
79
 
 
80
  dout(10) << "finisher_thread stop" << dendl;
 
81
  finisher_lock.Unlock();
 
82
  return 0;
 
83
}
 
84