Exemplo n.º 1
0
//----------------------------------------------------------------------
//
//	ProcessDestroy
//
//	Destroy a process by setting its status to zombie and putting it
//	on the zombie queue.  The next time the scheduler is called, this
//	process will be marked as free.  We can't necessarily do it now
//	because we might be the currently running process.
//
//	NOTE: This must only be called from an interrupt or trap.  However,
//	it need not be followed immediately by a ProcessSchedule() because
//	the process can continue running.
//
//----------------------------------------------------------------------
void
ProcessDestroy (PCB *pcb)
{
  dbprintf('p', "Entering ProcessDestroy for 0x%x.\n", pcb);
  ProcessSetStatus (pcb, PROCESS_STATUS_ZOMBIE);
  QueueRemove (&pcb->l);
  QueueInsertFirst (&zombieQueue, &pcb->l);
  dbprintf('p', "Leaving ProcessDestroy for 0x%x.\n", pcb);
}
//----------------------------------------------------------------------
//
//	ProcessModuleInit
//
//	Initialize the process module.  This involves initializing all
//	of the process control blocks to appropriate values (ie, free
//	and available).  We also need to initialize all of the queues.
//
//----------------------------------------------------------------------
void
ProcessModuleInit ()
{
  int		i;

  dbprintf ('p', "Entering ProcessModuleInit\n");
  QueueInit (&freepcbs);
  QueueInit (&runQueue);
  QueueInit (&waitQueue);
  QueueInit (&zombieQueue);
  for (i = 0; i < PROCESS_MAX_PROCS; i++) {
    dbprintf ('p', "Initializing PCB %d @ 0x%x.\n", i, &(pcbs[i]));
    pcbs[i].flags = PROCESS_STATUS_FREE;
    QueueLinkInit (&(pcbs[i].l), (void *)&pcbs[i]);
    QueueInsertFirst(&freepcbs, &(pcbs[i].l));
  }
  currentPCB = NULL;
  dbprintf ('p', "Leaving ProcessModuleInit\n");
}