【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

知识点

相关推荐
橘色的喵1 小时前
zmq Linux 内核与系统调优(ARM64 嵌入式平台)
linux·网络·性能优化·zmq·内核优化
无奈笑天下3 小时前
Linux上kdump故障标准处理流程
linux·运维·服务器·github
小飞在努力4 小时前
【实现负载均匀在线判题③】从零散模块到统一,编译运行全链路封装
c语言·开发语言·c++·笔记
我是码代码7 小时前
高分辨率ADC布局详解:走线压降、回流路径与地平面处理
linux·c语言·嵌入式
瑞雪兆丰年兮7 小时前
Linux快速入门 第四章 Linux系统常用操作技巧
linux·运维·服务器
星恒随风7 小时前
从0实现C++ AI大模型接入SDK(四):大模型API接入、公共数据结构设计与日志库封装
linux·服务器·数据结构·c++·人工智能
炸膛坦客7 小时前
单片机/C/C++八股:(三十四)C 语言函数参数入栈顺序
c语言·开发语言·c++
时间的拾荒人8 小时前
Linux进程间通信(上篇):匿名管道 +进程池(基于匿名管道实现)
linux·服务器·管道
码途行者8 小时前
每天10分钟学Go:第20课 泛型
c++·算法·golang
无足鸟ICT9 小时前
【RHCA+】介绍proc
linux·运维·服务器