Ejemplo n.º 1
0
void TimerQueue::reset(std::vector<TimerQueue::Entry> expired, Timestamp  now)
{
	for (auto iter : expired)
	{
		ActiveTimer timer(iter.second, iter.second->sequeue());
		if (iter.second->repeat() && 
				cancleTimers_.find(timer) == cancleTimers_.end())
		{
			iter.second->restart(now);
			//timers_.insert(iter);
			//activeTimers_.insert(timer);
			insert(iter.second);
		}
		else
		{
			delete iter.second;
		}
	}

	Timestamp time;
	if (!timers_.empty())
	{
		time = timers_.begin()->second->expiration();
	}

	if (time.valid())
	{
		ext::resetTimerfd(timerfd_, time);
	}
}
Ejemplo n.º 2
0
void TimerQueue::reset(const std::vector<Entry>& expired, Timestamp now)
{
    Timestamp nextExpire;

    for (std::vector<Entry>::const_iterator it = expired.begin();
        it != expired.end(); it++)
    {
        ActiveTimer timer(it->second, it->second->sequence());
        if (it->second->repeat()
		&& cancelingTimers_.find(timer) == cancelingTimers_.end())
        {
            it->second->restart(now);
            insert(it->second);
        }
        else
        {
            delete it->second;
        }
    }

    if (!timers_.empty())
    {
        nextExpire = timers_.begin()->second->expiration();
    }
    
    if (nextExpire.valid())
    {
        resetTimerfd(timerfd_, nextExpire);
    }
}
Ejemplo n.º 3
0
void EventLoop::loop()
{
	assertInLoopThread();
    running_ = true;

    Timestamp now;
    while (running_)
    {
        activeChannels_.clear();

        int timeoutMs = 0;
        now = Timestamp::now();
        Timestamp nextExpired = timerQueue_->getNearestExpiration();
        if(nextExpired.valid())
        {
            
            double seconds = Timestamp::timeDiff(nextExpired, now);
            LOG_INFO("nextExpired.valid() [%s][%s][%lf]", nextExpired.toString().c_str(), now.toString().c_str(), seconds);
            if(seconds <= 0)
                timeoutMs = 0;
            else
                timeoutMs = seconds * 1000;
        }
        else
        {
        #if defined(POLL_WAIT_INDEFINITE)
            timeoutMs = -1;
        #else
            timeoutMs = 0;
        #endif
        }

        now = poller_->poll_once(timeoutMs, activeChannels_);
        //LOG_INFO("EventLoop::loop [%s][%d]", now.toString().c_str(), activeChannels_.size());

        eventHandling_ = true;
        for (ChannelList::iterator it = activeChannels_.begin(); it != activeChannels_.end(); ++it)
        {
            currentActiveChannel_ = *it;
            currentActiveChannel_->handleEvent(now);
        }
        currentActiveChannel_ = NULL;
        eventHandling_ = false;

        timerQueue_->runTimer(now);

        callPendingFunctors();    //处理poll等待过程中发生的事件
    }
}
Ejemplo n.º 4
0
void TimerQueue::reset(const vector<Entry> &expired,
			Timestamp now){
	Timestamp nextExpired;


	for (vector<Entry>::const_iterator it = expired.begin();
				it != expired.end();
				it++){
		if (it->second->ifRepeat()){
			it->second->restart(now);
			insert(it->second);
		}
		else{
			delete it->second;
		}
	}
	if (!timers.empty()){
		nextExpired = timers.begin()->second->getExpiration();

	}
	if (nextExpired.valid()){
		resetTimerFd(timeFd, nextExpired);
	}
}