- 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:
tchernobog 2006-07-02 13:51:03 +00:00
parent fa06e2f4f1
commit 759b90b017
24 changed files with 170 additions and 414 deletions

View File

@ -40,7 +40,7 @@ class Policy:
# # function body
# @endcode
#
# @param queue The sgpem::SchedulableQueue to be sorted.
# @param queue The sgpem::ReadyQueue to be sorted.
# Only some methods of it are implemented,
# notably get_item_at(position),
# swap(positionA, positionB) and size().
@ -113,7 +113,7 @@ class Policy:
## @brief This function implements an in-place stable sort
# using directly SchedulableQueue methods
# using directly ReadyQueue methods
#
# The compare parameter should be a user defined binary
# function returning either True or False, defined in one
@ -137,7 +137,7 @@ class Policy:
# @endcode
#
# @param self The object caller
# @param queue The SchedulableQueue to be sorted in place
# @param queue The ReadyQueue to be sorted in place
# @param cmpf The binary function to use to compare elements
# @returns None
def sort(self, queue, cmpf):
@ -167,7 +167,7 @@ class Policy:
#
# Feel the love.
#
# @param queue The SchedulableQueue to sort
# @param queue The ReadyQueue to sort
# @param a The partition starting element position in the queue
# @param b The partition ending element position in the queue
# @param cmpf The binary function to use for comparing two elements

View File

@ -1,11 +1,14 @@
%include "std_vector.i"
%module sgpem
%{
#include "policy.hh"
#include "policy_parameters.hh"
#include "static_schedulable.hh"
#include "schedulable_queue.hh"
#include "dynamic_schedulable.hh"
#include "process.hh"
#include "ready_queue.hh"
#include "schedulable.hh"
#include "scheduler.hh"
#include "thread.hh"
%}
/* NOTE : passing Unicode strings to C++ methods calling them
@ -14,12 +17,16 @@
* the sgpem user manual)
*/
/** Due to the relatively new support for namespaces in SWIG,
/* Due to the relatively new support for namespaces in SWIG,
* make sure to include the full visibility signature when
* returning / passing parameters from / to functions with
* objects different to the one you're declaring.
*/
/* FIXME : look up into Swig manual the management of
* STL exceptions and write wrappers for them.
*/
namespace std {
class exception {
public:
@ -36,6 +43,8 @@ namespace std {
};
}
// (See last comment): Wrap the above exceptions in the SWIG way.
namespace sgpem {
/** Don't get worried, order is not important! */
@ -158,29 +167,75 @@ namespace sgpem {
}
}; //~ class Schedulable
// --------------------------------------------
class SchedulableQueue
// Instantiate a Thread* vector for usage with Process
// std::out_of_range should be automatically defined,
// see Swig manual at the STL Vector §.
namespace std {
%template(ThreadVector) vector<Thread*>;
}
class Process : public virtual Schedulable
{
public:
unsigned int size() const;
const sgpem::Schedulable* get_item_at(const unsigned int&) const;
void swap(unsigned int positionA, unsigned int positionB) throw();
virtual std::vector<Thread*> get_threads();
} //~ class Process
class Thread : public virtual Schedulable
{
public:
virtual Process& get_process();
} //~ class Thread
// --------------------------------------------
class ReadyQueue
{
public:
typedef unsigned int position;
typedef unsigned int size_t;
size_t size() const;
// Dynamic cast to Process or to Thread so
// that Python code sees the extra-methods
%typename(out) sgpem::Schedulable*;
{
// OMG, Ponies!!
Process* proc;
Thread* thread;
if((proc = dynamic_cast<Process*>($1)) != NULL)
$result = SWIG_NewPointerObj(SWIG_as_voidptr(proc),
SWIGTYPE_p_sgpem__Process, 0 | 0 );
else if((thread = dynamic_cast<Thread*>($1)) != NULL)
$result = SWIG_NewPointerObj(SWIG_as_voidptr(thread),
SWIGTYPE_p_sgpem__Thread, 0 | 0 );
else // Fall back to Schedulable* if no dynamic_cast went well:
$result = SWIG_NewPointerObj(SWIG_as_voidptr(thread),
$1_descriptor, 0 | 0 );
}
sgpem::Schedulable* get_item_at(position index);
%typename(out) sgpem::Schedulable*;
void swap(position a, position b) throw(std::out_of_range);
private:
// Avoid instantiation and copy
SchedulableQueue();
SchedulableQueue(const SchedulableQueue&);
SchedulableQueue& operator=(const SchedulableQueue&);
~SchedulableQueue();
}; //~ class Schedulable
ReadyQueue();
ReadyQueue(const ReadyQueue&);
ReadyQueue& operator=(const ReadyQueue&);
~ReadyQueue();
}; //~ class ReadyQueue
// ---------------------------------------------
class Scheduler {
public:
sgpem::Policy& get_policy();
static sgpem::Scheduler& get_instance();
sgpem::SchedulableQueue* get_ready_queue();
sgpem::ReadyQueue* get_ready_queue();
private:
Scheduler();
~Scheduler();

View File

@ -24,8 +24,9 @@
#include "../python_policy_manager.hh"
#include "../python_policy.hh"
#include "global_preferences.hh"
#include "schedulable_queue.hh"
#include "ready_queue.hh"
#include "scheduler.hh"
#include "user_interrupt_exception.hh"
@ -114,7 +115,7 @@ main(int argc, char** argv)
try
{
SchedulableQueue sl;
ReadyQueue sl;
polman.test_init("python_loader_sort_queue");
polman.get_policy().sort_queue();
}

View File

@ -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)
{

View File

@ -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.

View File

@ -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

View File

@ -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;

View File

@ -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;
}

