/* XXX Handle timer rollover? */ void Scheduler::DequeueAndUpdateTimeout() { LOG_AM_TRACE("Entering function %s", __FUNCTION__); /* Nothing to do? Then return. A new timeout will be scheduled * the next time something is queued */ if (m_queue.empty() && (!m_localOffsetSet || m_localQueue.empty())) { LOG_AM_DEBUG("Not dequeuing any items as queue is now empty"); if (m_wakeScheduled) { CancelTimeout(); m_wakeScheduled = false; } return; } time_t curTime = time(NULL); LOG_AM_DEBUG("Beginning to dequeue items at time %llu", (unsigned long long)curTime); /* If anything on the queue already happened in the past, dequeue it * and mark it as Scheduled(). */ ProcessQueue(m_queue, curTime); /* Only process the local queue if the timezone offset is known. * Otherwise, wait, because it will be known shortly. */ if (m_localOffsetSet) { ProcessQueue(m_localQueue, curTime + m_localOffset); } LOG_AM_DEBUG("Done dequeuing items"); /* Both queues scheduled and dequeued (or unknown if time zone is not * yet known)? */ if (m_queue.empty() && (!m_localOffsetSet || m_localQueue.empty())) { LOG_AM_DEBUG("No unscheduled items remain"); if (m_wakeScheduled) { CancelTimeout(); m_wakeScheduled = false; } return; } time_t nextWakeup = GetNextStartTime(); if (!m_wakeScheduled || (nextWakeup != m_nextWakeup)) { UpdateTimeout(nextWakeup, curTime); m_nextWakeup = nextWakeup; m_wakeScheduled = true; } }
bool Schedule::operator<(const Schedule& rhs) const { return GetNextStartTime() < rhs.GetNextStartTime(); }