【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

知识点

相关推荐
范纹杉想快点毕业28 分钟前
以项目的方式学QT开发(一)——超详细讲解(120000多字详细讲解,涵盖qt大量知识)逐步更新!
c语言·数据结构·c++·git·qt·链表·github
yangshuo12811 小时前
风车OVF镜像:解放AI开发限制的Ubuntu精简系统
linux·人工智能·ubuntu
flypig哗啦啦1 小时前
ubuntu服务器版启动卡在start job is running for wait for...to be Configured
linux·运维·ubuntu
_Itachi__1 小时前
LeetCode 热题 100 114. 二叉树展开为链表
linux·leetcode·链表
敷啊敷衍1 小时前
深入探索 C++ 中的 string 类:从基础到实践
开发语言·数据结构·c++
あ-2 小时前
CentOS7 OpenSSL升级1.1.1w
linux
tianyuanwo2 小时前
深入解读tcpdump:原理、数据结构与操作手册
linux·运维·服务器·tcpdump
什么名字都被用了2 小时前
编译openssl源码
c++·openssl
ai.Neo2 小时前
牛客网NC22157:牛牛学数列2
数据结构·c++·算法
Nobkins3 小时前
2023CCPC河南省赛暨河南邀请赛个人补题ABEFGHK
开发语言·数据结构·c++·算法·图论