forked from L1w-Y/muduo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventLoopThreadPool.h
More file actions
32 lines (27 loc) · 828 Bytes
/
Copy pathEventLoopThreadPool.h
File metadata and controls
32 lines (27 loc) · 828 Bytes
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
#pragma onec
#include "noncopyable.h"
#include<functional>
#include<string>
#include<vector>
#include<memory>
class EventLoop;
class EventLoopThread;
class EventLoopThreadPool :noncopyable{
public:
using ThreadInitCallback = std::function<void(EventLoop*)>;
EventLoopThreadPool(EventLoop *baseLoop, const std::string &nameArg);
~EventLoopThreadPool();
void setThreadNum(int numThreads){numThreads = numThreads;}
void start(const ThreadInitCallback &cb = ThreadInitCallback());
EventLoop* getNextLoop();
std::vector<EventLoop*> getAllLoops();
bool started()const{return started_;}
private:
EventLoop *baseLoop_;
std::string name_;
bool started_;
int numThreads_;
int next_;
std::vector<std::unique_ptr<EventLoopThread>> threads_;
std::vector<EventLoop*> loops_;
};