-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventLoopThread.cc
50 lines (47 loc) · 1.11 KB
/
EventLoopThread.cc
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
#include"EventLoopThread.h"
#include"MutexLock.h"
#include"MutexLockGrard.h"
#include"EventLoop.h"
#include<glog/logging.h>
void* threadFunc(void * arg)
{
EventLoop *thisLoop;
EventLoopThread *thread=(EventLoopThread*) arg;
{
MutexLockGrard LOCK(*(thread->getmutex()));
EventLoop *IOloop=new EventLoop();
thread->setIOloop(IOloop);
pthread_cond_signal(thread->getCond());
thisLoop=IOloop;
}
thread->loop();
LOG(INFO)<<"EventLoop :"<<thisLoop<<" exited\n";
//IOloop=new EventLoop();
}
EventLoopThread::EventLoopThread(/* args */)
:mutex_(new MutexLock()),
cond_(PTHREAD_COND_INITIALIZER)
{
}
EventLoopThread::~EventLoopThread()
{
}
EventLoop* EventLoopThread::startLoop()
{
if(pthread_create(&(this->currentThread),NULL,threadFunc,this)!=0)
LOG(ERROR)<<"thread creat\n";
IOloop =NULL;
{
MutexLockGrard LOCK(*mutex_);
while(IOloop==NULL)
{
pthread_cond_wait(&cond_,mutex_->getMutex());
}
}
return IOloop;
}
void EventLoopThread::loop()
{
assert(IOloop!=NULL);
IOloop->loop();
}