一、主循环驱动流程(核心大动脉)

1
2
3
4
5
6
7
8
9
10
11
loop()
↓
while (!quit_)
↓
poller_->poll() // 阻塞等待事件
↓
activeChannels 被填充
↓
遍历 channel->handleEvent() // IO 关键路径
↓
doPendingFunctors() // 任务队列

二、Channel 注册 / 更新 / 删除 流程

1
2
3
4
5
6
7
8
9
Channel::enableReading()
↓
Channel::update()
↓
EventLoop::updateChannel()
↓
Poller::updateChannel()
↓
epoll_ctl()
1
2
3
4
5
EventLoop::removeChannel()
↓
Poller::removeChannel()
↓
epoll_ctl_del()

三、任务队列 完整联动(跨线程)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
runInLoop(cb)
↓
本线程 → cb()
跨线程 → queueInLoop(cb)
↓
加锁、加入 pendingFunctors_
↓
if (!isInLoopThread() || callingPendingFunctors_)
↓
wakeup()
↓
loop() 被唤醒
↓
doPendingFunctors()
↓
callingPendingFunctors_ = true
↓
swap 交换队列(解锁)
↓
执行所有 functor
↓
callingPendingFunctors_ = false

四、退出流程 联动

1
2
3
4
5
6
7
8
9
10
11
quit()
↓
quit_ = true
↓
if (!isInLoopThread()) wakeup()
↓
loop() 被唤醒
↓
while (!quit_) 退出
↓
loop 结束

五、状态判断函数 作用点

1
2
3
4
5
hasChannel(channel)
↓
Poller::hasChannel()
↓
判断 channel 是否在 epoll 监听中
1
2
3
4
5
isInLoopThread()
↓
runInLoop / queueInLoop / quit 全都用
↓
决定是否直接执行 or 唤醒