// src/backend/scheduler.hh - Copyright 2005, 2006, University // of Padova, dept. of Pure and Applied // Mathematics // // This file is part of SGPEMv2. // // This is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // SGPEMv2 is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with SGPEMv2; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #ifndef SCHEDULER_HH #define SCHEDULER_HH 1 namespace sgpem { class Scheduler; class PolicyManager; class Policy; } #include "config.h" #include #include #include "observed_subject.hh" #include "history.hh" #include "schedulable_list.hh" namespace sgpem { class Scheduler; /** \brief Manages the SchedulableStatus objects, implementing a given policy. Class Scheduler manages the schedulable entities which are ready to run, ordering them in a queue; it also checks that the current scheduling policy is well-defined and does not disrupt the application inner mechanism. It is also responsible for the creation and the destruction of some of the SchedulableStatus objects (for further details about this, check class SchedulableStatus). */ class SG_DLLEXPORT Scheduler { public: /** The events that may cause the need for updating the scheduling queue and/or the running process. */ enum event { /** The arrival of a newly-created process. */ event_schedulable_arrival, /** The termination of the executing process. */ event_schedulable_termination, /** The end of the executing process' time quantum. */ event_end_time_slice }; /** \brief Returns the unique instance of this class, conforming to the Singleton pattern. * * If Scheduler isn't initialized, creates it. Should be called at least once before * starting the Simulation. * \return the unique instance of this class, conforming to the Singleton pattern. */ static Scheduler& get_instance(); /** Returns a pointer to the queue containing all the ready schedulable objects (for the policy to sort it). \return a pointer to the queue containing all the ready schedulable objects (for the policy to sort it). */ SchedulableList* get_ready_queue(); /** Resets the simulation to the initial state. */ void reset_status(); /** Generates a new SchedulableList representing the status of the processes at the simulation instant next to the current one, and extends the History by one instant with it. */ void step_forward(); /** Sets the policy that will be used to generate the simulation at the next instant. \param policy the policy that will be used to generate the simulation at the next instant. */ /* DISABLED until we don't have PolicyManager::set_policy() void set_policy(Policy* policy); */ /** Returns the policy that will be used to generate the simulation at the next instant. \return the policy that will be used to generate the simulation at the next instant. */ Policy& get_policy(); private: Scheduler(); //private constructor. static Scheduler* _instance; SchedulableList _ready_queue; PolicyManager& _policy_manager; }; }//~ namespace sgpem #endif //SCHEDULER_HH