【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

知识点

相关推荐
清酒难咽6 小时前
算法案例之递归
c++·经验分享·算法
z20348315206 小时前
C++对象布局
开发语言·c++
Nick.Q7 小时前
vim插件的管理与离线安装
linux·编辑器·vim
张张努力变强7 小时前
C++ Date日期类的设计与实现全解析
java·开发语言·c++·算法
沉默-_-7 小时前
力扣hot100滑动窗口(C++)
数据结构·c++·学习·算法·滑动窗口
斐夷所非8 小时前
C++ 继承、多态与类型转换 | 函数重载 / 隐藏 / 覆盖实现与基派生类指针转换
c++
gfdhy9 小时前
【C++实战】多态版商品库存管理系统:从设计到实现,吃透面向对象核心
开发语言·数据库·c++·microsoft·毕业设计·毕设
清酒难咽9 小时前
算法案例之分治法
c++·经验分享·算法
小屁猪qAq9 小时前
强符号和弱符号及应用场景
c++·弱符号·链接·编译
头发还没掉光光9 小时前
HTTP协议从基础到实战全解析
linux·服务器·网络·c++·网络协议·http