【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

知识点

相关推荐
杨筱毅8 小时前
【底层机制】Linux内核4.10版本的完整存储栈架构讲解--用户空间到物理设备完整IO路径
linux·架构·1024程序员节·底层机制
千里马-horse9 小时前
Boost.Iostreams 简介
开发语言·c++·boost
陌路209 小时前
C17值类别概念
开发语言·c++
Wang's Blog9 小时前
Linux小课堂: 网络接口与连接监控命令详解
linux·运维·服务器
纳切威9 小时前
CentOS 10 系统安装
linux
apolloyhl9 小时前
Linux目录
linux
java_logo9 小时前
Docker 部署 Debian 全流程教程
linux·运维·docker·容器·debian
shark_dev9 小时前
C++新特性—— 智能指针(shared_ptr/unique_ptr/weak_ptr)
c++
liu****9 小时前
笔试强训(十三)
开发语言·c++·算法·1024程序员节
天上飞的粉红小猪9 小时前
linux的文件系统
linux·运维·服务器·1024程序员节