/
flusher.hh
67 lines (54 loc) · 1.31 KB
/
flusher.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#ifndef FLUSHER_H
#define FLUSHER_H 1
#include "common.hh"
#include "ep.hh"
#include "dispatcher.hh"
enum flusher_state {
initializing,
running,
pausing,
paused,
stopping,
stopped
};
class Flusher;
class FlusherStepper : public DispatcherCallback {
public:
FlusherStepper(Flusher* f) : flusher(f) { }
virtual bool callback(Dispatcher &d, TaskId t);
private:
Flusher *flusher;
};
class Flusher {
public:
Flusher(EventuallyPersistentStore *st, Dispatcher *d) :
store(st), _state(initializing), dispatcher(d) {
}
~Flusher() {
stop();
wait();
}
bool stop();
void wait();
bool pause();
bool resume();
void initialize(TaskId);
void start(void);
void wake(void);
bool step(Dispatcher&, TaskId);
bool transition_state(enum flusher_state to);
enum flusher_state state() const;
const char * stateName() const;
private:
int doFlush();
void schedule_UNLOCKED();
EventuallyPersistentStore *store;
volatile enum flusher_state _state;
Mutex taskMutex;
TaskId task;
Dispatcher *dispatcher;
const char * stateName(enum flusher_state st) const;
DISALLOW_COPY_AND_ASSIGN(Flusher);
};
#endif /* FLUSHER_H */