Main Page   Compound List   File List   Compound Members   File Members  

Scheduler Class Reference

#include <scheduler.h>

List of all members.

Public Methods

 Scheduler ()
 ~Scheduler ()
void ReadyToRun (Thread *thread)
ThreadFindNextToRun ()
void Run (Thread *nextThread)
void Print ()

Private Attributes

ListreadyList


Constructor & Destructor Documentation

Scheduler::Scheduler  
 

Definition at line 30 of file scheduler.cc.

References readyList.

00031 { 
00032     readyList = new List; 
00033 } 

Scheduler::~Scheduler  
 

Definition at line 40 of file scheduler.cc.

References readyList.

00041 { 
00042     delete readyList; 
00043 } 


Member Function Documentation

Thread * Scheduler::FindNextToRun  
 

Definition at line 71 of file scheduler.cc.

References readyList, and List::Remove.

00072 {
00073     return (Thread *)readyList->Remove();
00074 }

void Scheduler::Print  
 

Definition at line 143 of file scheduler.cc.

References List::Mapcar, readyList, and VoidFunctionPtr.

00144 {
00145     printf("Ready list contents:\n");
00146     readyList->Mapcar((VoidFunctionPtr) ThreadPrint);
00147 }

void Scheduler::ReadyToRun Thread   thread
 

Definition at line 54 of file scheduler.cc.

References List::Append, DEBUG, Thread::getName, READY, readyList, and Thread::setStatus.

00055 {
00056     DEBUG('t', "Putting thread %s on ready list.\n", thread->getName());
00057 
00058     thread->setStatus(READY);
00059     readyList->Append((void *)thread);
00060 }

void Scheduler::Run Thread   nextThread
 

Definition at line 91 of file scheduler.cc.

References Thread::CheckOverflow, DEBUG, Thread::getName, NULL, RUNNING, Thread::setStatus, and SWITCH.

00092 {
00093     Thread *oldThread = currentThread;
00094     
00095 #ifdef USER_PROGRAM                     // ignore until running user programs 
00096     if (currentThread->space != NULL) { // if this thread is a user program,
00097         currentThread->SaveUserState(); // save the user's CPU registers
00098         currentThread->space->SaveState();
00099     }
00100 #endif
00101     
00102     oldThread->CheckOverflow();             // check if the old thread
00103                                             // had an undetected stack overflow
00104 
00105     currentThread = nextThread;             // switch to the next thread
00106     currentThread->setStatus(RUNNING);      // nextThread is now running
00107     
00108     DEBUG('t', "Switching from thread \"%s\" to thread \"%s\"\n",
00109           oldThread->getName(), nextThread->getName());
00110     
00111     // This is a machine-dependent assembly language routine defined 
00112     // in switch.s.  You may have to think
00113     // a bit to figure out what happens after this, both from the point
00114     // of view of the thread and from the perspective of the "outside world".
00115 
00116     SWITCH(oldThread, nextThread);
00117     
00118     DEBUG('t', "Now in thread \"%s\"\n", currentThread->getName());
00119 
00120     // If the old thread gave up the processor because it was finishing,
00121     // we need to delete its carcass.  Note we cannot delete the thread
00122     // before now (for example, in Thread::Finish()), because up to this
00123     // point, we were still running on the old thread's stack!
00124     if (threadToBeDestroyed != NULL) {
00125         delete threadToBeDestroyed;
00126         threadToBeDestroyed = NULL;
00127     }
00128     
00129 #ifdef USER_PROGRAM
00130     if (currentThread->space != NULL) {         // if there is an address space
00131         currentThread->RestoreUserState();     // to restore, do it.
00132         currentThread->space->RestoreState();
00133     }
00134 #endif
00135 }


Member Data Documentation

List* Scheduler::readyList [private]
 

Definition at line 32 of file scheduler.h.

Referenced by FindNextToRun, Print, ReadyToRun, Scheduler, and ~Scheduler.


The documentation for this class was generated from the following files:
Generated on Mon Feb 10 09:54:58 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees