-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathepoller_thread.cpp
More file actions
53 lines (45 loc) · 824 Bytes
/
Copy pathepoller_thread.cpp
File metadata and controls
53 lines (45 loc) · 824 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "epoller.h"
#include "epoller_thread.h"
#include <boost/bind.hpp>
using namespace ydx;
EPollerThread::EPollerThread(const std::string & name)
: epoller_(NULL),
exiting_(false),
thread_(boost::bind(&EPollerThread::threadFunc, this), name),
mutex_(),
cond_(mutex_)
{}
EPollerThread::~EPollerThread()
{
exiting_ = true;
if(NULL != epoller_)
{
epoller_->quit();
thread_.join();
}
}
EPollPoller* EPollerThread::startEpoll()
{
thread_.start();
{
MutexLockGuard lock(mutex_);
while(epoller_ == NULL)
{
cond_.wait();
}
}
return epoller_;
}
void EPollerThread::threadFunc()
{
EPollPoller epoller;
{
MutexLockGuard lock(mutex_);
epoller_ = &epoller ;
cond_.notify();
}
epoller_->enable_wakeup();
epoller_->poll();
//existed epoller main loop
epoller_ = NULL;
}