forked from guoxuanhan/NetServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheventloopthreadpool.cpp
More file actions
53 lines (49 loc) · 1.15 KB
/
eventloopthreadpool.cpp
File metadata and controls
53 lines (49 loc) · 1.15 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
#include "eventloopthreadpool.h"
EventLoopThreadPool::EventLoopThreadPool(EventLoop *mainloop, int threadnum) :
mainloop_(mainloop),
threadnum_(threadnum),
threadlist_(),
index_(0)
{
for(int i = 0; i < threadnum_; ++i)
{
EventLoopThread *peventloopthread = new EventLoopThread;
threadlist_.push_back(peventloopthread);
}
}
EventLoopThreadPool::~EventLoopThreadPool()
{
std::cout << "Clean up the EventLoopThreadPool" << std::endl;
for(int i = 0; i < threadnum_; ++i)
{
delete threadlist_[i];
}
threadlist_.clear();
}
void EventLoopThreadPool::Start()
{
if(threadnum_ > 0)
{
for(int i = 0; i < threadnum_; ++i)
{
threadlist_[i]->Start();
}
}
}
EventLoop* EventLoopThreadPool::GetNextLoop()
{
if(threadnum_ > 0)
{
EventLoop *loop = threadlist_[index_]->GetLoop();
index_ = (index_ + 1) % threadnum_;
return loop;
//LC策略,还没写
//EventLoop *loop = threadlist_[index_]->GetLoop();
//index_ = (index_ + 1) % threadnum_;
//return loop;
}
else
{
return mainloop_;
}
}