定时器:
目前主流的定时器实现包括时间轮和最小堆,最后一战是用最小堆(优先队列)实现的定时器,下面先分析下其具体实现:
typedef std::function<void(int64_t, int64_t)> HeartbeatCallback;
typedef int64_t TimeKey;
class CBattleTimer
{
public:
CBattleTimer(void);
~CBattleTimer(void);
//服务器启动之初调用该函数初始化m_InitTime作为相对时间的对照标准
void SetInitTime(ptime& time){
m_InitTime = time;}
//添加定时器 参数:回调函数,定时时间,是否延续
int64_t AddTimer(HeartbeatCallback pHeartbeatCallback, int64_t interval, bool ifPersist<

最低0.47元/天 解锁文章
4099

被折叠的 条评论
为什么被折叠?



