版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/andylau00j/article/details/80904180
定时器 时序图
对于定时任务的原理:
- muduo采用
timerfd_*
将超时任务转换成文件描述符进行监听 - 当时间一到,
timerfd
变为可读,相应的Channel
调用回调函数(TimerQueue::handleRead
) - 回调函数中将所有在
TimerQueue
中的超时任务找出,一次调用其回调函数 - 对于周期性定时任务,再添加回
TimerQueue
中