ngl_server 1.0
基于 Actor 模型的 C++ 服务器框架
tools_time_wheel.cpp File Reference

实现时间轮定时器逻辑 More...

#include "tools/tools/tools_time_wheel.h"
#include "tools/tools/tools_thread.h"
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <chrono>
#include <limits>
#include <memory>

Classes

class  ngl::tools::wheel
 时间轮轮次类 More...
struct  ngl::tools::time_wheel::impl_time_wheel
 time_wheel内部实现结构体 More...

Namespaces

namespace  ngl::tools
 工具函数命名空间。

Detailed Description

实现时间轮定时器逻辑

基于层级时间轮(Hierarchical Timing Wheel)算法实现高效定时器:

  1. 多层级时间轮:每个轮次覆盖递增的时间跨度,支持长时间范围定时
  2. 槽位推进:通过shift_current_pos实现O(1)时间复杂度的定时器触发
  3. 重复定时器:支持按间隔重复执行,自动克隆和重新调度
  4. 线程安全:使用读写锁保护定时器状态,支持独立回调线程
Note
时间精度由m_time_wheel_precision配置,单位毫秒
See also
tools_time_wheel.h, time_wheel, wheel_node