Vogon Fleet: implementation: Added environment, concrete_environment, a
placeholder for the ready queue, needed by environment, and factorized stubs for tests in a separate directory. Updated makefile including environment, concrete_environment, ready_queue, but NOT the stubs and/or the tests. git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@685 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
36f62cbb8d
commit
53da6e4bb8
12
Makefile.am
12
Makefile.am
|
@ -144,12 +144,14 @@ src_backend_libbackend_la_LDFLAGS = \
|
||||||
|
|
||||||
# Please keep this in sorted order:
|
# Please keep this in sorted order:
|
||||||
src_backend_libbackend_la_SOURCES = \
|
src_backend_libbackend_la_SOURCES = \
|
||||||
|
src/backend/concrete_environment.cc \
|
||||||
src/backend/dynamic_process.cc \
|
src/backend/dynamic_process.cc \
|
||||||
src/backend/dynamic_request.cc \
|
src/backend/dynamic_request.cc \
|
||||||
src/backend/dynamic_resource.cc \
|
src/backend/dynamic_resource.cc \
|
||||||
src/backend/dynamic_schedulable.cc \
|
src/backend/dynamic_schedulable.cc \
|
||||||
src/backend/dynamic_sub_request.cc \
|
src/backend/dynamic_sub_request.cc \
|
||||||
src/backend/dynamic_thread.cc \
|
src/backend/dynamic_thread.cc \
|
||||||
|
src/backend/environment.cc \
|
||||||
src/backend/global_preferences.cc \
|
src/backend/global_preferences.cc \
|
||||||
src/backend/history.cc \
|
src/backend/history.cc \
|
||||||
src/backend/observed_subject.cc \
|
src/backend/observed_subject.cc \
|
||||||
|
@ -158,6 +160,7 @@ src_backend_libbackend_la_SOURCES = \
|
||||||
src/backend/policy_manager.cc \
|
src/backend/policy_manager.cc \
|
||||||
src/backend/policy_parameters.cc \
|
src/backend/policy_parameters.cc \
|
||||||
src/backend/process.cc \
|
src/backend/process.cc \
|
||||||
|
src/backend/ready_queue.cc \
|
||||||
src/backend/request.cc \
|
src/backend/request.cc \
|
||||||
src/backend/resource.cc \
|
src/backend/resource.cc \
|
||||||
src/backend/schedulable.cc \
|
src/backend/schedulable.cc \
|
||||||
|
@ -179,6 +182,7 @@ src_backend_libbackend_la_SOURCES = \
|
||||||
# For headers used internally by the backend, see below.
|
# For headers used internally by the backend, see below.
|
||||||
pkginclude_HEADERS += \
|
pkginclude_HEADERS += \
|
||||||
config.h \
|
config.h \
|
||||||
|
src/backend/environment.hh \
|
||||||
src/backend/global_preferences.hh \
|
src/backend/global_preferences.hh \
|
||||||
src/backend/history.hh \
|
src/backend/history.hh \
|
||||||
src/backend/observed_subject.hh \
|
src/backend/observed_subject.hh \
|
||||||
|
@ -187,6 +191,7 @@ pkginclude_HEADERS += \
|
||||||
src/backend/policy.hh \
|
src/backend/policy.hh \
|
||||||
src/backend/policy_manager.hh \
|
src/backend/policy_manager.hh \
|
||||||
src/backend/policy_parameters.hh \
|
src/backend/policy_parameters.hh \
|
||||||
|
src/backend/ready_queue.hh \
|
||||||
src/backend/request.hh \
|
src/backend/request.hh \
|
||||||
src/backend/resource.hh \
|
src/backend/resource.hh \
|
||||||
src/backend/process.hh \
|
src/backend/process.hh \
|
||||||
|
@ -201,6 +206,7 @@ pkginclude_HEADERS += \
|
||||||
# Put here headers used internally by the backend
|
# Put here headers used internally by the backend
|
||||||
# They won't be installed for the end-user.
|
# They won't be installed for the end-user.
|
||||||
noinst_HEADERS += \
|
noinst_HEADERS += \
|
||||||
|
src/backend/concrete_environment.hh \
|
||||||
src/backend/dynamic_process.hh \
|
src/backend/dynamic_process.hh \
|
||||||
src/backend/dynamic_request.hh \
|
src/backend/dynamic_request.hh \
|
||||||
src/backend/dynamic_resource.hh \
|
src/backend/dynamic_resource.hh \
|
||||||
|
@ -294,7 +300,7 @@ noinst_PROGRAMS = \
|
||||||
|
|
||||||
# disable :
|
# disable :
|
||||||
# src/testsuite/test-parse_command
|
# src/testsuite/test-parse_command
|
||||||
# src/testsuite/test-stepforward
|
# src/testsuite/test-stepforward
|
||||||
|
|
||||||
src_testsuite_test_history_CPPFLAGS = \
|
src_testsuite_test_history_CPPFLAGS = \
|
||||||
-I@top_srcdir@/src \
|
-I@top_srcdir@/src \
|
||||||
|
@ -328,6 +334,10 @@ src_testsuite_test_history_SOURCES = \
|
||||||
# src/backend/libbackend.la \
|
# src/backend/libbackend.la \
|
||||||
# $(GLIBMM_LIBS)
|
# $(GLIBMM_LIBS)
|
||||||
#src_testsuite_test_stepforward_SOURCES = \
|
#src_testsuite_test_stepforward_SOURCES = \
|
||||||
|
# src/testsuite/stubs/history.cc \
|
||||||
|
# src/testsuite/stubs/prrpolicy.cc \
|
||||||
|
# src/testsuite/stubs/policy_manager.cc \
|
||||||
|
# src/backend/scheduler.cc \
|
||||||
# src/testsuite/test-stepforward.cc
|
# src/testsuite/test-stepforward.cc
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,149 @@
|
||||||
|
// src/backend/resource.cc - 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
|
||||||
|
|
||||||
|
#include "concrete_environment.hh"
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
|
using namespace sgpem;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ConcreteEnvironment::ConcreteEnvironment()
|
||||||
|
{
|
||||||
|
// Nothing to do here. Really.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ConcreteEnvironment::ConcreteEnvironment(const ConcreteEnvironment & c) :
|
||||||
|
Environment(c), _sched_queue(c._sched_queue)
|
||||||
|
{
|
||||||
|
// DynamicRequest objects never change, so there is no need to keep
|
||||||
|
// a separate copy for each instant of the simulation, therefore
|
||||||
|
// we simply copy the map.
|
||||||
|
// Actually we may even avoid copiying the map, but this would not
|
||||||
|
// be worth the effort (too much code to change)
|
||||||
|
// Anyway, this causes much trouble when coming to destruction, see.
|
||||||
|
_resources = c._resources;
|
||||||
|
|
||||||
|
// DynamicProcess object need to be copied.
|
||||||
|
// The deep copy is guaranteed by the DynamicProcess copy constructor
|
||||||
|
std::vector<Process *>::const_iterator iter = c._processes.begin();
|
||||||
|
while (iter != c._processes.end())
|
||||||
|
{
|
||||||
|
DynamicProcess * current = dynamic_cast<DynamicProcess *>(*iter++);
|
||||||
|
_processes.push_back(new DynamicProcess(*current));
|
||||||
|
}
|
||||||
|
|
||||||
|
// The ready queue needs to be copied, too.
|
||||||
|
// This implementation relies on the copy constructor
|
||||||
|
// which is explicit in the initialization list
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const std::vector<Process *>
|
||||||
|
ConcreteEnvironment::get_processes() const
|
||||||
|
{
|
||||||
|
return _processes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<Process *>
|
||||||
|
ConcreteEnvironment::get_processes()
|
||||||
|
{
|
||||||
|
return _processes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const std::map<int, Resource *>
|
||||||
|
ConcreteEnvironment::get_resources() const
|
||||||
|
{
|
||||||
|
return _resources;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
std::map<int, Resource *>
|
||||||
|
ConcreteEnvironment::get_resources()
|
||||||
|
{
|
||||||
|
return _resources;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const std::vector<Request *>
|
||||||
|
ConcreteEnvironment::get_request_queue(Resource * resource) const
|
||||||
|
{
|
||||||
|
std::vector<Request *> request_queue;
|
||||||
|
// TODO: fill that vector, walking over the classes, looking for
|
||||||
|
// those no-more-valid requests.
|
||||||
|
return request_queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const ReadyQueue *
|
||||||
|
ConcreteEnvironment::get_sorted_queue() const
|
||||||
|
{
|
||||||
|
return &_sched_queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ReadyQueue *
|
||||||
|
ConcreteEnvironment::get_sorted_queue()
|
||||||
|
{
|
||||||
|
return &_sched_queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ConcreteEnvironment::~ConcreteEnvironment()
|
||||||
|
{
|
||||||
|
std::vector<Process *>::iterator iter = _processes.begin();
|
||||||
|
while (iter != _processes.end())
|
||||||
|
{
|
||||||
|
// This call will invoke the DynamicProcess virtual destructor
|
||||||
|
// Which will delete on cascade all DynamicThreads and so on.
|
||||||
|
delete *iter++;
|
||||||
|
// The iterator is still valid, since the pointed object is not,
|
||||||
|
// but the pointer is.
|
||||||
|
}
|
||||||
|
// After this, the destructor of _sched_queue is invoked
|
||||||
|
// After that, the destructor of _processes is invoked
|
||||||
|
// After that, the destructor of _resources is invoked
|
||||||
|
// The current implementation does not destroy the DynamicResource
|
||||||
|
// objects, as they are shared among all the DynamicEnvironment
|
||||||
|
// objects. This means that if none deletes them when deleting the
|
||||||
|
// last DynamicEnvironment object, we have a memory leak.
|
||||||
|
// And we do have one, since none by now cares for this. Maybe
|
||||||
|
// History will. Anyway, this is not nice, so please FIXME.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ConcreteEnvironment::serialize(SerializeVisitor& translator) const
|
||||||
|
{
|
||||||
|
// TODO: call something like translator.serializeEnvironment(this);
|
||||||
|
}
|
|
@ -0,0 +1,222 @@
|
||||||
|
// src/backend/resource.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 CONCRETE_ENVIRONMENT_HH
|
||||||
|
#define CONCRETE_ENVIRONMENT_HH 1
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "environment.hh"
|
||||||
|
#include "resource.hh"
|
||||||
|
#include "dynamic_process.hh"
|
||||||
|
#include "dynamic_request.hh"
|
||||||
|
#include "ready_queue.hh"
|
||||||
|
|
||||||
|
|
||||||
|
namespace sgpem
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class SerializeVisitor;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief An implementation of the Environment class
|
||||||
|
/// Class ConcreteEnvironment implements the Environment
|
||||||
|
/// abstract class.
|
||||||
|
///
|
||||||
|
/// This implementation actually contains the collections
|
||||||
|
/// of snapshots accessed by the function members defined
|
||||||
|
/// in the Environment class.
|
||||||
|
///
|
||||||
|
/// \see Environment
|
||||||
|
|
||||||
|
class ConcreteEnvironment : public Environment
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief Standard constructor.
|
||||||
|
/// Builds an empty environment.
|
||||||
|
|
||||||
|
ConcreteEnvironment();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief Copy constructor.
|
||||||
|
/// Performs a deep copy of all structures.
|
||||||
|
|
||||||
|
ConcreteEnvironment(const ConcreteEnvironment & c);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief Returns an indexed set of snapshots of the processes
|
||||||
|
/// Returns a standard vector of Process objects describing
|
||||||
|
/// all the processes of the simulated environment at the
|
||||||
|
/// considered instant.
|
||||||
|
///
|
||||||
|
/// The Process objects returned are actually DynamicProcess
|
||||||
|
/// objects. A downcast to DynamicProcess is guaranteed to be
|
||||||
|
/// always safe.
|
||||||
|
///
|
||||||
|
/// \return a constant set of snapshots of processes
|
||||||
|
|
||||||
|
virtual const std::vector<Process *>
|
||||||
|
get_processes() const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief Non-constant version of get_processes()
|
||||||
|
///
|
||||||
|
/// \return a set of snapshots of processes
|
||||||
|
/// \see get_processes()
|
||||||
|
|
||||||
|
virtual std::vector<Process *>
|
||||||
|
get_processes();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief Returns an indexed set of snapshots of the resources
|
||||||
|
/// Returns a standard map of \code int \endcode to Resource
|
||||||
|
/// objects describing the all resources of the simulated environment
|
||||||
|
/// at the considered instant.
|
||||||
|
///
|
||||||
|
/// The set is indexed in order to allow retreiving the requested
|
||||||
|
/// resource of a SubRequest object.
|
||||||
|
///
|
||||||
|
/// Future implementation may provide a cleaner implementation, i.e.
|
||||||
|
/// a \code get_request \endcode function member in the SubRequest
|
||||||
|
/// class which returns the Resource object indexed.
|
||||||
|
///
|
||||||
|
/// The Resource objects returned are actually DynamicResource
|
||||||
|
/// objects. A downcast to DynamicResource is guaranteed to be
|
||||||
|
/// always safe.
|
||||||
|
///
|
||||||
|
/// \return a indexed constant set of snapshot of resources.
|
||||||
|
/// \see DynamicSybrequest::get_resource()
|
||||||
|
|
||||||
|
virtual const std::map<int, Resource *>
|
||||||
|
get_resources() const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief Non-constant version of get_resources()
|
||||||
|
///
|
||||||
|
/// \return an indexed set of snapshots of resources
|
||||||
|
/// \see get_resources()
|
||||||
|
|
||||||
|
virtual std::map<int, Resource *>
|
||||||
|
get_resources();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief Returns a snapshot of the current request queue for a resource.
|
||||||
|
/// Returns a standard vector of Request objects
|
||||||
|
/// representing the queue of ready requests of threads which
|
||||||
|
/// are waiting for getting control of a limited-access resource.
|
||||||
|
///
|
||||||
|
/// The Request objects returned are actually DynamicRequest
|
||||||
|
/// objects. A downcast to DynamicRequest is guaranteed to be
|
||||||
|
/// always safe.
|
||||||
|
///
|
||||||
|
/// \param resource the resource the requests are for
|
||||||
|
/// \return the current ready requests queue.
|
||||||
|
|
||||||
|
virtual const std::vector<Request *>
|
||||||
|
get_request_queue(Resource * resource) const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief Returns a snapshot of the current scheduler's ready queue.
|
||||||
|
/// Returns a ReadyQueue object representing the queue
|
||||||
|
/// of ready processes or ready threads, depending on the
|
||||||
|
/// scheduling policy, which are waiting for getting control
|
||||||
|
/// of the CPU.
|
||||||
|
///
|
||||||
|
/// \return the current ready queue (constant).
|
||||||
|
|
||||||
|
virtual const ReadyQueue *
|
||||||
|
get_sorted_queue() const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief Non-constant version of get_sorted_queue()
|
||||||
|
///
|
||||||
|
/// \return the current ready queue.
|
||||||
|
/// \see get_sorted_queue()
|
||||||
|
|
||||||
|
virtual ReadyQueue *
|
||||||
|
get_sorted_queue();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief The standard virtual destructor.
|
||||||
|
/// The standard virtual destructor.
|
||||||
|
|
||||||
|
virtual
|
||||||
|
~ConcreteEnvironment();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief Serializes the whole environment.
|
||||||
|
/// \see SerializeVisitor
|
||||||
|
|
||||||
|
virtual void
|
||||||
|
serialize(SerializeVisitor& translator) const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief The container of all Resource objecs.
|
||||||
|
/// Actually contains only DynamicResource objects.
|
||||||
|
// resources come before processes because of
|
||||||
|
// destruction order. See destructor implementation
|
||||||
|
|
||||||
|
std::map<int, Resource *>
|
||||||
|
_resources;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief The container of all Process objecs.
|
||||||
|
/// Actually contains only DynamicProcess objects.
|
||||||
|
|
||||||
|
std::vector<Process *>
|
||||||
|
_processes;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief The queue of the ready schedulables
|
||||||
|
/// Does not contain the running process.
|
||||||
|
|
||||||
|
ReadyQueue
|
||||||
|
_sched_queue;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,28 @@
|
||||||
|
// src/backend/resource.cc - 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
|
||||||
|
|
||||||
|
#include "environment.hh"
|
||||||
|
|
||||||
|
using namespace sgpem;
|
||||||
|
|
||||||
|
|
||||||
|
Environment::~Environment()
|
||||||
|
{}
|
||||||
|
|
|
@ -0,0 +1,120 @@
|
||||||
|
// src/backend/resource.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 ENVIRONMENT_HH
|
||||||
|
#define ENVIRONMENT_HH 1
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
namespace sgpem
|
||||||
|
{
|
||||||
|
class ReadyQueue;
|
||||||
|
class Process;
|
||||||
|
class Request;
|
||||||
|
class Resource;
|
||||||
|
|
||||||
|
/// \brief An instant of the simulation.
|
||||||
|
/// An object of the Environment class represents a snapshot of
|
||||||
|
/// the simulated environment taken in a fixed instant, composed
|
||||||
|
/// by processes, threads, resources and more.
|
||||||
|
/// A snapshot for every single entity is accessible from here.
|
||||||
|
/// All the provided objects and data is constant.
|
||||||
|
///
|
||||||
|
/// Class History provides access to Environments for each instant
|
||||||
|
/// of the simulation.
|
||||||
|
///
|
||||||
|
/// Anyway, as well as the returned collections contain non-const
|
||||||
|
/// pointers, it will be possible to call non-const member functions
|
||||||
|
/// on these objects. This has no consequences until someone adds
|
||||||
|
/// non-const member functions to these classes.
|
||||||
|
///
|
||||||
|
/// This class is abstract: it provides the public interface to
|
||||||
|
/// read the content of an History.
|
||||||
|
/// \see History
|
||||||
|
|
||||||
|
class SG_DLLEXPORT Environment
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/// \brief Returns an indexed set of snapshots of the processes
|
||||||
|
/// Returns a standard vector of Process objects describing
|
||||||
|
/// all the processes of the simulated environment at the
|
||||||
|
/// considered instant.
|
||||||
|
///
|
||||||
|
/// \return a constant set of snapshots of processes
|
||||||
|
|
||||||
|
virtual std::vector<Process *> const
|
||||||
|
get_processes() const = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief Returns an indexed set of snapshots of the resources
|
||||||
|
/// Returns a standard map of \code int \endcode to Resource
|
||||||
|
/// objects describing the all resources of the simulated environment
|
||||||
|
/// at the considered instant.
|
||||||
|
///
|
||||||
|
/// The set is indexed in order to allow retreiving the requested
|
||||||
|
/// resource of a SubRequest object.
|
||||||
|
///
|
||||||
|
/// Future implementation may provide a cleaner implementation, i.e.
|
||||||
|
/// a \code get_request \endcode function member in the SubRequest
|
||||||
|
/// class which returns the Resource object indexed.
|
||||||
|
///
|
||||||
|
/// \return an indexed constant set of snapshot of resources.
|
||||||
|
|
||||||
|
virtual std::map<int, Resource *> const
|
||||||
|
get_resources() const = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief Returns a snapshot of the current request queue for a resource.
|
||||||
|
/// Returns a standard vector of Request objects
|
||||||
|
/// representing the queue of ready requests of threads which
|
||||||
|
/// are waiting for getting control of a limited-access resource.
|
||||||
|
/// \param resource the resource the requests are for
|
||||||
|
/// \return the current ready requests queue (constant).
|
||||||
|
|
||||||
|
virtual std::vector<Resource *> const
|
||||||
|
get_request_queue(const Resource * resource) const = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief Returns a snapshot of the current scheduler's ready queue.
|
||||||
|
/// Returns a ReadyQueue object representing the queue
|
||||||
|
/// of ready processes or ready threads, depending on the
|
||||||
|
/// scheduling policy, which are waiting for getting control
|
||||||
|
/// of the CPU.
|
||||||
|
/// \return the current ready queue (constant).
|
||||||
|
|
||||||
|
virtual const ReadyQueue *
|
||||||
|
get_sorted_queue() const = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/// \brief The standard virtual destructor.
|
||||||
|
/// The standard virtual destructor.
|
||||||
|
|
||||||
|
virtual
|
||||||
|
~Environment();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
// src/backend/resource.cc - 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
|
||||||
|
|
||||||
|
#include "ready_queue.hh"
|
||||||
|
|
||||||
|
using namespace sgpem;
|
||||||
|
|
||||||
|
ReadyQueue::~ReadyQueue()
|
||||||
|
{}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
// src/backend/resource.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 READY_QUEUE_HH
|
||||||
|
#define READY_QUEUE_HH 1
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "glibmm/ustring.h"
|
||||||
|
|
||||||
|
namespace sgpem
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
class SG_DLLEXPORT ReadyQueue
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual
|
||||||
|
~ReadyQueue();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
// src/testsuite/test-stepforward.cc - 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
|
||||||
|
|
||||||
|
|
||||||
|
#include "history.hh"
|
||||||
|
|
||||||
|
using namespace sgpem;
|
||||||
|
|
||||||
|
|
||||||
|
memory::smart_ptr<sgpem::DynamicSchedulable>
|
||||||
|
History::get_scheduled_at(int time) const
|
||||||
|
{
|
||||||
|
using namespace memory;
|
||||||
|
smart_ptr<DynamicSchedulable> scheduled_at = smart_ptr<DynamicSchedulable>();
|
||||||
|
if (0 <= time && time <= _total_time_elapsed)
|
||||||
|
{
|
||||||
|
smart_ptr<SchedulableQueue> sl = get_simulation_status_at(time);
|
||||||
|
bool found = false;
|
||||||
|
bool invalid = sl == smart_ptr<SchedulableQueue>();
|
||||||
|
for (uint i = 0; !found && !invalid && i < sl->size(); i++)
|
||||||
|
{
|
||||||
|
const DynamicSchedulable* ss = sl->get_item_at(i);
|
||||||
|
if ((bool)ss && ss->get_state() == DynamicSchedulable::state_running)
|
||||||
|
{
|
||||||
|
scheduled_at = smart_ptr<DynamicSchedulable>(new DynamicSchedulable(*(ss)));
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return scheduled_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
memory::smart_ptr<sgpem::SchedulableQueue>
|
||||||
|
History::get_simulation_status_at(int time) const
|
||||||
|
{
|
||||||
|
using namespace memory;
|
||||||
|
smart_ptr<SchedulableQueue> simulation_status_at = smart_ptr<SchedulableQueue>();
|
||||||
|
if (0 <= time && time <= _total_time_elapsed)
|
||||||
|
{
|
||||||
|
if (_slice == memory::smart_ptr<Slice>())
|
||||||
|
std::cout<<"History::get_simulation_status_at.NULL.error";
|
||||||
|
else
|
||||||
|
simulation_status_at = memory::smart_ptr<SchedulableQueue>
|
||||||
|
(
|
||||||
|
new SchedulableQueue
|
||||||
|
(
|
||||||
|
*(_slice->get_simulation_status())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return simulation_status_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
History::get_current_time() const
|
||||||
|
{
|
||||||
|
return _total_time_elapsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
History::enqueue_slice(const sgpem::SchedulableQueue& status)
|
||||||
|
{
|
||||||
|
_slice = memory::smart_ptr<Slice>(new Slice(_total_time_elapsed, 1, status));
|
||||||
|
_total_time_elapsed++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
History::truncate_at(int instant)
|
||||||
|
{
|
||||||
|
//std::cout << "\nRecreating a Singleton History";
|
||||||
|
_slice = memory::smart_ptr<Slice>();
|
||||||
|
_total_time_elapsed = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
History&
|
||||||
|
History::get_instance()
|
||||||
|
{
|
||||||
|
if (History::_instance == NULL)
|
||||||
|
History::_instance = new History();
|
||||||
|
return *History::_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
History::History()
|
||||||
|
{
|
||||||
|
_slice = memory::smart_ptr<Slice>();
|
||||||
|
_total_time_elapsed = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
History * History::_instance = NULL;
|
|
@ -0,0 +1,111 @@
|
||||||
|
// src/testsuite/test-stepforward.cc - 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 HISTORY_HH
|
||||||
|
#define HISTORY_HH 1
|
||||||
|
|
||||||
|
#include "backend/observed_subject.hh"
|
||||||
|
#include "backend/slice.hh"
|
||||||
|
#include "backend/schedulable_queue.hh"
|
||||||
|
#include "templates/smartp.tcc"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <glibmm/module.h> // ??
|
||||||
|
#include <cassert>
|
||||||
|
#include <string>
|
||||||
|
#include "config.h"
|
||||||
|
#include "gettext.h"
|
||||||
|
#include "glibmm/ustring.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "backend/static_process.hh"
|
||||||
|
|
||||||
|
|
||||||
|
#include "backend/dynamic_schedulable.hh"
|
||||||
|
|
||||||
|
#include "backend/user_interrupt_exception.hh"
|
||||||
|
#include "backend/policy.hh"
|
||||||
|
|
||||||
|
#include "prrpolicy.cc"
|
||||||
|
#include <iostream>
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace sgpem
|
||||||
|
{
|
||||||
|
|
||||||
|
/** an History stub, should only save the last state included.
|
||||||
|
*/
|
||||||
|
class History : public ObservedSubject
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
/** Returns the DynamicSchedulable of the schedulable
|
||||||
|
* which was running at the time, if any.
|
||||||
|
*/
|
||||||
|
memory::smart_ptr<sgpem::DynamicSchedulable>
|
||||||
|
get_scheduled_at(int time) const;
|
||||||
|
|
||||||
|
|
||||||
|
/** Returns the last recorded instant, but may raise an error.
|
||||||
|
*/
|
||||||
|
memory::smart_ptr<sgpem::SchedulableQueue>
|
||||||
|
get_simulation_status_at(int time) const;
|
||||||
|
|
||||||
|
|
||||||
|
/** Returns the total time recorded.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
get_current_time() const;
|
||||||
|
|
||||||
|
|
||||||
|
/** Extends the recorded history by one unit, overwriting the old value
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
enqueue_slice(const sgpem::SchedulableQueue& status);
|
||||||
|
|
||||||
|
|
||||||
|
/** STUB: THIS FEATURE IS NOT AVAILABLE
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
truncate_at(int instant);
|
||||||
|
|
||||||
|
|
||||||
|
/** Returns the singleton instance.
|
||||||
|
*/
|
||||||
|
static History&
|
||||||
|
get_instance();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
History();
|
||||||
|
|
||||||
|
static History * _instance;
|
||||||
|
int _total_time_elapsed;
|
||||||
|
memory::smart_ptr<Slice> _slice;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} //~ namespace sgpem
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,53 @@
|
||||||
|
// src/testsuite/test-stepforward.cc - 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
|
||||||
|
|
||||||
|
#include "policy_manager.hh"
|
||||||
|
|
||||||
|
using namespace sgpem;
|
||||||
|
|
||||||
|
PolicyManager::PolicyManager()
|
||||||
|
{}
|
||||||
|
|
||||||
|
PolicyManager&
|
||||||
|
PolicyManager::get_registered_manager()
|
||||||
|
{
|
||||||
|
if (_registered == NULL)
|
||||||
|
_registered = new PolicyManager();
|
||||||
|
return *_registered;
|
||||||
|
}
|
||||||
|
|
||||||
|
Policy&
|
||||||
|
PolicyManager::get_policy()
|
||||||
|
{
|
||||||
|
return PRRPolicy::get_instance();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PolicyManager::init()
|
||||||
|
{}
|
||||||
|
|
||||||
|
PolicyManager::~PolicyManager()
|
||||||
|
{
|
||||||
|
if(_registered == this) _registered = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PolicyManager*
|
||||||
|
PolicyManager::_registered = NULL;
|
|
@ -0,0 +1,73 @@
|
||||||
|
// src/testsuite/test-stepforward.cc - 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 POLICY_MANAGER_HH
|
||||||
|
#define POLICY_MANAGER_HH 1
|
||||||
|
|
||||||
|
#include "prrpolicy.hh"
|
||||||
|
/*
|
||||||
|
#include <glibmm/module.h> // ??
|
||||||
|
#include <cassert>
|
||||||
|
#include <string>
|
||||||
|
#include "config.h"
|
||||||
|
#include "gettext.h"
|
||||||
|
#include "glibmm/ustring.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
#include "backend/static_process.hh"
|
||||||
|
#include "backend/observed_subject.hh"
|
||||||
|
#include "backend/schedulable_queue.hh"
|
||||||
|
#include "backend/dynamic_schedulable.hh"
|
||||||
|
#include "templates/smartp.tcc"
|
||||||
|
#include "backend/user_interrupt_exception.hh"
|
||||||
|
#include "backend/policy.hh"
|
||||||
|
#include "backend/slice.hh"
|
||||||
|
#include "prrpolicy.cc"
|
||||||
|
#include <iostream>
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace sgpem
|
||||||
|
{
|
||||||
|
/** A policyManager stub, provides access to the PRRPolicy.
|
||||||
|
*/
|
||||||
|
class PolicyManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
PolicyManager();
|
||||||
|
|
||||||
|
static PolicyManager&
|
||||||
|
get_registered_manager();
|
||||||
|
|
||||||
|
virtual Policy&
|
||||||
|
get_policy();
|
||||||
|
|
||||||
|
virtual void
|
||||||
|
init();
|
||||||
|
|
||||||
|
virtual
|
||||||
|
~PolicyManager();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static PolicyManager* _registered;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,121 @@
|
||||||
|
// src/testsuite/test-stepforward.cc - 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
|
||||||
|
|
||||||
|
#include "prrpolicy.hh"
|
||||||
|
|
||||||
|
using namespace sgpem;
|
||||||
|
|
||||||
|
PRRPolicy::PRRPolicy()
|
||||||
|
{
|
||||||
|
_instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRRPolicy::PRRPolicy(int quantum)
|
||||||
|
: _quantum(quantum)
|
||||||
|
{
|
||||||
|
_instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Policy&
|
||||||
|
PRRPolicy::get_instance()
|
||||||
|
{
|
||||||
|
if(_instance == NULL) _instance = new PRRPolicy(3); // quantum size
|
||||||
|
return *_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PRRPolicy::~PRRPolicy()
|
||||||
|
{}
|
||||||
|
|
||||||
|
void
|
||||||
|
PRRPolicy::configure()
|
||||||
|
throw(UserInterruptException)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void
|
||||||
|
PRRPolicy::sort_queue() const
|
||||||
|
throw(UserInterruptException)
|
||||||
|
{
|
||||||
|
SchedulableQueue* local_sl = Scheduler::get_instance().get_ready_queue();
|
||||||
|
for (uint useless = 0; useless < local_sl->size(); useless++)
|
||||||
|
for (uint i = 0; i < local_sl->size() - 1; i++)
|
||||||
|
if
|
||||||
|
(
|
||||||
|
local_sl->get_item_at(i)->get_schedulable()->get_priority() >
|
||||||
|
local_sl->get_item_at(i + 1)->get_schedulable()->get_priority()
|
||||||
|
)
|
||||||
|
local_sl->swap(i, i + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PRRPolicy::activate()
|
||||||
|
{}
|
||||||
|
|
||||||
|
void
|
||||||
|
PRRPolicy::deactivate()
|
||||||
|
{}
|
||||||
|
|
||||||
|
int
|
||||||
|
PRRPolicy::get_id() const
|
||||||
|
{
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
|
||||||
|
sgpem::policy_sorts_type
|
||||||
|
PRRPolicy::wants() const
|
||||||
|
throw(UserInterruptException)
|
||||||
|
{
|
||||||
|
return policy_sorts_processes;
|
||||||
|
}
|
||||||
|
|
||||||
|
Glib::ustring
|
||||||
|
PRRPolicy::get_name() const
|
||||||
|
{
|
||||||
|
return "42";
|
||||||
|
}
|
||||||
|
|
||||||
|
Glib::ustring
|
||||||
|
PRRPolicy::get_description() const
|
||||||
|
{
|
||||||
|
return "42";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
PRRPolicy::is_pre_emptive() const
|
||||||
|
throw(UserInterruptException)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
PRRPolicy::get_time_slice() const
|
||||||
|
throw(UserInterruptException)
|
||||||
|
{
|
||||||
|
return _quantum;
|
||||||
|
}
|
||||||
|
|
||||||
|
PolicyParameters&
|
||||||
|
PRRPolicy::get_parameters()
|
||||||
|
{
|
||||||
|
return _parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
Policy*
|
||||||
|
PRRPolicy::_instance = NULL;
|
|
@ -0,0 +1,129 @@
|
||||||
|
// src/testsuite/test-stepforward.cc - 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 PRRPOLICY_HH
|
||||||
|
#define PRRPOLICY_HH 1
|
||||||
|
|
||||||
|
#include "backend/policy.hh"
|
||||||
|
#include "backend/user_interrupt_exception.hh"
|
||||||
|
#include "backend/schedulable_queue.hh"
|
||||||
|
#include "backend/scheduler.hh"
|
||||||
|
#include "glibmm/ustring.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <string>
|
||||||
|
#include "config.h"
|
||||||
|
#include "gettext.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
#include "backend/static_process.hh"
|
||||||
|
#include "backend/observed_subject.hh"
|
||||||
|
|
||||||
|
#include "backend/dynamic_schedulable.hh"
|
||||||
|
#include "templates/smartp.tcc"
|
||||||
|
#include "backend/user_interrupt_exception.hh"
|
||||||
|
|
||||||
|
#include "backend/slice.hh"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace sgpem
|
||||||
|
{
|
||||||
|
/** An hard-coded Priority Round Robin policy
|
||||||
|
* It's actually called PRRPolicy, altough my personal taste would have suggested
|
||||||
|
* naming it
|
||||||
|
* Prioriy-Reliant Roughly-Realized Recently-Reimplemented Round-Robin Policy,
|
||||||
|
* i.e. PRRRRRRR-Policy.
|
||||||
|
* it adds a new constructor taking the quantum size (time slice)
|
||||||
|
*/
|
||||||
|
class PRRPolicy : public Policy
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
PRRPolicy();
|
||||||
|
|
||||||
|
PRRPolicy(int quantum);
|
||||||
|
|
||||||
|
static Policy&
|
||||||
|
get_instance();
|
||||||
|
|
||||||
|
virtual
|
||||||
|
~PRRPolicy();
|
||||||
|
|
||||||
|
virtual void
|
||||||
|
configure()
|
||||||
|
throw(UserInterruptException);
|
||||||
|
|
||||||
|
virtual void
|
||||||
|
sort_queue() const
|
||||||
|
throw(UserInterruptException);
|
||||||
|
|
||||||
|
|
||||||
|
virtual void
|
||||||
|
activate();
|
||||||
|
|
||||||
|
virtual void
|
||||||
|
deactivate();
|
||||||
|
|
||||||
|
|
||||||
|
virtual int
|
||||||
|
get_id() const;
|
||||||
|
|
||||||
|
virtual sgpem::policy_sorts_type
|
||||||
|
wants() const
|
||||||
|
throw(UserInterruptException);
|
||||||
|
|
||||||
|
|
||||||
|
virtual Glib::ustring
|
||||||
|
get_name() const;
|
||||||
|
|
||||||
|
virtual Glib::ustring
|
||||||
|
get_description() const;
|
||||||
|
|
||||||
|
virtual bool
|
||||||
|
is_pre_emptive() const
|
||||||
|
throw(UserInterruptException);
|
||||||
|
|
||||||
|
virtual int
|
||||||
|
get_time_slice() const
|
||||||
|
throw(UserInterruptException);
|
||||||
|
|
||||||
|
|
||||||
|
virtual PolicyParameters&
|
||||||
|
get_parameters();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
PolicyParameters _parameters;
|
||||||
|
int _id;
|
||||||
|
int _quantum;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
static Policy* _instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue