// CPUScheduler.h Dave Reed // // CPUScheduler class /////////////////////////////////////////////////////////////////////////////// #ifndef _CPU_SCHEDULER_ #define _CPU_SCHEDULER_ #include #include #include "Job.h" #include "RandGen.h" using namespace std; const int TIME_SLICE = 10; // TIME SLICE DURATION FOR TIME SHARING const int LOAD_DELAY = 2; // SETUP TIME FOR A NEW JOB const int IO_MIN_DELAY = 5; // MINIMUM TIME TO SERVICE AN I/O REQUEST const int IO_MAX_DELAY = 10; // MAXIMUM TIME TO SERVICE AN I/O REQUEST class CPUScheduler { public: CPUScheduler(); bool JobsRemaining() const; // RETURNS TRUE IF JOBS IN EITHER QUEUE void AddNewJob(Job newJob, int time); // ADDS NEW JOB TO READY QUEUE void Execute(int time); // EXECUTES CURRENT JOB, UPDATES QUEUES private: class PriorityJob : Job // HIDDEN CLASS FOR PRIORITY QUEUE OF JOBS { public: PriorityJob(Job j, int pri) : Job(j) { priority = pri; } int GetPriority() const { return priority; } bool operator<(const PriorityJob & j) const { return priority > j.priority; } private: int priority; }; queue ReadyQueue; // JOBS READY TO EXECUTE priority_queue WaitQueue; // JOBS WAITING ON I/O int sliceTimeRemaining, loadTimeRemaining; // TIME REMAINING IN JOB SLICE, LOADING RandGen randomizer; // RANDOM # GENERATOR (FOR I/O DELAYS) }; #endif