src/c/scheduler.c
static void iot_schedule_enqueue (iot_schd_queue_t * queue, iot_schedule_t * schedule)
{
  /* Search for the correct schedule location */
  iot_schedule_t * next_schedule = NULL;
  iot_schedule_t * previous_schedule = NULL;
  iot_schedule_t * current_sched = queue->front;
  
  while (current_sched)
  {
    if (schedule->start < current_sched->start)
    {
      next_schedule = current_sched;
      previous_schedule = current_sched->previous;
      break;
    }
    else
    {
      previous_schedule = current_sched;
    }
    current_sched = current_sched->next;
  }

  /* Insert new schedule in correct location */
  if (queue->length == 0)
  {
    schedule->next = NULL;
    schedule->previous = NULL;
  }
  else
  {
    /* Set references in new entry */
    schedule->next = next_schedule;
    schedule->previous = previous_schedule;

    /* Update existing references, check if either is at the front or back */
    if (previous_schedule != NULL)
    {
      previous_schedule->next = schedule;
    }
    if (next_schedule != NULL)
    {
      next_schedule->previous = schedule;
    }
  }
  queue->length += 1;

  /* If no previous schedule, set as front */
  if (previous_schedule == NULL)
  {
    queue->front = schedule;
  }
}
/* Add a schedule to the queue */
Add a schedule to the queue
Add a schedule to the queue
static void iot_schedule_enqueue (iot_schd_queue_t * queue, iot_schedule_t * schedule)
{
  iot_schedule_t * next_schedule = NULL;
  iot_schedule_t * previous_schedule = NULL;
  iot_schedule_t * current_sched = queue->front;
  while (current_sched)
  {
    if (schedule->start < current_sched->start)
    {
      next_schedule = current_sched;
      previous_schedule = current_sched->previous;
      break;
    }
    else
    {
      previous_schedule = current_sched;
    }
    current_sched = current_sched->next;
  }
  if (queue->length == 0)
  {
    schedule->next = NULL;
    schedule->previous = NULL;
  }
  else
  {
    schedule->next = next_schedule;
    schedule->previous = previous_schedule;
    if (previous_schedule != NULL)
    {
      previous_schedule->next = schedule;
    }
    if (next_schedule != NULL)
    {
      next_schedule->previous = schedule;
    }
  }
  queue->length += 1;
  if (previous_schedule == NULL)
  {
    queue->front = schedule;
  }
}
static void iot_schedule_enqueue ( iot_schd_queue_t * queue , iot_schedule_t * schedule ) { iot_schedule_t * next_schedule = NULL ; iot_schedule_t * previous_schedule = NULL ; iot_schedule_t * current_sched = queue -> front ; while ( current_sched ) { if ( schedule -> start < current_sched -> start ) { next_schedule = current_sched ; previous_schedule = current_sched -> previous ; break ; } else { previous_schedule = current_sched ; } current_sched = current_sched -> next ; } if ( queue -> length == 0 ) { schedule -> next = NULL ; schedule -> previous = NULL ; } else { schedule -> next = next_schedule ; schedule -> previous = previous_schedule ; if ( previous_schedule != NULL ) { previous_schedule -> next = schedule ; } if ( next_schedule != NULL ) { next_schedule -> previous = schedule ; } } queue -> length += 1 ; if ( previous_schedule == NULL ) { queue -> front = schedule ; } }
Add a schedule to the queue
Add a schedule to the queue
/* Search for the correct schedule location */ /* Insert new schedule in correct location */ /* Set references in new entry */ /* Update existing references, check if either is at the front or back */ /* If no previous schedule, set as front */