ngl_server 1.0
基于 Actor 模型的 C++ 服务器框架
ngl::tools::wheel Class Reference

时间轮轮次类 More...

Public Member Functions

 wheel ()
 wheel默认构造函数
void set (int64_t aslotms, int32_t aslotbit, wheel *anextround, wheel *alastround, time_wheel *atime_wheel)
 初始化时间轮配置
int slot_count ()
int slot_less ()
int64_t all_slot_ms ()
bool push_slots (wheel_node *anode)
 将定时器节点插入槽位
bool push (wheel_node *anode)
 尝试将定时器节点推入当前轮次
wheel_nodeshift_current_pos (int apos, wheel *awheel)
 处理指定槽位的定时器节点(重调度版本)
wheel_nodeshift_current_pos (wheel *awheel)
 推进时间轮当前位置并处理到期定时器

Friends

class time_wheel
struct time_wheel::impl_time_wheel

Detailed Description

时间轮轮次类

单层时间轮,包含固定数量的槽位,每个槽位存储定时器链表

Note
轮次之间通过m_nextround和m_lastround形成层级结构

Member Function Documentation

◆ push()

bool ngl::tools::wheel::push ( wheel_node * anode)
inline

尝试将定时器节点推入当前轮次

如果定时器时间范围超出当前轮次则拒绝

Parameters
anode定时器节点
Return values
true接受并插入
false时间范围超出,应尝试下一层轮次

◆ push_slots()

bool ngl::tools::wheel::push_slots ( wheel_node * anode)
inline

将定时器节点插入槽位

根据到期时间计算槽位索引,超范围则下推到上一层轮次

Parameters
anode定时器节点
Return values
true插入成功
false插入失败

◆ set()

void ngl::tools::wheel::set ( int64_t aslotms,
int32_t aslotbit,
wheel * anextround,
wheel * alastround,
time_wheel * atime_wheel )
inline

初始化时间轮配置

Parameters
aslotms每个槽位的时间跨度(毫秒)
aslotbit槽位数量的位数(槽位数 = 2^aslotbit)
anextround下一层级时间轮指针
alastround上一层级时间轮指针
atime_wheel所属time_wheel指针

◆ shift_current_pos() [1/2]

wheel_node * ngl::tools::wheel::shift_current_pos ( int apos,
wheel * awheel )
inline

处理指定槽位的定时器节点(重调度版本)

将槽位中的节点重新插入到目标轮次

Parameters
apos槽位索引
awheel目标轮次指针
Returns
nullptr(节点已重调度)

◆ shift_current_pos() [2/2]

wheel_node * ngl::tools::wheel::shift_current_pos ( wheel * awheel)
inline

推进时间轮当前位置并处理到期定时器

推进槽位指针,处理到期节点,处理重复定时器

Parameters
awheel目标轮次指针(用于重调度)
Returns
需要重新调度的定时器节点链表

The documentation for this class was generated from the following file: