-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventLoopThreadPool.h
58 lines (40 loc) · 1.04 KB
/
EventLoopThreadPool.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
#ifndef EVENTLOOPTHREADPOLL_H_
#define EVENTLOOPTHREADPOLL_H_
#include"base/noncopyable.h"
#include"EventLoop.h"
#include"EventLoopThread.h"
#include<functional>
#include<memory>
#include<vector>
#include<string>
class EventLoopThreadPool:noncopyable
{
public:
typedef std::function<void(EventLoop*)> ThreadInitCallback;
EventLoopThreadPool(EventLoop* base,const std::string & namearg);
~EventLoopThreadPool();
void setThreadNum(int numThreads);
void start(const ThreadInitCallback &cb=ThreadInitCallback());
//round-robin
EventLoop* getNextLoop();
std:: vector<EventLoop*> getAllLoops();
bool started()const
{
return started_;
}
const std::string& name()const
{
return name_;
}
private:
typedef std::unique_ptr<EventLoopThread> LoopThreadPtr;
typedef std::vector<LoopThreadPtr> LoopThreadList;
EventLoop* base_;
std::string name_;
bool started_;
int next_;
int numthreads_;
LoopThreadList threads_;
std::vector<EventLoop*> loops_;
};
#endif