1
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2
// vim: ts=8 sw=2 smarttab
4
* Ceph - scalable distributed file system
6
* Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8
* This is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public
10
* License version 2.1, as published by the Free Software
11
* Foundation. See file COPYING.
15
#ifndef CEPH_FINISHER_H
16
#define CEPH_FINISHER_H
18
#include "common/Mutex.h"
19
#include "common/Cond.h"
20
#include "common/Thread.h"
24
Cond finisher_cond, finisher_empty_cond;
25
bool finisher_stop, finisher_running;
26
vector<Context*> finisher_queue;
27
list<pair<Context*,int> > finisher_queue_rval;
29
void *finisher_thread_entry();
31
struct FinisherThread : public Thread {
33
FinisherThread(Finisher *f) : fin(f) {}
34
void* entry() { return (void*)fin->finisher_thread_entry(); }
38
void queue(Context *c, int r = 0) {
41
finisher_queue_rval.push_back(pair<Context*, int>(c, r));
42
finisher_queue.push_back(NULL);
44
finisher_queue.push_back(c);
45
finisher_cond.Signal();
46
finisher_lock.Unlock();
48
void queue(vector<Context*>& ls) {
50
finisher_queue.insert(finisher_queue.end(), ls.begin(), ls.end());
51
finisher_cond.Signal();
52
finisher_lock.Unlock();
55
void queue(deque<Context*>& ls) {
57
finisher_queue.insert(finisher_queue.end(), ls.begin(), ls.end());
58
finisher_cond.Signal();
59
finisher_lock.Unlock();
66
void wait_for_empty();
68
Finisher() : finisher_lock("Finisher::finisher_lock"),
69
finisher_stop(false), finisher_running(false), finisher_thread(this) {}
72
class C_OnFinisher : public Context {
76
C_OnFinisher(Context *c, Finisher *f) : con(c), fin(f) {}