- Substitute the old SchedulableQueue with the new ReadyQueue
- Add interfaces for Process and Thread into the "sgpem.i" SWIG interface file, change DynamicSchedulable into Schedulable - Add dynamic_cast for the return value of ReadyQueue::get_item_at() into the pyloader "sgpem.i" SWIG interface, so that a Schedulable can be either recognized as a Thread or a Process - TODO: wrap STL exceptions in SWIG interface - Please note that code won't compile until the new History and Scheduler::step_forward() will be in place. This is a known issue. git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@689 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
fa06e2f4f1
commit
759b90b017
24 changed files with 170 additions and 414 deletions
|
@ -21,11 +21,15 @@
|
|||
#include "config.h"
|
||||
|
||||
#include "history.hh"
|
||||
#include "dynamic_process.hh"
|
||||
#include "dynamic_thread.hh"
|
||||
|
||||
// Do not include in header file:
|
||||
#include "singleton.tcc"
|
||||
#include "smartp.tcc"
|
||||
|
||||
#include <exception>
|
||||
|
||||
using namespace std;
|
||||
using namespace sgpem;
|
||||
using namespace memory;
|
||||
|
@ -34,7 +38,7 @@ using namespace memory;
|
|||
template class SG_DLLEXPORT Singleton<History>;
|
||||
|
||||
// FIXME: These two should disappear!!!
|
||||
template class SG_DLLEXPORT smart_ptr<SchedulableQueue>;
|
||||
template class SG_DLLEXPORT smart_ptr<ReadyQueue>;
|
||||
template class SG_DLLEXPORT smart_ptr<DynamicSchedulable>;
|
||||
|
||||
/**
|
||||
|
@ -50,7 +54,7 @@ History::History() //private constructor.
|
|||
/**
|
||||
Returns a pointer to a copy of the DynamicSchedulable object relative to this instant.
|
||||
It can be NULL if time is out of range or if there are no running entities in the associated
|
||||
SchedulableQueue
|
||||
ReadyQueue
|
||||
*/
|
||||
smart_ptr<DynamicSchedulable>
|
||||
History::get_scheduled_at(int time) const
|
||||
|
@ -59,11 +63,24 @@ History::get_scheduled_at(int time) const
|
|||
return smart_ptr<DynamicSchedulable>(NULL);
|
||||
|
||||
//look for a runing entity
|
||||
smart_ptr<SchedulableQueue> p = get_simulation_status_at(time);
|
||||
smart_ptr<ReadyQueue> p = get_simulation_status_at(time);
|
||||
|
||||
for (uint i = 0; i < p->size(); i++)
|
||||
if (p->get_item_at(i)->get_state() == DynamicSchedulable::state_running)
|
||||
return smart_ptr<DynamicSchedulable>(new DynamicSchedulable(*(p->get_item_at(i))));
|
||||
if (p->get_item_at(i).get_state() == DynamicSchedulable::state_running)
|
||||
{
|
||||
// Copy the right object
|
||||
// FIXME: this code has to be reworked (probably ditched by the new ConcreteHistory)
|
||||
Schedulable* tmp = &p->get_item_at(i);
|
||||
|
||||
DynamicProcess* proc;
|
||||
DynamicThread* thread;
|
||||
if((proc = dynamic_cast<DynamicProcess*>(tmp)) != NULL)
|
||||
return smart_ptr<DynamicSchedulable>(new DynamicProcess(*proc));
|
||||
else if((thread = dynamic_cast<DynamicThread*>(tmp)) != NULL)
|
||||
return smart_ptr<DynamicSchedulable>(new DynamicThread(*thread));
|
||||
else
|
||||
throw std::bad_cast();
|
||||
}
|
||||
|
||||
return smart_ptr<DynamicSchedulable>(NULL);
|
||||
}
|
||||
|
@ -72,21 +89,21 @@ History::get_scheduled_at(int time) const
|
|||
Returns a pointer to a copy of the SimulationStatus object relative to this instant or NULL
|
||||
if time is out of range.
|
||||
*/
|
||||
smart_ptr<SchedulableQueue>
|
||||
smart_ptr<ReadyQueue>
|
||||
History::get_simulation_status_at(int time) const
|
||||
{
|
||||
if (time > _total_time_elapsed || time < 0) //out of range
|
||||
return smart_ptr<SchedulableQueue>(NULL);
|
||||
return smart_ptr<ReadyQueue>(NULL);
|
||||
|
||||
int trascorso = -1;
|
||||
for(vector<Slice>::const_iterator i = _slices.begin(); i < _slices.end(); i++)
|
||||
if (time <= trascorso + i->get_duration()) //FOUND!!
|
||||
return smart_ptr<SchedulableQueue>(new SchedulableQueue(*i->get_simulation_status()));
|
||||
return smart_ptr<ReadyQueue>(new ReadyQueue(*i->get_simulation_status()));
|
||||
else //Go on...
|
||||
trascorso += i->get_duration();
|
||||
|
||||
//never reached if all slices are CONTIGUOUS (ans THIS shoul be!!)!!!
|
||||
return smart_ptr<SchedulableQueue>(NULL);
|
||||
return smart_ptr<ReadyQueue>(NULL);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -100,7 +117,7 @@ History::get_current_time() const
|
|||
Calls the method notify() in quality of ObservedSubject, updating all observers.
|
||||
*/
|
||||
void
|
||||
History::enqueue_slice(const SchedulableQueue& status)
|
||||
History::enqueue_slice(const ReadyQueue& status)
|
||||
{
|
||||
if(_slices.size() == 0)
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
#include "slice.hh"
|
||||
#include "observed_subject.hh"
|
||||
#include "schedulable_queue.hh"
|
||||
#include "ready_queue.hh"
|
||||
#include "dynamic_schedulable.hh"
|
||||
#include "smartp.hh"
|
||||
|
||||
|
@ -67,7 +67,7 @@ namespace sgpem
|
|||
\param time The inquired time instant.
|
||||
\return The list of Schedulable status objects at the specified time.
|
||||
*/
|
||||
virtual memory::smart_ptr<sgpem::SchedulableQueue> get_simulation_status_at(int time) const;
|
||||
virtual memory::smart_ptr<sgpem::ReadyQueue> get_simulation_status_at(int time) const;
|
||||
|
||||
/**
|
||||
Gets the current time.
|
||||
|
@ -79,7 +79,7 @@ namespace sgpem
|
|||
Sets the status of simulation at the current time.
|
||||
\param status The list of \ref Schedulable status objects at the current time.
|
||||
*/
|
||||
virtual void enqueue_slice(const sgpem::SchedulableQueue& status);
|
||||
virtual void enqueue_slice(const sgpem::ReadyQueue& status);
|
||||
|
||||
/**
|
||||
Remove all data in History following the specified time.
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace sgpem
|
|||
It's a Strategy wich stay for a scheduling algorithm.
|
||||
It implements the related scheduling policy.
|
||||
Its goal is, usually, to keep a list of Schedulable objects
|
||||
mantained in a SchedulableQueue.
|
||||
mantained in a ReadyQueue.
|
||||
*/
|
||||
class SG_DLLEXPORT Policy
|
||||
{
|
||||
|
@ -62,7 +62,7 @@ namespace sgpem
|
|||
virtual void configure() throw(UserInterruptException) = 0;
|
||||
|
||||
/**
|
||||
Sort the \ref SchedulableQueue object that contain all the Schedulable objects
|
||||
Sort the \ref ReadyQueue object that contain all the Schedulable objects
|
||||
(Processes, Threads) still active managed by the scheduler.
|
||||
|
||||
Because it's a pure virtual method, must be re-implemented
|
||||
|
|
|
@ -38,9 +38,9 @@ namespace sgpem
|
|||
typedef unsigned int size_t;
|
||||
|
||||
void swap(position a, position b) throw (std::out_of_range);
|
||||
inline size_t size() const;
|
||||
size_t size() const;
|
||||
Schedulable& get_item_at(position index) throw (std::out_of_range);
|
||||
inline void append(Schedulable& schedulable);
|
||||
void append(Schedulable& schedulable);
|
||||
|
||||
private:
|
||||
typedef std::vector<Schedulable*> Schedulables;
|
||||
|
|
|
@ -1,215 +0,0 @@
|
|||
// src/backend/schedulable_queue.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_queue.hh"
|
||||
|
||||
#include "smartp.tcc"
|
||||
|
||||
using namespace sgpem;
|
||||
using namespace std;
|
||||
using namespace memory;
|
||||
|
||||
SchedulableQueue::SchedulableQueue()
|
||||
{}
|
||||
|
||||
DynamicSchedulable*
|
||||
SchedulableQueue::top()
|
||||
{
|
||||
if (_list.size() == 0)
|
||||
return NULL;
|
||||
return &_list.front();
|
||||
}
|
||||
|
||||
DynamicSchedulable*
|
||||
SchedulableQueue::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.
|
||||
*/
|
||||
DynamicSchedulable*
|
||||
SchedulableQueue::get_item_at(const uint& where)
|
||||
{
|
||||
if (_list.size() == 0 || where >= _list.size())
|
||||
return NULL;
|
||||
|
||||
list<DynamicSchedulable>::iterator i = _list.begin();
|
||||
for (uint f = 0; f < where; f++)
|
||||
i++;
|
||||
return &(*i);
|
||||
}
|
||||
|
||||
const DynamicSchedulable*
|
||||
SchedulableQueue::get_item_at(const uint& where) const
|
||||
{
|
||||
if (_list.size() == 0 || where >= _list.size())
|
||||
return NULL;
|
||||
|
||||
list<DynamicSchedulable>::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
|
||||
SchedulableQueue::size() const
|
||||
{
|
||||
return _list.size();
|
||||
}
|
||||
|
||||
void
|
||||
SchedulableQueue::add_at_top(const DynamicSchedulable& ss)
|
||||
{
|
||||
_list.push_front(ss);
|
||||
}
|
||||
|
||||
void
|
||||
SchedulableQueue::add_at_bottom(const DynamicSchedulable& ss)
|
||||
{
|
||||
_list.push_back(ss);
|
||||
}
|
||||
|
||||
smart_ptr<DynamicSchedulable>
|
||||
SchedulableQueue::remove(const uint& position)
|
||||
{
|
||||
if (_list.size() == 0 || position >= _list.size())
|
||||
return smart_ptr<DynamicSchedulable>(NULL);
|
||||
|
||||
//creates a copy of the first element
|
||||
smart_ptr<DynamicSchedulable> sm = new DynamicSchedulable(*top());
|
||||
//pops the first element
|
||||
_list.pop_front();
|
||||
//returns the copy
|
||||
return sm;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
bool
|
||||
SchedulableQueue::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<DynamicSchedulable>::iterator i_where = _list.begin();
|
||||
list<DynamicSchedulable>::iterator i_which = _list.begin();
|
||||
for (uint f = 0; f < where; f++)
|
||||
i_where++;
|
||||
for (uint f = 0; f < which; f++)
|
||||
i_which++;
|
||||
|
||||
//save and pop WHICH
|
||||
DynamicSchedulable temp = *i_which;
|
||||
_list.erase(i_which);
|
||||
|
||||
//insert WHICH before WHERE
|
||||
_list.insert(i_where, temp);
|
||||
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
Removes all elements
|
||||
*/
|
||||
|
||||
void
|
||||
SchedulableQueue::clear()
|
||||
{
|
||||
_list.clear();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Returns TRUE if the two objects have the same DynamicSchedulable objects in the same order.
|
||||
*/
|
||||
bool
|
||||
SchedulableQueue::operator==(const SchedulableQueue& dx) const
|
||||
{
|
||||
return _list == dx._list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Returns TRUE if the two objects have the same DynamicSchedulable objects with NO ORDER IMPORTANCE.
|
||||
*/
|
||||
bool
|
||||
SchedulableQueue::has_same_objects(const SchedulableQueue& 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<DynamicSchedulable>::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;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SchedulableQueue::swap(unsigned int positionA, unsigned int positionB) throw()
|
||||
{
|
||||
if (positionA == positionB || positionA >= _list.size() || positionB >= _list.size())
|
||||
return;
|
||||
|
||||
unsigned int min, max;
|
||||
if (positionA < positionB)
|
||||
{
|
||||
min = positionA;
|
||||
max = positionB;
|
||||
}
|
||||
else
|
||||
{
|
||||
min = positionB;
|
||||
max = positionA;
|
||||
}
|
||||
|
||||
list<DynamicSchedulable>::iterator i1 = _list.begin();
|
||||
list<DynamicSchedulable>::iterator i2 = _list.begin();
|
||||
|
||||
//reach the first element;
|
||||
for (uint f = 0; f < min; f++)
|
||||
i1++;
|
||||
DynamicSchedulable temp = *i1;
|
||||
|
||||
//reach the second element;
|
||||
i2 = i1;
|
||||
for (uint f = min; f < max; f++)
|
||||
i2++;
|
||||
|
||||
*i1 = *i2;
|
||||
*i2 = temp;
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
// src/backend/schedulable_queue.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 "dynamic_schedulable.hh"
|
||||
|
||||
#include "smartp.hh"
|
||||
|
||||
#include <list>
|
||||
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
class SchedulableQueue;
|
||||
|
||||
class SG_DLLEXPORT SchedulableQueue
|
||||
{
|
||||
public:
|
||||
SchedulableQueue();
|
||||
bool operator==(const SchedulableQueue&) const;
|
||||
bool has_same_objects(const SchedulableQueue& dx) const;
|
||||
|
||||
/** \brief Returns a pointer to the first element
|
||||
*
|
||||
* This function returns a pointer to the first element, or null if the
|
||||
* queue is empty.
|
||||
*
|
||||
* It is very important not to delete these pointers as their deallocation
|
||||
* is managed by the queue.
|
||||
*/
|
||||
DynamicSchedulable* top();
|
||||
|
||||
/** \brief Returns a pointer to the last element
|
||||
* \see top
|
||||
*/
|
||||
DynamicSchedulable* bottom();
|
||||
|
||||
/** \brief Adds an element at the top of the queue */
|
||||
void add_at_top(const DynamicSchedulable&);
|
||||
|
||||
/** \brief Adds an element at the end of the queue */
|
||||
void add_at_bottom(const DynamicSchedulable&);
|
||||
|
||||
/** \brief Removes */
|
||||
/**
|
||||
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
|
||||
*/
|
||||
|
||||
memory::smart_ptr<sgpem::DynamicSchedulable> remove(const unsigned int& position);
|
||||
bool insert_at(const unsigned int&, const unsigned int&);
|
||||
unsigned int size() const;
|
||||
DynamicSchedulable* get_item_at(const uint&);
|
||||
const DynamicSchedulable* get_item_at(const uint&) const;
|
||||
void clear();
|
||||
|
||||
/** \brief This method swaps two elements given their list positions
|
||||
*
|
||||
* At the present moment, this function shouldn't throw any exception, but
|
||||
* just do nothing when the parameters don't make sense (e.g. one of the
|
||||
* positions is outside range [0,this.size()]).
|
||||
*
|
||||
* However, it should work the same either if positionA is greater than or
|
||||
* less than positionB.
|
||||
*
|
||||
* In the future, this method could throw an OutOfRange exception.
|
||||
*
|
||||
* \param positionA The position of the first element to swap
|
||||
* \param positionB The position of the second element to swap
|
||||
*/
|
||||
void swap(unsigned int positionA, unsigned int positionB) throw();
|
||||
|
||||
private:
|
||||
std::list<DynamicSchedulable> _list;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //SCHEDULABLE_LIST_HH
|
|
@ -42,7 +42,7 @@ Scheduler::Scheduler()
|
|||
_policy_manager.init();
|
||||
}
|
||||
|
||||
SchedulableQueue*
|
||||
ReadyQueue*
|
||||
Scheduler::get_ready_queue()
|
||||
{
|
||||
// FIXME return the correct queue accordingly to the value returned by Policy::wants()
|
||||
|
@ -88,7 +88,7 @@ Scheduler::step_forward() throw(UserInterruptException)
|
|||
//******************
|
||||
//check for arrivals and prepare the queue
|
||||
//******************
|
||||
smart_ptr<SchedulableQueue> initial = h.get_simulation_status_at(h.get_current_time());
|
||||
smart_ptr<ReadyQueue> initial = h.get_simulation_status_at(h.get_current_time());
|
||||
if (!initial)
|
||||
{
|
||||
cout << _("\nNo initial state inserted!!\n");
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace sgpem
|
|||
|
||||
#include "observed_subject.hh"
|
||||
#include "history.hh"
|
||||
#include "schedulable_queue.hh"
|
||||
#include "ready_queue.hh"
|
||||
#include "user_interrupt_exception.hh"
|
||||
|
||||
// Do not include full template definition here
|
||||
|
@ -65,13 +65,13 @@ namespace sgpem
|
|||
\return a pointer to the queue containing all the ready
|
||||
schedulable objects (for the policy to sort it).
|
||||
*/
|
||||
SchedulableQueue* get_ready_queue();
|
||||
ReadyQueue* get_ready_queue();
|
||||
/**
|
||||
Resets the simulation to the initial state.
|
||||
*/
|
||||
void reset_status();
|
||||
/**
|
||||
Generates a new SchedulableQueue representing the status of the processes
|
||||
Generates a new ReadyQueue representing the status of the processes
|
||||
at the simulation instant next to the current one, and extends the History by
|
||||
one instant with it.
|
||||
*/
|
||||
|
@ -91,7 +91,7 @@ namespace sgpem
|
|||
|
||||
private:
|
||||
Scheduler(); //private constructor.
|
||||
SchedulableQueue _ready_queue;
|
||||
ReadyQueue _ready_queue;
|
||||
PolicyManager& _policy_manager;
|
||||
};
|
||||
|
||||
|
|
|
@ -23,11 +23,11 @@ using namespace sgpem;
|
|||
using namespace std;
|
||||
|
||||
|
||||
Slice::Slice(const int& start, const int& duration, const SchedulableQueue& status)
|
||||
Slice::Slice(const int& start, const int& duration, const ReadyQueue& status)
|
||||
: _ref(status), _started_at(start), _duration(duration)
|
||||
{}
|
||||
|
||||
const SchedulableQueue*
|
||||
const ReadyQueue*
|
||||
Slice::get_simulation_status() const
|
||||
{
|
||||
return &_ref;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include "schedulable_queue.hh"
|
||||
#include "ready_queue.hh"
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
|
@ -45,13 +45,13 @@ namespace sgpem
|
|||
\param duration Time length of Slice.
|
||||
\param status Photoshot of all \ref Schedulable during this Slice.
|
||||
*/
|
||||
Slice(const int& start, const int& duration, const SchedulableQueue& status);
|
||||
Slice(const int& start, const int& duration, const ReadyQueue& status);
|
||||
|
||||
/**
|
||||
Gets a constant reference to the \ref SchedulableQueue object for this Slice.
|
||||
\return The reference (constant) to the SchedulableQueue object for this Slice.
|
||||
Gets a constant reference to the \ref ReadyQueue object for this Slice.
|
||||
\return The reference (constant) to the ReadyQueue object for this Slice.
|
||||
*/
|
||||
const SchedulableQueue* get_simulation_status() const;
|
||||
const ReadyQueue* get_simulation_status() const;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -73,7 +73,7 @@ namespace sgpem
|
|||
void set_duration(const int& duration);
|
||||
|
||||
private:
|
||||
SchedulableQueue _ref;
|
||||
ReadyQueue _ref;
|
||||
int _started_at;
|
||||
int _duration;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue