示例#1
0
/**
 * ProcessQueue is called whenever there is a timer interrupt.
 * We need to wake up and process the current top item in the timer queue as
 * long
 * as its scheduled time is after the current time. Then the item is removed or
 * rescheduled (repetitive events) in the queue.
 */
void Notifier::ProcessQueue(uint32_t currentTimeInt, void *params) {
  Notifier *current;
  while (true)  // keep processing past events until no more
  {
    {
      std::lock_guard<priority_recursive_mutex> sync(queueMutex);
      double currentTime = currentTimeInt * 1.0e-6;
      current = timerQueueHead;
      if (current == nullptr || current->m_expirationTime > currentTime) {
        break;  // no more timer events to process
      }
      // need to process this entry
      timerQueueHead = current->m_nextEvent;
      if (current->m_periodic) {
        // if periodic, requeue the event
        // compute when to put into queue
        current->InsertInQueue(true);
      } else {
        // not periodic; removed from queue
        current->m_queued = false;
      }
      // Take handler mutex while holding queue mutex to make sure
      //  the handler will execute to completion in case we are being deleted.
      current->m_handlerMutex.lock();
    }

    current->m_handler(current->m_param);  // call the event handler
    current->m_handlerMutex.unlock();
  }
  // reschedule the first item in the queue
  std::lock_guard<priority_recursive_mutex> sync(queueMutex);
  UpdateAlarm();
}
示例#2
0
/**
 * ProcessQueue is called whenever there is a timer interrupt.
 * We need to wake up and process the current top item in the timer queue as long
 * as its scheduled time is after the current time. Then the item is removed or 
 * rescheduled (repetitive events) in the queue.
 */
void Notifier::ProcessQueue(tNIRIO_u32 mask, void *params)
{
    Notifier *current;
    while (1)                   // keep processing past events until no more
    {
        CRITICAL_REGION(m_semaphore)
        {
            double currentTime = GetClock();
            current = timerQueueHead;
            if (current == NULL || current->m_expirationTime > currentTime)
            {
                break;          // no more timer events to process
            }
            // need to process this entry
            timerQueueHead = current->m_nextEvent;
            if (current->m_periodic)
            {
                // if periodic, requeue the event
                // compute when to put into queue
                current->InsertInQueue(false);
            }
        }
        END_REGION;

        current->m_handler(current->m_param);   // call the event handler
    }
    // reschedule the first item in the queue
    CRITICAL_REGION(m_semaphore)
    {
        UpdateAlarm();
    }
    END_REGION;
}
示例#3
0
/**
 * ProcessQueue is called whenever there is a timer interrupt.
 * We need to wake up and process the current top item in the timer queue as long
 * as its scheduled time is after the current time. Then the item is removed or
 * rescheduled (repetitive events) in the queue.
 */
void Notifier::ProcessQueue(uint32_t mask, void *params)
{
	Notifier *current;
	while (true)				// keep processing past events until no more
	{
		{
			std::lock_guard<priority_recursive_mutex> sync(queueMutex);
			double currentTime = GetClock();

			if (timerQueue.empty())
			{
				break;
			}
			current = timerQueue.front();
			if (current->m_expirationTime > currentTime)
			{
				break;		// no more timer events to process
			}
			// remove next entry before processing it
			timerQueue.pop_front();

			current->m_queued = false;
			if (current->m_periodic)
			{
				// if periodic, requeue the event
				// compute when to put into queue
				current->InsertInQueue(true);
			}
			else
			{
				// not periodic; removed from queue
				current->m_queued = false;
			}
			// Take handler mutex while holding queue semaphore to make sure
			//  the handler will execute to completion in case we are being deleted.
			current->m_handlerMutex.lock();
		}

		current->m_handler();	// call the event handler
		current->m_handlerMutex.unlock();
	}
	// reschedule the first item in the queue
	std::lock_guard<priority_recursive_mutex> sync(queueMutex);
	UpdateAlarm();
}
示例#4
0
/**
 * ProcessQueue is called whenever there is a timer interrupt.
 * We need to wake up and process the current top item in the timer queue as long
 * as its scheduled time is after the current time. Then the item is removed or 
 * rescheduled (repetitive events) in the queue.
 */
void Notifier::ProcessQueue(uint32_t mask, void *params)
{
    Notifier *current;
    while (true)                // keep processing past events until no more
    {
        {
            Synchronized sync(queueSemaphore);
            double currentTime = GetClock();
            current = timerQueueHead;
            if (current == NULL || current->m_expirationTime > currentTime)
            {
                break;        // no more timer events to process
            }
            // need to process this entry
            timerQueueHead = current->m_nextEvent;
            if (current->m_periodic)
            {
                // if periodic, requeue the event
                // compute when to put into queue
                current->InsertInQueue(true);
            }
            else
            {
                // not periodic; removed from queue
                current->m_queued = false;
            }
            // Take handler semaphore while holding queue semaphore to make sure
            //  the handler will execute to completion in case we are being deleted.
            semTake(current->m_handlerSemaphore, WAIT_FOREVER);
        }

        current->m_handler(current->m_param);    // call the event handler
        semGive(current->m_handlerSemaphore);
    }
    // reschedule the first item in the queue
    Synchronized sync(queueSemaphore);
    UpdateAlarm();
}