|
ngl_server 1.0
基于 Actor 模型的 C++ 服务器框架
|
时间轮定时器管理器 More...
#include <tools_time_wheel.h>
Classes | |
| struct | impl_time_wheel |
| time_wheel内部实现结构体 More... | |
Public Member Functions | |
| time_wheel (const time_wheel_config &aconfig=time_wheel_config(), bool aisthreadcallback=true) | |
| 构造函数 | |
| ~time_wheel () | |
| 析构函数 | |
| int | count () |
| 获取当前定时器数量 | |
| bool | empty () |
| 检查时间轮是否为空 | |
| int64_t | server_start_ms () |
| 获取服务器启动时间(毫秒) | |
| int64_t | server_current_ms () |
| 获取服务器当前时间(毫秒) | |
| int64_t | addtimer (const wheel_parm &apram) |
| 添加定时器 | |
| void | removetimer (int64_t atimerid) |
| 移除定时器 | |
| std::shared_ptr< wheel_node > | pop_node () |
| 弹出到期的定时器节点 | |
Static Public Member Functions | |
| static int64_t | getms () |
| 获取当前时间戳(毫秒) | |
Friends | |
| class | wheel |
时间轮定时器管理器
实现分层时间轮算法,用于高效管理大量定时器。 支持单次触发、重复触发和自定义间隔的定时器。 采用惰性移除机制,避免扫描整个时间轮。
| ngl::tools::time_wheel::time_wheel | ( | const time_wheel_config & | aconfig = time_wheel_config(), |
| bool | aisthreadcallback = true ) |
构造函数
time_wheel构造函数
| aconfig | 时间轮配置 |
| aisthreadcallback | 是否使用专用回调线程 |
| aconfig | 时间轮配置 |
| aisthreadcallback | 是否使用独立回调线程 |
|
default |
析构函数
time_wheel析构函数
| int64_t ngl::tools::time_wheel::addtimer | ( | const wheel_parm & | apram | ) |
添加定时器
| apram | 定时器参数 |
返回一个稳定的定时器ID。m_count <= 0 表示"永远重复"。
| apram | 定时器参数 |
| int ngl::tools::time_wheel::count | ( | ) |
获取当前定时器数量
获取当前活跃定时器数量
| bool ngl::tools::time_wheel::empty | ( | ) |
检查时间轮是否为空
| true | 无活跃定时器 |
| false | 有活跃定时器 |
|
static |
获取当前时间戳(毫秒)
获取系统时钟毫秒时间戳
使用system_clock,返回Unix纪元以来的毫秒数
| std::shared_ptr< wheel_node > ngl::tools::time_wheel::pop_node | ( | ) |
弹出到期的定时器节点
从回调队列中弹出一个到期定时器节点
当回调被手动消费而非从专用回调线程消费时使用。
| void ngl::tools::time_wheel::removetimer | ( | int64_t | atimerid | ) |
移除定时器
| atimerid | 定时器ID |
移除是惰性的,标记共享取消标志而非扫描每个时间轮槽位。
| atimerid | 定时器ID |
| int64_t ngl::tools::time_wheel::server_current_ms | ( | ) |
获取服务器当前时间(毫秒)
获取服务器当前逻辑时间戳(毫秒)
| int64_t ngl::tools::time_wheel::server_start_ms | ( | ) |
获取服务器启动时间(毫秒)
获取服务器启动时间戳(毫秒)