balloonwj / flamingo

flamingo 一款高性能轻量级开源即时通讯软件

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TimerQueue中的doTimer()函数

huxingqun opened this issue · comments

`
void TimerQueue::doTimer()
{
loop_->assertInLoopThread();

Timestamp now(Timestamp::now());

for (auto iter = timers_.begin(); iter != timers_.end(); )
{
    //if (iter->first <= now)
    if (iter->second->expiration() <= now)
    {
        //LOGD("time: %lld", iter->second->expiration().microSecondsSinceEpoch());
        iter->second->run();
        if (iter->second->getRepeatCount() == 0)
        {
            iter = timers_.erase(iter);
        }
        else
        {
            ++iter;
        }
    }
    else
    {
        break;
    }           
}

`
在TimerQueue中的doTimer()函数中,最外层的else里面应该是continue而不是break吧

定时器对象是按过期时间从小到大排列,在循环中如果遇到一个定时器的过期时间已经比当前时间大了,还需要继续判断吗?所以是 break,而不是continue。 @huxingqun

哦,好的,是我疏忽了,忽略了这里存储timer的集合是set::set,谢谢 @balloonwj