定时器 时序图
对于定时任务的原理:
- muduo采用
timerfd_*
将超时任务转换成文件描述符进行监听 - 当时间一到,
timerfd
变为可读,相应的Channel
调用回调函数(TimerQueue::handleRead
) - 回调函数中将所有在
TimerQueue
中的超时任务找出,一次调用其回调函数 - 对于周期性定时任务,再添加回
TimerQueue
中
定时器 时序图
对于定时任务的原理:
timerfd_*
将超时任务转换成文件描述符进行监听timerfd
变为可读,相应的Channel
调用回调函数(TimerQueue::handleRead
)TimerQueue
中的超时任务找出,一次调用其回调函数TimerQueue
中