00001 // scheduler.h 00002 // Data structures for the thread dispatcher and scheduler. 00003 // Primarily, the list of threads that are ready to run. 00004 // 00005 // Copyright (c) 1992-1996 The Regents of the University of California. 00006 // All rights reserved. See copyright.h for copyright notice and limitation 00007 // of liability and disclaimer of warranty provisions. 00008 00009 #ifndef SCHEDULER_H 00010 #define SCHEDULER_H 00011 00012 #include "copyright.h" 00013 #include "list.h" 00014 #include "thread.h" 00015 00016 // The following class defines the scheduler/dispatcher abstraction -- 00017 // the data structures and operations needed to keep track of which 00018 // thread is running, and which threads are ready but not running. 00019 00020 class Scheduler { 00021 public: 00022 Scheduler(); // Initialize list of ready threads 00023 ~Scheduler(); // De-allocate ready list 00024 00025 void ReadyToRun(Thread* thread); 00026 // Thread can be dispatched. 00027 Thread* FindNextToRun(); // Dequeue first thread on the ready 00028 // list, if any, and return thread. 00029 void Run(Thread* nextThread, bool finishing); 00030 // Cause nextThread to start running 00031 void CheckToBeDestroyed();// Check if thread that had been 00032 // running needs to be deleted 00033 void Print(); // Print contents of ready list 00034 00035 // SelfTest for scheduler is implemented in class Thread 00036 00037 private: 00038 List<Thread *> *readyList; // queue of threads that are ready to run, 00039 // but not running 00040 Thread *toBeDestroyed; // finishing thread to be destroyed 00041 // by the next thread that runs 00042 }; 00043 00044 #endif // SCHEDULER_H