View File

@ -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

View File

@ -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");

View File

@ -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;
};

View File

@ -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;

View File

@ -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;
};

View File

@ -27,7 +27,7 @@
#include "backend/history.hh"
#include "backend/static_schedulable.hh"
#include "backend/schedulable_queue.hh"
#include "backend/ready_queue.hh"
#include "backend/dynamic_schedulable.hh"
#include "backend/slice.hh"
#include "backend/static_process.hh"
@ -123,7 +123,7 @@ main(int argc, char* argv[])
DynamicSchedulable ss5(p5);
DynamicSchedulable ss6(p6);
SchedulableQueue initial;
ReadyQueue initial;
initial.add_at_bottom(ss1);
initial.add_at_bottom(ss2);
initial.add_at_bottom(ss3);
@ -155,17 +155,17 @@ main(int argc, char* argv[])
// ************** TEST HISTORY
SchedulableQueue l1;
ReadyQueue l1;
l1.add_at_top(ss1); l1.add_at_top(ss2); l1.add_at_top(ss3);
SchedulableQueue l2;
ReadyQueue 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::SchedulableQueue> quale;
smart_ptr<const sgpem::ReadyQueue> quale;
quale = h.get_simulation_status_at(0); //stato iniziale
@ -202,7 +202,7 @@ main(int argc, char* argv[])
//************** TEST QUEUE
/* cout << "\n\nTEST QUEUE\n";
SchedulableQueue sq;
ReadyQueue sq;
sq.add_at_bottom(ss1);
sq.add_at_bottom(ss2);
sq.add_at_bottom(ss3);

View File

@ -100,7 +100,7 @@ Simulation::run() throw(UserInterruptException)
{
// chech for termination
bool all_term = true;
smart_ptr<SchedulableQueue> left = h.get_simulation_status_at(h.get_current_time());
smart_ptr<ReadyQueue> left = h.get_simulation_status_at(h.get_current_time());
for(uint i = 0; i < left->size(); i++)
if (left->get_item_at(i)->get_state() != DynamicSchedulable::state_terminated)
{
@ -144,7 +144,7 @@ Simulation::run() throw(UserInterruptException)
{
// chech for termination
bool all_term = true;
smart_ptr<SchedulableQueue> left = h.get_simulation_status_at(h.get_current_time());
smart_ptr<ReadyQueue> left = h.get_simulation_status_at(h.get_current_time());
for(uint i = 0; i < left->size(); i++)
if (left->get_item_at(i)->get_state() != DynamicSchedulable::state_terminated)
{

View File

@ -31,9 +31,9 @@ using namespace sgpem;
smart_ptr<DynamicSchedulable> scheduled_at = smart_ptr<DynamicSchedulable>();
if (0 <= time && time <= _total_time_elapsed)
{
smart_ptr<SchedulableQueue> sl = get_simulation_status_at(time);
smart_ptr<ReadyQueue> sl = get_simulation_status_at(time);
bool found = false;
bool invalid = sl == smart_ptr<SchedulableQueue>();
bool invalid = sl == smart_ptr<ReadyQueue>();
for (uint i = 0; !found && !invalid && i < sl->size(); i++)
{
const DynamicSchedulable* ss = sl->get_item_at(i);
@ -48,19 +48,19 @@ using namespace sgpem;
}
memory::smart_ptr<sgpem::SchedulableQueue>
memory::smart_ptr<sgpem::ReadyQueue>
History::get_simulation_status_at(int time) const
{
using namespace memory;
smart_ptr<SchedulableQueue> simulation_status_at = smart_ptr<SchedulableQueue>();
smart_ptr<ReadyQueue> simulation_status_at = smart_ptr<ReadyQueue>();
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>
simulation_status_at = memory::smart_ptr<ReadyQueue>
(
new SchedulableQueue
new ReadyQueue
(
*(_slice->get_simulation_status())
)
@ -78,7 +78,7 @@ using namespace sgpem;
void
History::enqueue_slice(const sgpem::SchedulableQueue& status)
History::enqueue_slice(const sgpem::ReadyQueue& status)
{
_slice = memory::smart_ptr<Slice>(new Slice(_total_time_elapsed, 1, status));
_total_time_elapsed++;

View File

@ -24,7 +24,7 @@
#include "backend/observed_subject.hh"
#include "backend/slice.hh"
#include "backend/schedulable_queue.hh"
#include "backend/ready_queue.hh"
#include "templates/smartp.tcc"
#include <iostream>
@ -69,7 +69,7 @@ namespace sgpem
/** Returns the last recorded instant, but may raise an error.
*/
memory::smart_ptr<sgpem::SchedulableQueue>
memory::smart_ptr<sgpem::ReadyQueue>
get_simulation_status_at(int time) const;
@ -82,7 +82,7 @@ namespace sgpem
/** Extends the recorded history by one unit, overwriting the old value
*/
void
enqueue_slice(const sgpem::SchedulableQueue& status);
enqueue_slice(const sgpem::ReadyQueue& status);
/** STUB: THIS FEATURE IS NOT AVAILABLE

View File

@ -33,7 +33,7 @@
#include <iostream>
#include "backend/static_process.hh"
#include "backend/observed_subject.hh"
#include "backend/schedulable_queue.hh"
#include "backend/ready_queue.hh"
#include "backend/dynamic_schedulable.hh"
#include "templates/smartp.tcc"
#include "backend/user_interrupt_exception.hh"

View File

@ -53,7 +53,7 @@ PRRPolicy::configure()
PRRPolicy::sort_queue() const
throw(UserInterruptException)
{
SchedulableQueue* local_sl = Scheduler::get_instance().get_ready_queue();
ReadyQueue* 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

View File

@ -23,7 +23,7 @@
#include "backend/policy.hh"
#include "backend/user_interrupt_exception.hh"
#include "backend/schedulable_queue.hh"
#include "backend/ready_queue.hh"
#include "backend/scheduler.hh"
#include "glibmm/ustring.h"

View File

@ -36,7 +36,7 @@
#include "backend/static_process.hh"
#include "backend/slice.hh"
#include "backend/observed_subject.hh"
#include "backend/schedulable_queue.hh"
#include "backend/ready_queue.hh"
#include "backend/dynamic_schedulable.hh"
#include "templates/smartp.tcc"
@ -54,8 +54,8 @@ class HistoryTester
public:
HistoryTester(SchedulableQueue sl)
: _history_length(-1), _internal_schedulable_queue(sl)
HistoryTester(ReadyQueue sl)
: _history_length(-1), _internal_ready_queue(sl)
{}
/** this method gets a sequence of operations as a parameter and performs them
@ -73,10 +73,10 @@ public:
switch(commands_sequence[i])
{
case 'E':
_insert(_internal_schedulable_queue);
_insert(_internal_ready_queue);
break;
case 'R':
_randomize(_internal_schedulable_queue);
_randomize(_internal_ready_queue);
break;
case 'T':
_truncate();
@ -92,9 +92,9 @@ public:
private:
int _history_length; // mirrors the correct length of the history
SchedulableQueue* _get_simulation_status_at[400]; // mirrors the correct content of the history
ReadyQueue* _get_simulation_status_at[400]; // mirrors the correct content of the history
DynamicSchedulable* _get_scheduled_at[400]; // mirrors the correct content of the history
SchedulableQueue _internal_schedulable_queue;
ReadyQueue _internal_ready_queue;
// looks for anomalies
@ -131,13 +131,13 @@ private:
}
// saves the given SchedulableQueue into the history, and saves a copy of it into an array
void _insert(sgpem::SchedulableQueue& status)
// saves the given ReadyQueue into the history, and saves a copy of it into an array
void _insert(sgpem::ReadyQueue& status)
{
History::get_instance().enqueue_slice(status);
_history_length = _history_length + 1;
_get_simulation_status_at[_history_length] = new SchedulableQueue(status);
_get_simulation_status_at[_history_length] = new ReadyQueue(status);
if (History::get_instance().get_scheduled_at(_history_length) != memory::smart_ptr<DynamicSchedulable>(NULL))
_get_scheduled_at[_history_length] = new DynamicSchedulable(*(History::get_instance().get_scheduled_at(_history_length)));
@ -147,8 +147,8 @@ private:
}
// modifies the given SchedulableQueue object in an arbitrary way.
void _randomize(sgpem::SchedulableQueue& status)
// modifies the given ReadyQueue object in an arbitrary way.
void _randomize(sgpem::ReadyQueue& status)
{
status.swap(9, 10);
status.swap(1, 16);
@ -251,7 +251,7 @@ main(int argc, char** argv)
DynamicSchedulable ss18(p18);
DynamicSchedulable ss19(p19); // not used!
SchedulableQueue initial;
ReadyQueue initial;
initial.add_at_bottom(ss1);
initial.add_at_bottom(ss2);
initial.add_at_bottom(ss3);

View File

@ -38,7 +38,7 @@
#include "backend/static_process.hh"
#include "backend/slice.hh"
#include "backend/observed_subject.hh"
#include "backend/schedulable_queue.hh"
#include "backend/ready_queue.hh"
#include "backend/dynamic_schedulable.hh"
#include "smartp.tcc"
@ -57,7 +57,7 @@ namespace sgpem
std::cout << "get_scheduled_at" << time;
return History::get_scheduled_at(time);
}
memory::smart_ptr<sgpem::SchedulableQueue> get_simulation_status_at(int time) const
memory::smart_ptr<sgpem::ReadyQueue> get_simulation_status_at(int time) const
{
std::cout << "get_simulation_status_at" << time;
return History::get_simulation_status_at(time);
@ -67,7 +67,7 @@ namespace sgpem
std::cout << "getCurrentTime";
return History::get_current_time();
}
void enqueue_slice(const sgpem::SchedulableQueue& status)
void enqueue_slice(const sgpem::ReadyQueue& status)
{
std::cout << "enqueue_slice";
History::enqueue_slice(status);

View File

@ -33,7 +33,7 @@
#include <iostream>
#include "backend/static_process.hh"
#include "backend/observed_subject.hh"
#include "backend/schedulable_queue.hh"
#include "backend/ready_queue.hh"
#include "backend/dynamic_schedulable.hh"
#include "scheduler.hh"
@ -81,7 +81,7 @@ namespace sgpem
virtual void sort_queue() const throw(UserInterruptException)
{ // here a lot of fun, exactly O(n^2) fun!
SchedulableQueue sl = History.get_instance().get_simulation_status_at(get_current_time());
ReadyQueue sl = History.get_instance().get_simulation_status_at(get_current_time());
for (int i = 0; i < sl.size(); i++)
{
for (int j = 0; j < sl.size() - 1; j++)
@ -184,9 +184,9 @@ namespace sgpem
public:
memory::smart_ptr<sgpem::DynamicSchedulable> get_scheduled_at(int time) const {}
memory::smart_ptr<sgpem::SchedulableQueue> get_simulation_status_at(int time) const;
memory::smart_ptr<sgpem::ReadyQueue> get_simulation_status_at(int time) const;
int get_current_time() const {return _total_time_elapsed;}
void enqueue_slice(const sgpem::SchedulableQueue& status);
void enqueue_slice(const sgpem::ReadyQueue& status);
void truncate_at(int instant) {}
static History& get_instance();
private:
@ -270,7 +270,7 @@ main(int argc, char** argv)
DynamicSchedulable ss18(p18);
DynamicSchedulable ss19(p19); // not used!
SchedulableQueue initial;
ReadyQueue initial;
initial.add_at_bottom(ss1);
initial.add_at_bottom(ss2);
initial.add_at_bottom(ss3);

View File

@ -442,7 +442,7 @@ TextSimulation::update()
ustring temp;
when = h.get_current_time();
smart_ptr<SchedulableQueue> ll = h.get_simulation_status_at(when);
smart_ptr<ReadyQueue> ll = h.get_simulation_status_at(when);
for (uint dev = 0; dev < _devices.size(); dev++)
{