This repository was archived by the owner on May 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpraetor.h
More file actions
57 lines (44 loc) · 1.38 KB
/
Copy pathpraetor.h
File metadata and controls
57 lines (44 loc) · 1.38 KB
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
/**
* COPYRIGHT 2014 (C) Jason Volk
* COPYRIGHT 2014 (C) Svetlana Tkachenko
*
* DISTRIBUTED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) (see: LICENSE)
*/
class Schedule
{
std::deque<std::tuple<id_t,time_t>> sched;
void sort();
public:
static constexpr time_t max() { return std::numeric_limits<int32_t>::max(); }
bool empty() const { return sched.empty(); }
auto size() const { return sched.size(); }
id_t next_id() const { return !empty()? std::get<id_t>(sched.at(0)) : 0; }
time_t next_abs() const { return !empty()? std::get<time_t>(sched.at(0)) : max(); }
time_t next_rel() const { return !empty()? next_abs() - time(NULL) : max(); }
void add(const id_t &id, const time_t &absolute);
id_t pop();
};
class Praetor
{
Bot ⊥
Vdb &vdb;
std::mutex mutex;
std::atomic<bool> interrupted;
std::condition_variable cond;
Schedule sched;
public:
void add(const id_t &id, const time_t &absolute);
void add(std::unique_ptr<Vote> &&vote);
void add(const Adoc &serialized);
private:
bool process(Vote &vote) noexcept;
bool process(const id_t &id);
void process();
void worker();
std::thread thread;
void init();
std::thread init_thread;
public:
Praetor(Bot &bot, Vdb &vdb);
~Praetor() noexcept;
};