-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEventLoop.h
More file actions
57 lines (46 loc) · 1.25 KB
/
EventLoop.h
File metadata and controls
57 lines (46 loc) · 1.25 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
54
55
56
57
#ifndef __EVENT_LOOP_HEAD
#define __EVENT_LOOP_HEAD
#include <functional>
#include <vector>
#include <memory>
#include "Event.h"
#include "Epoll.h"
#include "utils/SocketUtils.h"
#include "utils/CurrentThread.h"
#include "utils/Thread.h"
// reference muduo
class EventLoop{
private:
typedef std::function<void()> Functor;
bool looping_;
std::shared_ptr<Epoll> epoller_;
// wakeupFd_ is a eventfd.
// async connect between diff thread use eventfd
int wakeupFd_;
bool quit_;
bool eventHandling_;
mutable MutexLock mutex_;
std::vector<Functor> pendingFunctors_;
bool callingPendingFunctors_;
const pid_t threadId_;
// wrapper eventfd as a Event class
std::shared_ptr<Event> pwakeupEvent_;
void wakeup();
void readWakeupFd();
void doPendingFunctors();
void handleConn();
public:
EventLoop();
~EventLoop();
void loop();
void quit();
void runInLoop(Functor&& callBack);
void queueInLoop(Functor&& callBack);
bool isInLoopThread() const{ return threadId_ == CurrentThread::tid(); }
void assertInLoopThread();
void shutdown(std::shared_ptr<Event> event);
void removeFromEpoller(std::shared_ptr<Event> event);
void updateEpoller(std::shared_ptr<Event> event, int timeout=0);
void addToEpoller(std::shared_ptr<Event> event, int timeout=0);
};
#endif