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
13 changed files with 1198 additions and 1 deletions
149
src/backend/concrete_environment.cc
Normal file
149
src/backend/concrete_environment.cc
Normal file
|
@ -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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue