// scheduler.h // Data structures for the thread dispatcher and scheduler. // Primarily, the list of threads that are ready to run. // // Copyright (c) 1992-1993 The Regents of the University of California. // All rights reserved. See copyright.h for copyright notice and limitation // of liability and disclaimer of warranty provisions. // Modified 9/19/2005 by Jacob Lee and Soumi Sinha for CS423ug MP1. #ifndef SCHEDULER_H #define SCHEDULER_H #include "copyright.h" #include "list.h" #include "thread.h" #include "timer.h" #include "stats.h" #include "oneshot.h" enum SchedPolicy { SCHED_FCFS, SCHED_PRIO_P, SCHED_RR, SCHED_PRIO_RR }; // The following class defines the scheduler/dispatcher abstraction -- // the data structures and operations needed to keep track of which // thread is running, and which threads are ready but not running. class Scheduler { public: Scheduler(); // Initialize list of ready threads ~Scheduler(); // De-allocate ready list void ReadyToRun(Thread* thread); // Thread can be dispatched. Thread* FindNextToRun(); // Dequeue first thread on the ready // list, if any, and return thread. bool ShouldISwitch(Thread* oldThread, Thread* newThread); void Run(Thread* nextThread); // Cause nextThread to start running void Print(); // Print contents of ready list void Suspend(Thread *thread); void Resume(Thread *thread); void SetSchedPolicy(SchedPolicy pol); void SetNumOfQueues(int level); // set the number of queues for MLQ void InterruptHandler( int dummy ); SchedPolicy getPolicy(); private: SchedPolicy policy; // scheduling policy to be used List *readyList; // queue of threads that are ready to run, // but not running List *suspendedList; // List of suspended threads. //Timer * ptimer; // A timer, if needed. // We use a one-shot timer instead of a recurring timer. OneShot *ptimer; }; #endif // SCHEDULER_H