- added scheduler and other incomplete backend classes
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@319 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
98cc6fb20b
commit
e2a0c3f248
|
@ -51,6 +51,7 @@ sgpemv2_SOURCES = \
|
||||||
graphical_terminal_io.cc \
|
graphical_terminal_io.cc \
|
||||||
main.cc \
|
main.cc \
|
||||||
main_window.cc \
|
main_window.cc \
|
||||||
|
observer.cc \
|
||||||
parse_opts.cc \
|
parse_opts.cc \
|
||||||
start_gui.cc
|
start_gui.cc
|
||||||
|
|
||||||
|
|
|
@ -49,18 +49,24 @@ libbackend_la_LDFLAGS = $(PYTHON_EXTRA_LDFLAGS) \
|
||||||
libbackend_la_SOURCES = \
|
libbackend_la_SOURCES = \
|
||||||
history.cc \
|
history.cc \
|
||||||
observed_subject.cc \
|
observed_subject.cc \
|
||||||
|
policy.cc \
|
||||||
|
policy_parameters.cc \
|
||||||
process.cc \
|
process.cc \
|
||||||
schedulable.cc \
|
schedulable.cc \
|
||||||
|
schedulable_list.cc \
|
||||||
schedulable_status.cc \
|
schedulable_status.cc \
|
||||||
simulation_status.cc \
|
scheduler.cc \
|
||||||
slice.cc
|
slice.cc
|
||||||
|
|
||||||
|
|
||||||
noinst_HEADERS = \
|
noinst_HEADERS = \
|
||||||
history.hh \
|
history.hh \
|
||||||
observed_subject.hh \
|
observed_subject.hh \
|
||||||
|
policy.hh \
|
||||||
|
policy_parameters.hh \
|
||||||
process.hh \
|
process.hh \
|
||||||
schedulable.hh \
|
schedulable.hh \
|
||||||
|
schedulable_list.hh \
|
||||||
schedulable_status.hh \
|
schedulable_status.hh \
|
||||||
simulation_status.hh \
|
scheduler.hh \
|
||||||
slice.hh
|
slice.hh
|
||||||
|
|
|
@ -26,56 +26,66 @@ using namespace memory;
|
||||||
//History::instance; //static object
|
//History::instance; //static object
|
||||||
History History::_instance(10); //dummy parameter
|
History History::_instance(10); //dummy parameter
|
||||||
|
|
||||||
|
/**
|
||||||
|
The constructor sets _total_time_elapsed to -1: this permits to insert the INITIAL STATUS
|
||||||
|
of the simulation which must begin at instant -1 and live for 1 instant.
|
||||||
|
*/
|
||||||
History::History(int) //private constructor. The parameter is discarded
|
History::History(int) //private constructor. The parameter is discarded
|
||||||
:_total_time_elapsed(0)
|
:_total_time_elapsed(-1)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
History&
|
History&
|
||||||
History::getInstance()
|
History::get_instance()
|
||||||
{
|
{
|
||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/**
|
||||||
Returns a pointer to a copy of the SchedulableStatus object relative to this instant.
|
Returns a pointer to a copy of the SchedulableStatus object relative to this instant.
|
||||||
It can be NULL if time is out of range or if the SimulationStatus object relative to
|
It can be NULL if time is out of range or if there are no running entities in the associated
|
||||||
this instant has no running entities.
|
SchedulableList
|
||||||
*/
|
*/
|
||||||
smart_ptr<const SchedulableStatus>
|
smart_ptr<const SchedulableStatus>
|
||||||
History::get_scheduled_at(int time)
|
History::get_scheduled_at(int time) const
|
||||||
{
|
{
|
||||||
if (time >= _total_time_elapsed || time < 0) //out of range
|
if (time >= _total_time_elapsed || time < 0) //out of range
|
||||||
return smart_ptr<const SchedulableStatus>(NULL);
|
return smart_ptr<const SchedulableStatus>(NULL);
|
||||||
|
|
||||||
return get_simulation_status_at(time)->get_running();
|
//look for a runing entity
|
||||||
|
smart_ptr<const SchedulableList> p = get_simulation_status_at(time);
|
||||||
|
|
||||||
|
for (int i = 0; i < p->size(); i++)
|
||||||
|
if (p->get_item_at(i)->get_state() == SchedulableStatus::state_running)
|
||||||
|
return smart_ptr<const SchedulableStatus>(new SchedulableStatus(*(p->get_item_at(i))));
|
||||||
|
|
||||||
|
return smart_ptr<const SchedulableStatus>(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns a pointer to a copy of the SimulationStatus object relative to this instant or NULL
|
Returns a pointer to a copy of the SimulationStatus object relative to this instant or NULL
|
||||||
if time is out of range.
|
if time is out of range.
|
||||||
*/
|
*/
|
||||||
smart_ptr<const SimulationStatus>
|
smart_ptr<const SchedulableList>
|
||||||
History::get_simulation_status_at(int time)
|
History::get_simulation_status_at(int time) const
|
||||||
{
|
{
|
||||||
if (time >= _total_time_elapsed || time < 0) //out of range
|
if (time > _total_time_elapsed || time < 0) //out of range
|
||||||
return smart_ptr<const SimulationStatus>(NULL);
|
return smart_ptr<const SchedulableList>(NULL);
|
||||||
|
|
||||||
int trascorso = 0;
|
int trascorso = -1;
|
||||||
for(vector<Slice>::iterator i=_slices.begin(); i < _slices.end(); i++)
|
for(vector<Slice>::const_iterator i=_slices.begin(); i < _slices.end(); i++)
|
||||||
if (time < trascorso + i->get_duration()) //FOUND!!
|
if (time <= trascorso + i->get_duration()) //FOUND!!
|
||||||
return smart_ptr<const SimulationStatus>(new SimulationStatus(i->get_simulation_status()));
|
return smart_ptr<const SchedulableList>(new SchedulableList(*i->get_simulation_status()));
|
||||||
else //Go on...
|
else //Go on...
|
||||||
trascorso += i->get_duration();
|
trascorso += i->get_duration();
|
||||||
|
|
||||||
//never reached
|
//never reached if all slices are CONTIGUOUS (ans THIS shoul be!!)!!!
|
||||||
return smart_ptr<const SimulationStatus>(NULL);
|
return smart_ptr<const SchedulableList>(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
History::get_current_time()
|
History::get_current_time() const
|
||||||
{
|
{
|
||||||
return _total_time_elapsed;
|
return _total_time_elapsed;
|
||||||
}
|
}
|
||||||
|
@ -85,10 +95,11 @@ History::get_current_time()
|
||||||
Calls the method notify() in quality of ObservedSubject, updating all observers.
|
Calls the method notify() in quality of ObservedSubject, updating all observers.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
History::enqueue_slice(SimulationStatus status)
|
History::enqueue_slice(const SchedulableList& status)
|
||||||
{
|
{
|
||||||
if(_slices.size() == 0){
|
if(_slices.size() == 0)
|
||||||
_slices.push_back(Slice(0, 1, status));
|
{
|
||||||
|
_slices.push_back(Slice(-1, 1, status));
|
||||||
_total_time_elapsed = 1;
|
_total_time_elapsed = 1;
|
||||||
notify();
|
notify();
|
||||||
return;
|
return;
|
||||||
|
@ -96,7 +107,7 @@ History::enqueue_slice(SimulationStatus status)
|
||||||
|
|
||||||
//check the last slice
|
//check the last slice
|
||||||
Slice& last = _slices[_slices.size()-1];
|
Slice& last = _slices[_slices.size()-1];
|
||||||
if (last.get_simulation_status() == status) //increments the duration by ONE unit
|
if (last.get_simulation_status()->has_same_objects(status)) //increments the duration by ONE unit
|
||||||
{
|
{
|
||||||
last.set_duration(last.get_duration()+1);
|
last.set_duration(last.get_duration()+1);
|
||||||
}
|
}
|
||||||
|
@ -110,17 +121,25 @@ History::enqueue_slice(SimulationStatus status)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Removes all the informations about the simulation following the specified instant.
|
Removes all the informations about the simulation following the specified instant.
|
||||||
|
|
||||||
|
Ex. truncate_at(0); removes all scheduled slices
|
||||||
|
Ex. truncate_at(-1); removes all scheduled slices and the initial status
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
History::truncate_at(int instant)
|
History::truncate_at(int instant)
|
||||||
{
|
{
|
||||||
//reach the instant
|
|
||||||
vector<Slice>::iterator i = _slices.begin();
|
vector<Slice>::iterator i = _slices.begin();
|
||||||
for (int k=0; k < instant; k++)
|
//reach the instant
|
||||||
|
while (i != _slices.end())
|
||||||
|
if (i->get_started_at() < instant)
|
||||||
i++;
|
i++;
|
||||||
|
else
|
||||||
|
{
|
||||||
//replaces the current vector with the "trimmed" one.
|
//replaces the current vector with the "trimmed" one.
|
||||||
_slices = vector<Slice>(_slices.begin(),i);
|
_slices = vector<Slice>(_slices.begin(),i);
|
||||||
_total_time_elapsed = instant;
|
_total_time_elapsed = instant;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
#include "slice.hh"
|
#include "slice.hh"
|
||||||
#include "observed_subject.hh"
|
#include "observed_subject.hh"
|
||||||
#include "simulation_status.hh"
|
#include "schedulable_list.hh"
|
||||||
#include "schedulable_status.hh"
|
#include "schedulable_status.hh"
|
||||||
#include "../templates/smartp.hh"
|
#include "../templates/smartp.hh"
|
||||||
|
|
||||||
|
@ -47,16 +47,17 @@ namespace sgpem
|
||||||
*/
|
*/
|
||||||
class History;
|
class History;
|
||||||
|
|
||||||
class SG_DLLEXPORT History : public ObservedSubject {
|
class SG_DLLEXPORT History : public ObservedSubject
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
memory::smart_ptr<const sgpem::SchedulableStatus> get_scheduled_at(int time);
|
memory::smart_ptr<const sgpem::SchedulableStatus> get_scheduled_at(int time) const;
|
||||||
memory::smart_ptr<const sgpem::SimulationStatus> get_simulation_status_at(int time);
|
memory::smart_ptr<const sgpem::SchedulableList> get_simulation_status_at(int time) const;
|
||||||
int get_current_time();
|
int get_current_time() const;
|
||||||
void enqueue_slice(sgpem::SimulationStatus status);
|
void enqueue_slice(const sgpem::SchedulableList& status);
|
||||||
void truncate_at(int instant);
|
void truncate_at(int instant);
|
||||||
|
|
||||||
static History& getInstance();
|
static History& get_instance();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
History(int); //private constructor. The parameter is discarded
|
History(int); //private constructor. The parameter is discarded
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
// src/backend/policy.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.hh"
|
||||||
|
using namespace std;
|
||||||
|
using namespace sgpem;
|
||||||
|
using namespace memory;
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
// src/backend/policy.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 POLICY_HH
|
||||||
|
#define POLICY_HH 1
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "scheduler.hh"
|
||||||
|
|
||||||
|
namespace sgpem
|
||||||
|
{
|
||||||
|
|
||||||
|
class Policy;
|
||||||
|
|
||||||
|
/** \brief
|
||||||
|
e' una Strategy che rappresenta un algoritmo di scheduling che implementa una politica
|
||||||
|
di scheduling.
|
||||||
|
*/
|
||||||
|
class SG_DLLEXPORT Policy
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void sort_queue(sgpem::Scheduler::event) {}
|
||||||
|
bool is_pre_emptive() {return true;}
|
||||||
|
int get_time_slice() {return 2;}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}//~ namespace sgpem
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,25 @@
|
||||||
|
// src/backend/policy_parameters.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_parameters.hh"
|
||||||
|
using namespace std;
|
||||||
|
using namespace sgpem;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
// src/backend/policy_parameters.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 POLICY_PARAMETERS_HH
|
||||||
|
#define POLICY_PARAMETERS_HH 1
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace sgpem
|
||||||
|
{
|
||||||
|
|
||||||
|
class PolicyParameters;
|
||||||
|
|
||||||
|
/** \brief
|
||||||
|
|
||||||
|
*/
|
||||||
|
class SG_DLLEXPORT PolicyParameters
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template<typename T>
|
||||||
|
class Parameter;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class PolicyParameters::Parameter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}//~ namespace sgpem
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,200 @@
|
||||||
|
// src/frontend/schedulable_list.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 "schedulable_list.hh"
|
||||||
|
|
||||||
|
using namespace sgpem;
|
||||||
|
using namespace std;
|
||||||
|
using namespace memory;
|
||||||
|
|
||||||
|
|
||||||
|
SchedulableList::SchedulableList()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a pointer to the first element. If the queue is empty the NULL pointer will
|
||||||
|
be returned.
|
||||||
|
|
||||||
|
DON'T call delete on the returned pointer! Its destruction is managed by the queue.
|
||||||
|
*/
|
||||||
|
|
||||||
|
SchedulableStatus*
|
||||||
|
SchedulableList::top()
|
||||||
|
{
|
||||||
|
if (_list.size() == 0)
|
||||||
|
return NULL;
|
||||||
|
return &_list.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a pointer to the last element. If the queue is empty the NULL pointer will
|
||||||
|
be returned.
|
||||||
|
|
||||||
|
DON'T call delete on the returned pointer! Its destruction is managed by the queue.
|
||||||
|
*/
|
||||||
|
|
||||||
|
SchedulableStatus*
|
||||||
|
SchedulableList::bottom()
|
||||||
|
{
|
||||||
|
if (_list.size() == 0)
|
||||||
|
return NULL;
|
||||||
|
return &_list.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a pointer to the element at position "where". If the queue is empty or "where" is
|
||||||
|
out of rangethe NULL pointer will be returned.
|
||||||
|
|
||||||
|
DON'T call delete on the returned pointer! Its destruction is managed by the queue.
|
||||||
|
*/
|
||||||
|
SchedulableStatus*
|
||||||
|
SchedulableList::get_item_at(const uint& where)
|
||||||
|
{
|
||||||
|
if (_list.size() == 0 || where >= _list.size())
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
list<SchedulableStatus>::iterator i = _list.begin();
|
||||||
|
for (uint f=0; f < where; f++)
|
||||||
|
i++;
|
||||||
|
return &(*i);
|
||||||
|
}
|
||||||
|
|
||||||
|
const SchedulableStatus*
|
||||||
|
SchedulableList::get_item_at(const uint& where) const
|
||||||
|
{
|
||||||
|
if (_list.size() == 0 || where >= _list.size())
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
list<SchedulableStatus>::const_iterator i = _list.begin();
|
||||||
|
for (uint f=0; f < where; f++)
|
||||||
|
i++;
|
||||||
|
return &(*i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the number of elements inserted into the queue.
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint
|
||||||
|
SchedulableList::size() const
|
||||||
|
{
|
||||||
|
return _list.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SchedulableList::add_at_bottom(const SchedulableStatus& ss)
|
||||||
|
{
|
||||||
|
_list.push_back(ss);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SchedulableList::add_at_top(const SchedulableStatus& ss)
|
||||||
|
{
|
||||||
|
_list.push_front(ss);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Removes an element from the list. Returns a smart pointer a copy of it or to NULL if
|
||||||
|
"position" is out of range.
|
||||||
|
|
||||||
|
Ex. remove(0); removes the top of the list
|
||||||
|
Ex. remove(size()-1) removes the bottom of the list
|
||||||
|
*/
|
||||||
|
smart_ptr<SchedulableStatus>
|
||||||
|
SchedulableList::remove(const uint& position)
|
||||||
|
{
|
||||||
|
if (_list.size() == 0 || position >= _list.size())
|
||||||
|
return smart_ptr<SchedulableStatus>(NULL);
|
||||||
|
|
||||||
|
//creates a copy of the first element
|
||||||
|
smart_ptr<SchedulableStatus> sm = new SchedulableStatus(*top());
|
||||||
|
//pops the first element
|
||||||
|
_list.pop_front();
|
||||||
|
//returns the copy
|
||||||
|
return sm;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Switches two elements in the queue. Returns FALSE if one of the indexes is out of range.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
SchedulableList::insert_at(const uint& which, const uint& where)
|
||||||
|
{
|
||||||
|
//out of range
|
||||||
|
if (which >= _list.size() || where >= _list.size())
|
||||||
|
return false;
|
||||||
|
//nothing to do
|
||||||
|
if (where == which)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
list<SchedulableStatus>::iterator i_where = _list.begin();
|
||||||
|
list<SchedulableStatus>::iterator i_which = _list.begin();
|
||||||
|
for (uint f=0; f < where; f++)
|
||||||
|
i_where++;
|
||||||
|
for (uint f=0; f < which; f++)
|
||||||
|
i_which++;
|
||||||
|
|
||||||
|
//save the one to replace
|
||||||
|
SchedulableStatus temp = *i_where;
|
||||||
|
//replace them
|
||||||
|
*i_where = *i_which;
|
||||||
|
*i_which = temp;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
Removes all elements
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
SchedulableList::clear()
|
||||||
|
{
|
||||||
|
_list.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Returns TRUE if the two objects have the same SchedulableStatus objects in the same order.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
SchedulableList::operator==(const SchedulableList& dx) const
|
||||||
|
{
|
||||||
|
return _list == dx._list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Returns TRUE if the two objects have the same SchedulableStatus objects with NO ORDER IMPORTANCE.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
SchedulableList::has_same_objects(const SchedulableList& dx) const
|
||||||
|
{
|
||||||
|
if (_list.size() != dx._list.size())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
//check if dx has ALL and ONLY the elements holded by _list with no order importance
|
||||||
|
for(list<SchedulableStatus>::const_iterator f=_list.begin(); f != _list.end(); f++)
|
||||||
|
if (find(dx._list.begin(), dx._list.end(), *f) == dx._list.end()) //element NOT found!!
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
// src/backend/schedulable_list.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 SCHEDULABLE_LIST_HH
|
||||||
|
#define SCHEDULABLE_LIST_HH 1
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
#include "schedulable_status.hh"
|
||||||
|
#include "../templates/smartp.hh"
|
||||||
|
|
||||||
|
|
||||||
|
namespace sgpem
|
||||||
|
{
|
||||||
|
|
||||||
|
class SchedulableList;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class SG_DLLEXPORT SchedulableList
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SchedulableList();
|
||||||
|
bool operator==(const SchedulableList&) const;
|
||||||
|
bool has_same_objects(const SchedulableList& dx) const;
|
||||||
|
|
||||||
|
sgpem::SchedulableStatus* top();
|
||||||
|
sgpem::SchedulableStatus* bottom();
|
||||||
|
void add_at_bottom(const sgpem::SchedulableStatus&);
|
||||||
|
void add_at_top(const sgpem::SchedulableStatus&);
|
||||||
|
memory::smart_ptr<sgpem::SchedulableStatus> remove(const uint& position);
|
||||||
|
bool insert_at(const uint&, const uint&);
|
||||||
|
uint size() const;
|
||||||
|
SchedulableStatus* get_item_at(const uint&);
|
||||||
|
const SchedulableStatus* get_item_at(const uint&) const;
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::list<sgpem::SchedulableStatus> _list;
|
||||||
|
};
|
||||||
|
|
||||||
|
}//~ namespace sgpem
|
||||||
|
|
||||||
|
#endif //SCHEDULABLE_LIST_HH
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// src/backend/schedulableStatus.cc - Copyright 2005, 2006, University
|
// src/backend/schedulable_status.cc - Copyright 2005, 2006, University
|
||||||
// of Padova, dept. of Pure and Applied
|
// of Padova, dept. of Pure and Applied
|
||||||
// Mathematics
|
// Mathematics
|
||||||
//
|
//
|
||||||
|
|
|
@ -0,0 +1,151 @@
|
||||||
|
// src/backend/scheduler.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.hh"
|
||||||
|
#include "scheduler.hh"
|
||||||
|
using namespace std;
|
||||||
|
using namespace sgpem;
|
||||||
|
using namespace memory;
|
||||||
|
|
||||||
|
//static object
|
||||||
|
Scheduler Scheduler::_instance(10); //dummy parameter
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
*/
|
||||||
|
Scheduler::Scheduler(int) //private constructor. The parameter is discarded
|
||||||
|
{}
|
||||||
|
|
||||||
|
Scheduler&
|
||||||
|
Scheduler::get_instance()
|
||||||
|
{
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
SchedulableList*
|
||||||
|
Scheduler::get_ready_queue()
|
||||||
|
{
|
||||||
|
return &_ready_queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** \note E' fondamentale che questo metodo memorizzi localmente qualora la politica
|
||||||
|
attuale sia a prerilascio o meno, e la durata del quanto di tempo, in quanto la politica
|
||||||
|
e' libera di variare questi parametri a piacere durante l'esecuzione della simulazione
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
Scheduler::reset_status()
|
||||||
|
{
|
||||||
|
_ready_queue.clear();
|
||||||
|
History::get_instance().truncate_at(0);
|
||||||
|
// restore the policy
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Scheduler::step_forward()
|
||||||
|
{
|
||||||
|
History& h = History::get_instance();
|
||||||
|
//******************
|
||||||
|
//check for arrivals and prepare the queue
|
||||||
|
//******************
|
||||||
|
smart_ptr<const SchedulableList> initial = h.get_simulation_status_at(h.get_current_time());
|
||||||
|
_ready_queue.clear();
|
||||||
|
|
||||||
|
//adds running schedulable
|
||||||
|
smart_ptr<const SchedulableStatus> running_ptr = h.get_scheduled_at(h.get_current_time());
|
||||||
|
if (running_ptr)
|
||||||
|
_ready_queue.add_at_top(*running_ptr);
|
||||||
|
|
||||||
|
//adds each new ready schedulable and sorts the queue
|
||||||
|
for(uint i=0; i < initial->size(); i++)
|
||||||
|
if (initial->get_item_at(i)->get_state() == SchedulableStatus::state_ready
|
||||||
|
&& initial->get_item_at(i)->get_schedulable()->get_arrival_time() == h.get_current_time())
|
||||||
|
{
|
||||||
|
_ready_queue.add_at_bottom(*initial->get_item_at(i));
|
||||||
|
|
||||||
|
//pops the running schedulable only if the policy is not preemptive
|
||||||
|
if (_policy->is_pre_emptive() == false && running_ptr)
|
||||||
|
_ready_queue.remove(0);
|
||||||
|
|
||||||
|
// Sort the queue
|
||||||
|
_policy->sort_queue(event_schedulable_arrival);
|
||||||
|
|
||||||
|
//restore the old running schedulable
|
||||||
|
if (_policy->is_pre_emptive() == false && running_ptr)
|
||||||
|
_ready_queue.add_at_top(*running_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
//****************
|
||||||
|
// Check for termination
|
||||||
|
//****************
|
||||||
|
|
||||||
|
if (running_ptr && running_ptr->get_cpu_time_left() == 0)
|
||||||
|
{
|
||||||
|
//there was a running schedulable and it's terminated. Remove it!
|
||||||
|
for(uint i=0; i < _ready_queue.size(); i++)
|
||||||
|
if (*_ready_queue.get_item_at(i) == *running_ptr)
|
||||||
|
{
|
||||||
|
_ready_queue.remove(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//IF _ready_queue.size() == 0 sort_queue(...) is called but has no effect!!
|
||||||
|
_policy->sort_queue(event_schedulable_termination);
|
||||||
|
}
|
||||||
|
|
||||||
|
//*****************
|
||||||
|
// Check for time slice
|
||||||
|
//*****************
|
||||||
|
if (_policy->get_time_slice() != numeric_limits<int>::max()) //time-slice
|
||||||
|
_policy->sort_queue(event_end_time_slice);
|
||||||
|
|
||||||
|
//******************
|
||||||
|
// Create the final list of schedulable
|
||||||
|
//******************
|
||||||
|
|
||||||
|
SchedulableList final = _ready_queue;
|
||||||
|
|
||||||
|
if (final.size() != 0)
|
||||||
|
//the firs element IS the running one (if != *running_ptr then there is a CONTEXT SWICH)
|
||||||
|
final.get_item_at(0)->set_state(SchedulableStatus::state_running);
|
||||||
|
|
||||||
|
//all the others are ready
|
||||||
|
for (uint i = 1; i < final.size(); i++)
|
||||||
|
if (final.get_item_at(i)->get_state() == SchedulableStatus::state_running)
|
||||||
|
final.get_item_at(i)->set_state(SchedulableStatus::state_ready);
|
||||||
|
|
||||||
|
//append blocked, future, terminated and the old running schedulables
|
||||||
|
for (uint i = 0; i < initial->size(); i++)
|
||||||
|
if(initial->get_item_at(i)->get_state() == SchedulableStatus::state_blocked
|
||||||
|
|| initial->get_item_at(i)->get_state() == SchedulableStatus::state_future
|
||||||
|
|| initial->get_item_at(i)->get_state() == SchedulableStatus::state_terminated
|
||||||
|
|| (initial->get_item_at(i)->get_state() == SchedulableStatus::state_ready
|
||||||
|
&& initial->get_item_at(i)->get_schedulable()->get_arrival_time() != h.get_current_time()) )
|
||||||
|
final.add_at_bottom(*initial->get_item_at(i));
|
||||||
|
|
||||||
|
h.enqueue_slice(final);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
// 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 Policy;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
|
||||||
|
#include "observed_subject.hh"
|
||||||
|
#include "history.hh"
|
||||||
|
#include "schedulable_list.hh"
|
||||||
|
|
||||||
|
namespace sgpem
|
||||||
|
{
|
||||||
|
class Scheduler;
|
||||||
|
|
||||||
|
/** \brief
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
class SG_DLLEXPORT Scheduler : public ObservedSubject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum event
|
||||||
|
{
|
||||||
|
event_schedulable_arrival,
|
||||||
|
event_schedulable_termination,
|
||||||
|
event_end_time_slice
|
||||||
|
};
|
||||||
|
|
||||||
|
static Scheduler& get_instance();
|
||||||
|
SchedulableList* get_ready_queue();
|
||||||
|
void reset_status();
|
||||||
|
void step_forward();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Scheduler(int); //private constructor. The parameter is discarded
|
||||||
|
static Scheduler _instance;
|
||||||
|
SchedulableList _ready_queue;
|
||||||
|
Policy* _policy;
|
||||||
|
};
|
||||||
|
|
||||||
|
}//~ namespace sgpem
|
||||||
|
|
||||||
|
#endif //SCHEDULER_HH
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,95 +0,0 @@
|
||||||
// src/backend/simulationStatus.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 "simulation_status.hh"
|
|
||||||
using namespace sgpem;
|
|
||||||
using namespace std;
|
|
||||||
using namespace memory;
|
|
||||||
|
|
||||||
/** \brief Creates the SimulationStatus object with no SchedulableStatus object
|
|
||||||
|
|
||||||
*/
|
|
||||||
SimulationStatus::SimulationStatus()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
SimulationStatus::SimulationStatus(const SimulationStatus& dx)
|
|
||||||
:_set(dx._set)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** \brief Adds a SchedulableStatus which represents a running Schedulable object.
|
|
||||||
|
|
||||||
Adds a SchedulableStatus which represents a running Schedulable object.
|
|
||||||
Note that a copy of SchedulableStatus will be created
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
SimulationStatus::set_running(SchedulableStatus entity)
|
|
||||||
{
|
|
||||||
if (entity.get_state() != SchedulableStatus::state_running)
|
|
||||||
entity.set_state(SchedulableStatus::state_running);
|
|
||||||
_set.push_back(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** \brief Looks for a running Schedulable object and returns ist state.
|
|
||||||
Looks for a running Schedulable object and returns its state. There can be only
|
|
||||||
one running schedulable object. If no running schedulable object is found will be returned
|
|
||||||
the NULL pointer.
|
|
||||||
*/
|
|
||||||
|
|
||||||
smart_ptr<SchedulableStatus>
|
|
||||||
SimulationStatus::get_running()
|
|
||||||
{
|
|
||||||
for (list<SchedulableStatus>::iterator f=_set.begin(); f != _set.end(); f++)
|
|
||||||
if (f->get_state() == SchedulableStatus::state_running){ //there can be only ONE running schedulable objext
|
|
||||||
return smart_ptr<SchedulableStatus>(new SchedulableStatus(*f));
|
|
||||||
}
|
|
||||||
return smart_ptr<SchedulableStatus>(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
smart_ptr<const SchedulableStatus>
|
|
||||||
SimulationStatus::get_running() const
|
|
||||||
{
|
|
||||||
for (list<SchedulableStatus>::const_iterator f=_set.begin(); f != _set.end(); f++)
|
|
||||||
if (f->get_state() == SchedulableStatus::state_running){ //there can be only ONE running schedulable objext
|
|
||||||
return smart_ptr<const SchedulableStatus>(new SchedulableStatus(*f));
|
|
||||||
}
|
|
||||||
return smart_ptr<const SchedulableStatus>(NULL); //NOT FOUND RUNNING ENTITIES
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
\brief Returns TRUE if the two objects have the same SchedulableStatus objects
|
|
||||||
*/
|
|
||||||
bool
|
|
||||||
SimulationStatus::operator==(const SimulationStatus& dx) const
|
|
||||||
{
|
|
||||||
if (_set.size() != dx._set.size())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
//check if dx has ALL and ONLY the elements holded by _set with no order importance
|
|
||||||
for(list<SchedulableStatus>::const_iterator f=_set.begin(); f != _set.end(); f++)
|
|
||||||
if (find(dx._set.begin(), dx._set.end(), *f) == dx._set.end()) //element NOT found!!
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
|
@ -1,61 +0,0 @@
|
||||||
// src/backend/simulationStatus.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 SIMULATIONSTATUS_HH
|
|
||||||
#define SIMULATIONSTATUS_HH 1
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include <list>
|
|
||||||
|
|
||||||
#include "schedulable_status.hh"
|
|
||||||
#include "../templates/smartp.hh"
|
|
||||||
|
|
||||||
namespace sgpem
|
|
||||||
{
|
|
||||||
class SimulationStatus;
|
|
||||||
|
|
||||||
/** \brief Keeps informatios about the configuration of the simulation
|
|
||||||
|
|
||||||
Keeps informatios about the configuration of the simulation: which process is
|
|
||||||
running and other infos (since M02+)
|
|
||||||
*/
|
|
||||||
|
|
||||||
class SG_DLLEXPORT SimulationStatus
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SimulationStatus();
|
|
||||||
SimulationStatus(const SimulationStatus&);
|
|
||||||
|
|
||||||
bool operator==(const SimulationStatus&) const;
|
|
||||||
|
|
||||||
//this method isn't const because it returns a pointer which CAN alter the object!
|
|
||||||
memory::smart_ptr<SchedulableStatus> get_running();
|
|
||||||
memory::smart_ptr<const SchedulableStatus> get_running() const;
|
|
||||||
void set_running(SchedulableStatus);
|
|
||||||
|
|
||||||
private:
|
|
||||||
//I used a list instead of a vector because this one could reallocate the internal elements
|
|
||||||
//making pointers returned by getRunning() point to nothing! SEGMENTATION-FAULT :-O
|
|
||||||
std::list<SchedulableStatus> _set;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -23,15 +23,15 @@ using namespace sgpem;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
Slice::Slice(const int& start, const int& duration, const SimulationStatus& status)
|
Slice::Slice(const int& start, const int& duration, const SchedulableList& status)
|
||||||
: _ref(status), _started_at(start), _duration(duration)
|
: _ref(status), _started_at(start), _duration(duration)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SimulationStatus&
|
const SchedulableList*
|
||||||
Slice::get_simulation_status()
|
Slice::get_simulation_status() const
|
||||||
{
|
{
|
||||||
return _ref;
|
return &_ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "simulation_status.hh"
|
#include "schedulable_list.hh"
|
||||||
|
|
||||||
namespace sgpem
|
namespace sgpem
|
||||||
{
|
{
|
||||||
|
@ -39,15 +39,15 @@ namespace sgpem
|
||||||
class SG_DLLEXPORT Slice
|
class SG_DLLEXPORT Slice
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Slice(const int& start, const int& duration, const SimulationStatus& status);
|
Slice(const int& start, const int& duration, const SchedulableList& status);
|
||||||
|
|
||||||
SimulationStatus& get_simulation_status();
|
const SchedulableList* get_simulation_status() const;
|
||||||
int get_started_at() const;
|
int get_started_at() const;
|
||||||
int get_duration() const;
|
int get_duration() const;
|
||||||
void set_duration(const int&);
|
void set_duration(const int&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SimulationStatus _ref;
|
SchedulableList _ref;
|
||||||
int _started_at;
|
int _started_at;
|
||||||
int _duration;
|
int _duration;
|
||||||
};
|
};
|
||||||
|
|
68
src/main.cc
68
src/main.cc
|
@ -27,10 +27,10 @@
|
||||||
|
|
||||||
#include "templates/smartp.hh"
|
#include "templates/smartp.hh"
|
||||||
#include "backend/history.hh"
|
#include "backend/history.hh"
|
||||||
#include "backend/slice.hh"
|
|
||||||
#include "backend/schedulable.hh"
|
#include "backend/schedulable.hh"
|
||||||
|
#include "backend/schedulable_list.hh"
|
||||||
#include "backend/schedulable_status.hh"
|
#include "backend/schedulable_status.hh"
|
||||||
#include "backend/simulation_status.hh"
|
#include "backend/slice.hh"
|
||||||
#include "backend/process.hh"
|
#include "backend/process.hh"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -68,32 +68,45 @@ main(int argc, char* argv[])
|
||||||
Process p1("P1", 0,10,1);
|
Process p1("P1", 0,10,1);
|
||||||
Process p2("P2", 0,30,2);
|
Process p2("P2", 0,30,2);
|
||||||
Process p3("P3", 5,15,3);
|
Process p3("P3", 5,15,3);
|
||||||
|
Process p4("P4", 6,5,3);
|
||||||
|
Process p5("P5", 1,10,3);
|
||||||
|
Process p6("P6", 10,2,1);
|
||||||
|
|
||||||
SchedulableStatus ss1(p1);
|
SchedulableStatus ss1(p1); ss1.set_state(SchedulableStatus::state_running);
|
||||||
SchedulableStatus ss2(p2);
|
SchedulableStatus ss2(p2);
|
||||||
SchedulableStatus ss3(p3);
|
SchedulableStatus ss3(p3);
|
||||||
|
SchedulableStatus ss4(p4); ss4.set_state(SchedulableStatus::state_running);
|
||||||
|
SchedulableStatus ss5(p5);
|
||||||
|
SchedulableStatus ss6(p6);
|
||||||
|
|
||||||
SimulationStatus sim1; sim1.set_running(p1);
|
// SimulationStatus sim1; sim1.set_running(p1);
|
||||||
SimulationStatus sim2; sim2.set_running(p2);
|
|
||||||
SimulationStatus sim3; sim3.set_running(p3);
|
|
||||||
|
|
||||||
History h(History::getInstance());
|
//************** TEST HISTORY
|
||||||
|
|
||||||
h.enqueue_slice(sim1);
|
SchedulableList l1;
|
||||||
h.enqueue_slice(sim1);
|
l1.add_at_top(ss1); l1.add_at_top(ss2); l1.add_at_top(ss3);
|
||||||
h.enqueue_slice(sim2);
|
|
||||||
h.enqueue_slice(sim1);
|
|
||||||
h.enqueue_slice(sim2);
|
|
||||||
h.enqueue_slice(sim1);
|
|
||||||
h.enqueue_slice(sim2);
|
|
||||||
h.enqueue_slice(sim3);
|
|
||||||
h.enqueue_slice(sim3);
|
|
||||||
h.enqueue_slice(sim1);
|
|
||||||
h.enqueue_slice(sim3);
|
|
||||||
h.enqueue_slice(sim1);
|
|
||||||
|
|
||||||
h.truncate_at(3);
|
SchedulableList l2;
|
||||||
|
l2.add_at_top(ss4); l2.add_at_top(ss5); l2.add_at_top(ss6);
|
||||||
|
|
||||||
|
History h(History::get_instance());
|
||||||
|
h.enqueue_slice(l1); //stato iniziale
|
||||||
|
h.enqueue_slice(l2);
|
||||||
|
|
||||||
|
smart_ptr<const sgpem::SchedulableList> quale;
|
||||||
|
|
||||||
|
quale = h.get_simulation_status_at(0); //stato iniziale
|
||||||
|
|
||||||
|
cout << quale->get_item_at(0)->get_schedulable()->get_name();
|
||||||
|
smart_ptr<const sgpem::SchedulableStatus> quale2 = h.get_scheduled_at(1);
|
||||||
|
cout << quale2->get_schedulable()->get_name();
|
||||||
|
|
||||||
|
h.truncate_at(0);
|
||||||
|
quale = h.get_simulation_status_at(0); //stato iniziale
|
||||||
|
|
||||||
|
cout << bool(quale) << " " << quale->get_item_at(0)->get_schedulable()->get_name();
|
||||||
|
|
||||||
|
/*
|
||||||
smart_ptr<const sgpem::SimulationStatus> quale;
|
smart_ptr<const sgpem::SimulationStatus> quale;
|
||||||
|
|
||||||
quale = h.get_simulation_status_at(0);
|
quale = h.get_simulation_status_at(0);
|
||||||
|
@ -112,8 +125,23 @@ main(int argc, char* argv[])
|
||||||
if (quale2) cout << "\n" << quale2->get_schedulable()->get_name(); else cout << "NO";
|
if (quale2) cout << "\n" << quale2->get_schedulable()->get_name(); else cout << "NO";
|
||||||
quale2 = h.get_scheduled_at(2);
|
quale2 = h.get_scheduled_at(2);
|
||||||
if (quale2) cout << "\n" << quale2->get_schedulable()->get_name(); else cout << "NO";
|
if (quale2) cout << "\n" << quale2->get_schedulable()->get_name(); else cout << "NO";
|
||||||
|
*/
|
||||||
|
|
||||||
|
//************** TEST QUEUE
|
||||||
|
cout << "\n\nTEST QUEUE\n";
|
||||||
|
|
||||||
|
/* SchedulableQueue sq;
|
||||||
|
sq.add_at_top(ss1);
|
||||||
|
sq.add_at_top(ss2);
|
||||||
|
sq.add_at_bottom(ss3);
|
||||||
|
cout << sq.get_item_at(0)->get_schedulable()->get_name() << "\n";
|
||||||
|
cout << sq.get_item_at(1)->get_schedulable()->get_name() << "\n";
|
||||||
|
cout << sq.get_item_at(2)->get_schedulable()->get_name() << "\n";
|
||||||
|
sq.insert_at(0,2);
|
||||||
|
cout << sq.get_item_at(0)->get_schedulable()->get_name() << "\n";
|
||||||
|
cout << sq.get_item_at(1)->get_schedulable()->get_name() << "\n";
|
||||||
|
cout << sq.get_item_at(2)->get_schedulable()->get_name() << "\n";
|
||||||
|
*/
|
||||||
cout << "\n\n";
|
cout << "\n\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
// src/frontend/observer.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 "observer.hh"
|
||||||
|
|
||||||
|
using namespace sgpem;
|
||||||
|
|
||||||
|
Observer::Observer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Observer::~Observer()
|
||||||
|
{
|
||||||
|
}
|
|
@ -37,9 +37,10 @@ namespace sgpem
|
||||||
class SG_DLLEXPORT Observer
|
class SG_DLLEXPORT Observer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Observer();
|
||||||
virtual ~Observer() = 0;
|
virtual ~Observer() = 0;
|
||||||
|
|
||||||
virtual void update();
|
virtual void update() =0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue