【sylar-webserver】7 定时器模块

文章目录

设计

belongs to 1 1 manages many <<enable_shared_from_this>> Timer -uint64_t m_ms -uint64_t m_next -bool m_recurring -TimerManager* m_manager +struct Comparator -std::function m_cb +bool cancel() +bool refresh() +bool reset(uint64_t ms, bool from_now) -Timer(uint64_t ms, std::function cb, bool recurring, TimerManager* manager) -Timer(uint64_t next) TimerManager -RWMutexType m_mutex -std::set m_timers -bool m_tickled -uint64_t m_previouseTime +TimerManager() +~TimerManager() +Timer::ptr addTimer(uint64_t ms, std::function cb, bool recurring = false) +Timer::ptr addConditionTimer(uint64_t ms, std::function cb, std::weak_ptr weak_cond, bool recurring = false) +uint64_t getNextTimer() +void listExpiredCb(std::vector>& cbs) +bool hasTimer() +bool detectClockRollover(uint64_t now_ms) #virtual void onTimerInsertedAtFront() #void addTimer(Timer::ptr val, RWMutexType::WriteLock& lock) enable_shared_from_this
Main iom timer_callback g_logger s_timer test_timer() addTimer(1000, timer_callback, true) Create and start recurring timer (1000ms) addTimer(500, lambda) Log "500ms timeout" after 500ms addTimer(5000, lambda) Log "5000ms timeout" after 5000ms timer_callback() Log "timer callback, timeout = {timeout}" Reset timer with new timeout (+1000ms) Cancel timer Stop recurring execution alt timeout \>= 5000 loop Recurring Timer Execution Main iom timer_callback g_logger s_timer

知识点

相关推荐
隐擎fox几秒前
Linux eBPF 与 XDP 高性能网络出口架构:动态连接追踪、丢包诊断与住宅网关 QoS 调优实战
linux·网络·网络协议·tcp/ip·架构
C语言小火车2 分钟前
C++ 为什么越来越依赖标准库?
java·开发语言·c++
八月的雨季 最後的冰吻17 分钟前
C++ 面试要点笔记(续)
c++·笔记·面试
xiaoliuliu1234532 分钟前
Linux 手动装毕昇 bisheng-jdk-8u432-linux-aarch64.tar.gz
linux
狂奔的sherry1 小时前
JRuby 多线程反引号偶发 127:GC 提前释放了 posix_spawn 的 argv
java·linux·ruby·gc·jruby
广州灵眸科技有限公司1 小时前
瑞芯微(EASY EAI)RV1126B DeepSeek R1部署教程
linux·数据库·yolo
青少儿编程课堂1 小时前
蓝桥杯·全国青少年信息素养大赛·电子学会C/C++考级:并查集连通块与朋友圈问题解析
c++·python·算法·bfs·信息学竞赛
沙老师1 小时前
linux比windows死板的地方
linux·运维·windows
wyhwust1 小时前
codeblocks程序调试
c++
H.莓飛1 小时前
【Linux】进程的创建与终止
linux·运维·服务器·c语言·visual studio