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

时间轮定时器接口 More...

#include "tools/tools/tools_thread.h"
#include "tools/tools/tools_impl.h"
#include <functional>
#include <algorithm>
#include <cstdint>
#include <limits>
#include <atomic>
#include <memory>
#include <thread>
#include <vector>
#include <array>
#include <mutex>
#include <map>

Classes

struct  ngl::tools::wheel_parm
 轮子类前向声明 More...
struct  ngl::tools::wheel_node
 时间轮节点 More...
struct  ngl::tools::time_wheel_config
 时间轮配置 More...
class  ngl::tools::time_wheel
 时间轮定时器管理器 More...
class  ngl::tools::twheel
 全局时间轮管理器 More...

Namespaces

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

Detailed Description

时间轮定时器接口

实现分层时间轮算法,用于高效管理大量定时器。 支持单次触发、重复触发和自定义间隔的定时器。 采用惰性移除机制,避免扫描整个时间轮。

Note
所有类和结构体均位于 ngl::tools 命名空间下。
// 创建时间轮并添加定时器示例
// 添加一个100ms后触发的定时器
parm.m_ms = 100;
parm.m_fun = [](const ngl::tools::wheel_node* node) {
// 定时器回调
};
int64_t timer_id = wheel.addtimer(parm);
// 添加一个每500ms重复触发的定时器
repeat_parm.m_ms = 500;
repeat_parm.m_count = 0; // 0表示永远重复
repeat_parm.m_intervalms = [](int64_t) { return 500; };
repeat_parm.m_fun = [](const ngl::tools::wheel_node* node) {
// 重复定时器回调
};
wheel.addtimer(repeat_parm);