-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey_seq_executor.h
59 lines (40 loc) · 1.21 KB
/
key_seq_executor.h
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
#ifndef KEY_SEQ_EXEC_H
#define KEY_SEQ_EXEC_H
#include <iostream>
#include <thread>
#include <functional>
#include <memory>
#include <unordered_map>
#include <boost/thread/latch.hpp>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/functional/hash.hpp>
using Job_t = std::function<void(void)>;
class Worker;
using WorkerPtr_t = std::shared_ptr<Worker>;
class KeySequentialExecutor
{
public:
KeySequentialExecutor(size_t numThreads);
~KeySequentialExecutor();
virtual void execute(const std::string& key, Job_t job);
private:
void run();
void execute_(const std::string& key, Job_t job);
void work(const boost::system::error_code& /*e*/);
void start();
void stop();
void startWorkers();
void stopWorkers();
boost::asio::io_service m_ios;
const std::string m_name;
boost::asio::deadline_timer m_wrkTimer;
std::vector<WorkerPtr_t> m_workers;
const size_t m_numThreads;
bool m_stopExecutor;
std::unique_ptr<std::thread> m_thread;
boost::latch m_latch;
std::unordered_map<int, unsigned long> m_stats;
};
#endif // KEY_SEQ_EXEC_H