sched/scheduler.c
/**************************************************************************
 * Name:
 *  sched_idle_task
 *
 * Description:
 *  This task is responsible for cleaning up resources used by the tasks
 *  and to put the board to sleep if CONFIG_BOARD_SLEEP is enabled.
 *  to be executed.
 *
 * Assumptions:
 *  This task should never exit.
 *
 *************************************************************************/


This task is responsible for cleaning up resources used by the tasks
and to put the board to sleep if CONFIG_BOARD_SLEEP is enabled.
to be executed.

This task should never exit.
This task is responsible for cleaning up resources used by the tasks and to put the board to sleep if CONFIG_BOARD_SLEEP is enabled . to be executed . This task should never exit .
static int sched_idle_task(int argc, char **argv)
{
  tcb_t *current_tcb;
  struct list_head *current, *temp;
  int fd;
  current_tcb = sched_get_current_task();
  SCHED_DEBUG_INFO("[%s] entry point\n", current_tcb->task_name);
  while (1)
  {
    irq_state_t irq_mask = cpu_disableint();
    list_for_each_safe(current, temp, &g_tcb_waiting_list)
    {
      if (current == NULL)
        continue;
      current_tcb = container_of(current, tcb_t, next_tcb);
      if (current_tcb == NULL ||
          current_tcb->t_state != HALTED)
      {
        continue;
      }
      SCHED_DEBUG_INFO("[idle_task] tear down task %s\n", current_tcb->task_name);
      list_del(current);
      for (fd = 0; fd < current_tcb->curr_resource_opened; fd++)
      {
        sched_free_resource(fd);
      }
      cpu_destroytask(current_tcb);
    }
    cpu_enableint(irq_mask);
    sched_run();
#ifdef CONFIG_BOARD_SLEEP
    board_entersleep();
#endif
  }
  return 0;
}
static int sched_idle_task ( int argc , char * * argv ) { tcb_t * current_tcb ; struct list_head * current , * temp ; int fd ; current_tcb = sched_get_current_task ( ) ; SCHED_DEBUG_INFO ( " \n " , current_tcb -> task_name ) ; while ( 1 ) { irq_state_t irq_mask = cpu_disableint ( ) ; list_for_each_safe ( current , temp , & g_tcb_waiting_list ) { if ( current == NULL ) continue ; current_tcb = container_of ( current , tcb_t , next_tcb ) ; if ( current_tcb == NULL || current_tcb -> t_state != HALTED ) { continue ; } SCHED_DEBUG_INFO ( " \n " , current_tcb -> task_name ) ; list_del ( current ) ; for ( fd = 0 ; fd < current_tcb -> curr_resource_opened ; fd ++ ) { sched_free_resource ( fd ) ; } cpu_destroytask ( current_tcb ) ; } cpu_enableint ( irq_mask ) ; sched_run ( ) ; #ifdef CONFIG_BOARD_SLEEP board_entersleep ( ) ; #endif } return 0 ; }
Name:
  sched_idle_task
Name : sched_idle_task
/* Check if we need to free any HALTED tasks */ /* Remove the task from the waiting list if it's in HALTED state */ /* Close the opened resources */ /* Tear down the task context */ /* Run the scheduler */ /* Put the board in sleep */