【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

知识点

相关推荐
ltl5 小时前
实时 OS 巡礼:VxWorks、QNX、Zephyr 与 PREEMPT_RT
linux
我是谁??5 小时前
Ubuntu22.04更换清华源
linux·运维·服务器
ShineWinsu6 小时前
对于C++:C++11中lambda、function、bind的解析
c++·面试·笔试·开发·lambda·bind·function
码匠许师傅6 小时前
【C++ 面试真题】聊聊 C++ 的拷贝构造与拷贝赋值
java·c++·面试
Shell运维手记6 小时前
Linux 常用基础命令学习笔记
linux·运维·笔记·学习·算法·github
旖旎夜光7 小时前
LeetCode 3:无重复字符的最长子串(滑动窗口) —— 题解
数据结构·c++·算法·leetcode·滑动窗口
汉字萌萌哒7 小时前
2024CSP-J入门级C++真题详解
开发语言·c++
测试运维日常笔记7 小时前
Linux系统安装配置TigerVNC服务器完整指南
linux·运维·服务器
hy.z_7778 小时前
【C++】13. 继承
c++
汉字萌萌哒8 小时前
2019CCF-CSP入门级C++试题解析
java·开发语言·c++