next up previous contents
Next: EDF Scheduler Up: Scheduler API Previous: Example Schedulers   Contents

FIFO Scheduler

#define MAX_THREAD 10
struct tcb *sched_struct[MAX_THREAD];
int count=0;

oskit_u32_t reset_thread(struct tcb *arg)
{
  arg->status=THREAD_READY;
  return 1;
}

oskit_u32_t delete_thread(struct tcb *arg)
{
  arg->status=THREAD_EXITED;
  return 1;
}

oskit_u32_t set_mode(struct tcb* arg,oskit_u32_t mode)
{
  switch (mode)
  {
    case THREAD_BLOCKED:
      arg->status=THREAD_BLOCKED;
      break;
    case THREAD_SUSPENDED:
      arg->status=THREAD_SUSPENDED;
      break;
    case THREAD_READY:
      arg->status=THREAD_READY;
      break;
    case THREAD_EXITED:
      arg->status=THREAD_EXITED;
      break;
    default:
      break;
    }
  return 1;
}

oskit_u32_t new_thread(struct tcb* thid)
{
  if (count>=MAX_THREAD) return NULL;
  sched_struct[count]=thid;
  count++;
  thid->sched_field=count;/* Keep info about the next thread */
  thid->status=THREAD_READY;
  return 1;
}


struct tcb *heir_thread(struct tcb *curr)
{
  int i=(curr->sched_field)%count;
  int j=0;
  if  (curr->status==THREAD_ON_CPU)
    curr->status=THREAD_READY;
  while (j<count)
    {
      if ((sched_struct[i]->status==THREAD_READY))
        {
          sched_struct[i]->status=THREAD_ON_CPU;
          return sched_struct[i];
          
        }
      i=(i+1)%count;
      ++j;
    }
    return NULL;
}

oskit_u32_t init(struct tcb *main_tcb)
{
  new_thread(main_tcb);
  main_tcb->status=THREAD_ON_CPU;
  return 1;
}


Soumyadeb Mitra 2002-08-07