- Added the Schedulable interface

- Renamed SchedulableStatus to DynamicSchedulable
- Implemented almost all methods of DynamicSchedulable

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@630 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-06-13 16:37:57 +00:00
parent 94c0b563c7
commit a1662de194
22 changed files with 492 additions and 239 deletions

View File

@ -142,6 +142,7 @@ src_backend_libbackend_la_LDFLAGS = \
# Please keep this in sorted order:
src_backend_libbackend_la_SOURCES = \
src/backend/dynamic_schedulable.cc \
src/backend/global_preferences.cc \
src/backend/history.cc \
src/backend/observed_subject.cc \
@ -149,17 +150,18 @@ src_backend_libbackend_la_SOURCES = \
src/backend/policy.cc \
src/backend/policy_manager.cc \
src/backend/policy_parameters.cc \
src/backend/static_process.cc \
src/backend/static_schedulable.cc \
src/backend/schedulable.cc \
src/backend/schedulable_queue.cc \
src/backend/schedulable_status.cc \
src/backend/scheduler.cc \
src/backend/slice.cc \
src/backend/static_process.cc \
src/backend/static_schedulable.cc \
src/backend/string_utils.cc \
src/backend/user_interrupt_exception.cc
pkginclude_HEADERS = \
config.h \
src/backend/dynamic_schedulable.hh \
src/backend/global_preferences.hh \
src/backend/history.hh \
src/backend/observed_subject.hh \
@ -168,12 +170,12 @@ pkginclude_HEADERS = \
src/backend/policy.hh \
src/backend/policy_manager.hh \
src/backend/policy_parameters.hh \
src/backend/static_process.hh \
src/backend/static_schedulable.hh \
src/backend/schedulable.hh \
src/backend/schedulable_queue.hh \
src/backend/schedulable_status.hh \
src/backend/scheduler.hh \
src/backend/slice.hh \
src/backend/static_process.hh \
src/backend/static_schedulable.hh \
src/backend/string_utils.hh \
src/backend/user_interrupt_exception.hh

View File

@ -120,7 +120,7 @@ class Policy:
# of the following ways:
# @code
# # As a lambda anonymous function (preferred)
# # (x and y are two SchedulableStatus objects)
# # (x and y are two DynamicSchedulable objects)
# cmpf = lambda x,y: x.someProperty() < y.someProperty()
#
# # As a normal *global* function

View File

@ -4,7 +4,7 @@
#include "policy_parameters.hh"
#include "static_schedulable.hh"
#include "schedulable_queue.hh"
#include "schedulable_status.hh"
#include "dynamic_schedulable.hh"
#include "scheduler.hh"
%}
@ -152,7 +152,7 @@ namespace sgpem {
{
public:
unsigned int size() const;
const sgpem::SchedulableStatus* get_item_at(const unsigned int&) const;
const sgpem::DynamicSchedulable* get_item_at(const unsigned int&) const;
void swap(unsigned int positionA, unsigned int positionB) throw();
private:
@ -164,7 +164,7 @@ namespace sgpem {
}; //~ class Schedulable
// ---------------------------------------------
class SchedulableStatus
class DynamicSchedulable
{
public:
enum state
@ -176,7 +176,7 @@ namespace sgpem {
state_terminated = 1<<4
};
SchedulableStatus(const SchedulableStatus& obj);
DynamicSchedulable(const DynamicSchedulable& obj);
int get_cpu_time_left() const;
int get_last_scheduled() const;

View File

@ -0,0 +1,177 @@
// src/backend/dynamic_schedulable.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 "dynamic_schedulable.hh"
using namespace sgpem;
using namespace std;
DynamicSchedulable::DynamicSchedulable(StaticSchedulable& obj) :
_time_left(obj.get_total_cpu_time()), _ref(&obj), _last_acquisition(-1),
_last_release(-1), _current_priority(obj.get_priority()), _last(-1),
_my_state(state_future)
{
}
bool
DynamicSchedulable::operator==(const DynamicSchedulable& dx) const
{
return (_ref==dx._ref)&&(_last==dx._last)&&(_time_left==dx._time_left)&&(_my_state==dx._my_state);
}
Glib::ustring
DynamicSchedulable::get_name() const
{
return _ref->get_name();
}
void
DynamicSchedulable::set_name(const Glib::ustring& new_name)
{
_ref->set_name(new_name);
}
unsigned int
DynamicSchedulable::get_arrival_time() const
{
return _ref->get_arrival_time();
}
void
DynamicSchedulable::set_arrival_time(unsigned int new_time)
{
_ref->set_arrival_time(new_time);
}
int
DynamicSchedulable::get_base_priority() const
{
return _ref->get_priority();
}
void
DynamicSchedulable::set_base_priority(int new_priority)
{
_ref->set_priority(new_priority);
}
unsigned int
DynamicSchedulable::get_total_cpu_time() const
{
return _ref->get_total_cpu_time();
}
int
DynamicSchedulable::get_current_priority() const
{
return _current_priority;
}
void
DynamicSchedulable::set_current_priority(int new_priority)
{
_current_priority = new_priority;
}
unsigned int
DynamicSchedulable::get_remaining_time() const
{
return _time_left;
}
void
DynamicSchedulable::decrease_remaining_time()
{
--_time_left;
}
int
DynamicSchedulable::get_last_acquisition() const
{
return _last_acquisition;
}
void
DynamicSchedulable::set_last_acquisition(int instant)
{
_last_acquisition = instant;
}
int
DynamicSchedulable::get_last_release() const
{
return _last_release;
}
void
DynamicSchedulable::set_last_release(int instant)
{
_last_release = instant;
}
void
DynamicSchedulable::serialize(SerializeVisitor& translator) const
{
//TODO write me as part of the serialization infrastructure
}
int
DynamicSchedulable::get_cpu_time_left() const
{
return _time_left;
}
void
DynamicSchedulable::give_cpu_time(const int& time)
{
_time_left -= time;
if (_time_left < 0)
_time_left = 0;
}
void
DynamicSchedulable::set_last_scheduled(const int& time)
{
_last = time;
}
int
DynamicSchedulable::get_last_scheduled() const
{
return _last;
}
DynamicSchedulable::state
DynamicSchedulable::get_state() const
{
return _my_state;
}
void
DynamicSchedulable::set_state(state s)
{
_my_state = s;
}
StaticSchedulable*
DynamicSchedulable::get_schedulable() const
{
return _ref;
}

View File

@ -1,4 +1,4 @@
// src/backend/schedulable_status.hh - Copyright 2005, 2006, University
// src/backend/dynamic_schedulable.hh - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
@ -18,15 +18,16 @@
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef SCHEDULABLESTATUS_HH
#define SCHEDULABLESTATUS_HH 1
#ifndef DYNAMIC_SCHEDULABLE_HH
#define DYNAMIC_SCHEDULABLE_HH 1
#include "config.h"
#include "schedulable.hh"
#include "static_schedulable.hh"
namespace sgpem
{
class SchedulableStatus;
class DynamicSchedulable;
/** \brief Desribes the state of a schedulable entity in a particular moment
* of the simulation
@ -34,32 +35,16 @@ namespace sgpem
* This class stores part of the information deeded by the Scheduler to
* manage processes and other ones.
*
* Objects of type SchedulableStatus are created by the Scheduler and are
* Objects of type DynamicSchedulable are created by the Scheduler and are
* destroyed by SimulationStatus if they are linked to it or by the Scheduler.
*/
class SG_DLLEXPORT SchedulableStatus
class SG_DLLEXPORT DynamicSchedulable : public Schedulable
{
public:
/** \brief This flag describes the actual state of the schedulable
*
* You can think of this flag as the particular stack in the OS where the
* process are placed during their lifetime. In the OS there are three
* main stacks that are Running processes, Read processes, and Blocked
* processes. These are emulated in a single list by this flag.
*/
enum state
{
state_running = 1<<0,
state_ready = 1<<1,
state_blocked = 1<<2,
state_future = 1<<3,
state_terminated = 1<<4
};
/** \brief Object constructor */
SchedulableStatus(const StaticSchedulable& obj);
DynamicSchedulable(StaticSchedulable& obj);
//SchedulableStatus(const SchedulableStatus& obj); //copy constructor
//DynamicSchedulable(const DynamicSchedulable& obj); //copy constructor
/** \brief Verify if two instances represents the same situation
*
@ -67,7 +52,44 @@ namespace sgpem
* actual represented process is the same, and if the status is also the
* same.
*/
bool operator==(const SchedulableStatus&) const;
bool operator==(const DynamicSchedulable&) const;
Glib::ustring get_name() const;
void set_name(const Glib::ustring& new_name);
unsigned int get_arrival_time() const;
void set_arrival_time(unsigned int new_time);
int get_base_priority() const;
void set_base_priority(int new_priority);
unsigned int get_total_cpu_time() const;
int get_current_priority() const;
void set_current_priority(int new_priority);
unsigned int get_remaining_time() const;
void decrease_remaining_time();
int get_last_acquisition() const;
void set_last_acquisition(int instant);
int get_last_release() const;
void set_last_release(int instant);
void serialize(SerializeVisitor& translator) const;
/*
FIXME
all following methods are deprecated, drop them
*/
/** \brief Returns the remaining CPU time */
int get_cpu_time_left() const;
@ -86,7 +108,8 @@ namespace sgpem
state get_state() const;
/** \brief Sets the state of this process
* \see state */
* \see state
*/
void set_state(state s);
/** \brief Returns a pointer to the schedulable object
@ -94,12 +117,19 @@ namespace sgpem
* This function returns a pointer to the actual schedable object
* represented, along with its status, by this instance.
*/
const StaticSchedulable* get_schedulable() const;
StaticSchedulable* get_schedulable() const;
protected:
int _time_left;
private:
const StaticSchedulable* _ref;
StaticSchedulable* _ref;
int _last_acquisition;
int _last_release;
int _current_priority;
//FIXME deprecated stuff used by deprecated methods
int _last;
int _time_left;
state _my_state;
};
}

View File

@ -45,24 +45,24 @@ History::get_instance()
/**
Returns a pointer to a copy of the SchedulableStatus object relative to this instant.
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
*/
smart_ptr<SchedulableStatus>
smart_ptr<DynamicSchedulable>
History::get_scheduled_at(int time) const
{
if (time > _total_time_elapsed || time < 0) //out of range
return smart_ptr<SchedulableStatus>(NULL);
return smart_ptr<DynamicSchedulable>(NULL);
//look for a runing entity
smart_ptr<SchedulableQueue> p = get_simulation_status_at(time);
for (uint i = 0; i < p->size(); i++)
if (p->get_item_at(i)->get_state() == SchedulableStatus::state_running)
return smart_ptr<SchedulableStatus>(new SchedulableStatus(*(p->get_item_at(i))));
if (p->get_item_at(i)->get_state() == DynamicSchedulable::state_running)
return smart_ptr<DynamicSchedulable>(new DynamicSchedulable(*(p->get_item_at(i))));
return smart_ptr<SchedulableStatus>(NULL);
return smart_ptr<DynamicSchedulable>(NULL);
}
/**

View File

@ -29,7 +29,7 @@
#include "slice.hh"
#include "observed_subject.hh"
#include "schedulable_queue.hh"
#include "schedulable_status.hh"
#include "dynamic_schedulable.hh"
#include "../templates/smartp.hh"
namespace sgpem
@ -55,7 +55,7 @@ namespace sgpem
\param time The inquired time instant.
\return The Schedulable object running at the given time.
*/
virtual memory::smart_ptr<sgpem::SchedulableStatus> get_scheduled_at(int time) const;
virtual memory::smart_ptr<sgpem::DynamicSchedulable> get_scheduled_at(int time) const;
/**
Gets the status of simulation at the specified time.

View File

@ -0,0 +1,28 @@
// src/backend/schedulable.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.hh"
using namespace sgpem;
Schedulable::~Schedulable()
{
}

View File

@ -0,0 +1,71 @@
// src/backend/schedulable.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_HH
#define SCHEDULABLE_HH 1
#include "config.h"
#include "glibmm/ustring.h"
namespace sgpem
{
class Schedulable;
class SerializeVisitor;
class SG_DLLEXPORT Schedulable
{
public:
/** \brief This flag describes the actual state of the schedulable
*
* You can think of this flag as the particular stack in the OS where the
* process are placed during their lifetime. In the OS there are three
* main stacks that are Running processes, Read processes, and Blocked
* processes. These are emulated in a single list by this flag.
*/
enum state
{
state_running = 1<<0,
state_ready = 1<<1,
state_blocked = 1<<2,
state_future = 1<<3,
state_terminated = 1<<4
};
virtual ~Schedulable();
virtual Glib::ustring get_name() const = 0;
virtual unsigned int get_arrival_time() const = 0;
virtual unsigned int get_remaining_time() const = 0;
virtual int get_base_priority() const = 0;
virtual unsigned int get_total_cpu_time() const = 0;
virtual int get_current_priority() const = 0;
virtual state get_state() const = 0;
virtual void serialize(SerializeVisitor& translator) const = 0;
};
}
#endif

View File

@ -28,7 +28,7 @@ SchedulableQueue::SchedulableQueue()
{
}
SchedulableStatus*
DynamicSchedulable*
SchedulableQueue::top()
{
if (_list.size() == 0)
@ -36,7 +36,7 @@ SchedulableQueue::top()
return &_list.front();
}
SchedulableStatus*
DynamicSchedulable*
SchedulableQueue::bottom()
{
if (_list.size() == 0)
@ -50,25 +50,25 @@ SchedulableQueue::bottom()
DON'T call delete on the returned pointer! Its destruction is managed by the queue.
*/
SchedulableStatus*
DynamicSchedulable*
SchedulableQueue::get_item_at(const uint& where)
{
if (_list.size() == 0 || where >= _list.size())
return NULL;
list<SchedulableStatus>::iterator i = _list.begin();
list<DynamicSchedulable>::iterator i = _list.begin();
for (uint f=0; f < where; f++)
i++;
return &(*i);
}
const SchedulableStatus*
const DynamicSchedulable*
SchedulableQueue::get_item_at(const uint& where) const
{
if (_list.size() == 0 || where >= _list.size())
return NULL;
list<SchedulableStatus>::const_iterator i = _list.begin();
list<DynamicSchedulable>::const_iterator i = _list.begin();
for (uint f=0; f < where; f++)
i++;
return &(*i);
@ -85,25 +85,25 @@ SchedulableQueue::size() const
}
void
SchedulableQueue::add_at_top(const SchedulableStatus& ss)
SchedulableQueue::add_at_top(const DynamicSchedulable& ss)
{
_list.push_front(ss);
}
void
SchedulableQueue::add_at_bottom(const SchedulableStatus& ss)
SchedulableQueue::add_at_bottom(const DynamicSchedulable& ss)
{
_list.push_back(ss);
}
smart_ptr<SchedulableStatus>
smart_ptr<DynamicSchedulable>
SchedulableQueue::remove(const uint& position)
{
if (_list.size() == 0 || position >= _list.size())
return smart_ptr<SchedulableStatus>(NULL);
return smart_ptr<DynamicSchedulable>(NULL);
//creates a copy of the first element
smart_ptr<SchedulableStatus> sm = new SchedulableStatus(*top());
smart_ptr<DynamicSchedulable> sm = new DynamicSchedulable(*top());
//pops the first element
_list.pop_front();
//returns the copy
@ -123,15 +123,15 @@ SchedulableQueue::insert_at(const uint& which, const uint& where)
if (where == which)
return true;
list<SchedulableStatus>::iterator i_where = _list.begin();
list<SchedulableStatus>::iterator i_which = _list.begin();
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
SchedulableStatus temp = *i_which;
DynamicSchedulable temp = *i_which;
_list.erase(i_which);
//insert WHICH before WHERE
@ -151,7 +151,7 @@ SchedulableQueue::clear()
/**
\brief Returns TRUE if the two objects have the same SchedulableStatus objects in the same order.
\brief Returns TRUE if the two objects have the same DynamicSchedulable objects in the same order.
*/
bool
SchedulableQueue::operator==(const SchedulableQueue& dx) const
@ -161,7 +161,7 @@ SchedulableQueue::operator==(const SchedulableQueue& dx) const
/**
\brief Returns TRUE if the two objects have the same SchedulableStatus objects with NO ORDER IMPORTANCE.
\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
@ -170,7 +170,7 @@ SchedulableQueue::has_same_objects(const SchedulableQueue& dx) const
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++)
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;
@ -196,13 +196,13 @@ SchedulableQueue::swap(unsigned int positionA, unsigned int positionB) throw()
max = positionA;
}
list<SchedulableStatus>::iterator i1 = _list.begin();
list<SchedulableStatus>::iterator i2 = _list.begin();
list<DynamicSchedulable>::iterator i1 = _list.begin();
list<DynamicSchedulable>::iterator i2 = _list.begin();
//reach the first element;
for (uint f=0; f < min; f++)
i1++;
SchedulableStatus temp = *i1;
DynamicSchedulable temp = *i1;
//reach the second element;
i2 = i1;

View File

@ -25,7 +25,7 @@
#include <list>
#include "schedulable_status.hh"
#include "dynamic_schedulable.hh"
#include "../templates/smartp.hh"
@ -48,18 +48,18 @@ namespace sgpem
* It is very important not to delete these pointers as their deallocation
* is managed by the queue.
*/
SchedulableStatus* top();
DynamicSchedulable* top();
/** \brief Returns a pointer to the last element
* \see top
*/
SchedulableStatus* bottom();
DynamicSchedulable* bottom();
/** \brief Adds an element at the top of the queue */
void add_at_top(const SchedulableStatus&);
void add_at_top(const DynamicSchedulable&);
/** \brief Adds an element at the end of the queue */
void add_at_bottom(const SchedulableStatus&);
void add_at_bottom(const DynamicSchedulable&);
/** \brief Removes */
/**
@ -70,11 +70,11 @@ namespace sgpem
Ex. remove(size()-1) removes the bottom of the list
*/
memory::smart_ptr<sgpem::SchedulableStatus> remove(const unsigned int& position);
memory::smart_ptr<sgpem::DynamicSchedulable> remove(const unsigned int& position);
bool insert_at(const unsigned int&, const unsigned int&);
unsigned int size() const;
SchedulableStatus* get_item_at(const uint&);
const SchedulableStatus* get_item_at(const uint&) 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
@ -94,7 +94,7 @@ namespace sgpem
void swap(unsigned int positionA, unsigned int positionB) throw();
private:
std::list<SchedulableStatus> _list;
std::list<DynamicSchedulable> _list;
};
}

View File

@ -1,80 +0,0 @@
// src/backend/schedulable_status.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_status.hh"
using namespace sgpem;
using namespace std;
SchedulableStatus::SchedulableStatus(const StaticSchedulable& obj) :
_ref(&obj), _last(-1), _time_left(obj.get_total_cpu_time()),
_my_state(state_future)
{
}
bool
SchedulableStatus::operator==(const SchedulableStatus& dx) const
{
return (_ref==dx._ref)&&(_last==dx._last)&&(_time_left==dx._time_left)&&(_my_state==dx._my_state);
}
int
SchedulableStatus::get_cpu_time_left() const
{
return _time_left;
}
void
SchedulableStatus::give_cpu_time(const int& time)
{
_time_left -= time;
if (_time_left < 0)
_time_left = 0;
}
void
SchedulableStatus::set_last_scheduled(const int& time)
{
_last = time;
}
int
SchedulableStatus::get_last_scheduled() const
{
return _last;
}
SchedulableStatus::state
SchedulableStatus::get_state() const
{
return _my_state;
}
void
SchedulableStatus::set_state(state s)
{
_my_state = s;
}
const StaticSchedulable*
SchedulableStatus::get_schedulable() const
{
return _ref;
}

View File

@ -101,18 +101,18 @@ Scheduler::step_forward() throw(UserInterruptException)
//adds running schedulable
smart_ptr<SchedulableStatus> running_ptr = h.get_scheduled_at(h.get_current_time());
smart_ptr<DynamicSchedulable> running_ptr = h.get_scheduled_at(h.get_current_time());
if (running_ptr)
_ready_queue.add_at_top(*running_ptr);
//adds the READY ones
for(uint rea=0; rea < initial->size(); rea++)
if (initial->get_item_at(rea)->get_state() == SchedulableStatus::state_ready)
if (initial->get_item_at(rea)->get_state() == DynamicSchedulable::state_ready)
_ready_queue.add_at_bottom(*initial->get_item_at(rea));
//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_future
if (initial->get_item_at(i)->get_state() == DynamicSchedulable::state_future
&& (int)initial->get_item_at(i)->get_schedulable()->get_arrival_time() == h.get_current_time())
{
//cout << "\nnuovo running: " << initial->get_item_at(i)->get_schedulable()->get_name();
@ -123,8 +123,8 @@ Scheduler::step_forward() throw(UserInterruptException)
//adds the NEW one
_ready_queue.add_at_bottom(*initial->get_item_at(i));
_ready_queue.get_item_at(_ready_queue.size()-1)->set_state(SchedulableStatus::state_ready);
initial->get_item_at(i)->set_state(SchedulableStatus::state_ready);
_ready_queue.get_item_at(_ready_queue.size()-1)->set_state(DynamicSchedulable::state_ready);
initial->get_item_at(i)->set_state(DynamicSchedulable::state_ready);
// Sort the queue
policy.sort_queue();
@ -147,7 +147,7 @@ Scheduler::step_forward() throw(UserInterruptException)
{
_ready_queue.add_at_bottom(*_ready_queue.get_item_at(i));
_ready_queue.remove(i);
_ready_queue.get_item_at(_ready_queue.size()-1)->set_state(SchedulableStatus::state_terminated);
_ready_queue.get_item_at(_ready_queue.size()-1)->set_state(DynamicSchedulable::state_terminated);
break;
}
//cout << "\nTERMINATO!!";
@ -168,24 +168,24 @@ Scheduler::step_forward() throw(UserInterruptException)
//******************
if (_ready_queue.size() != 0 && (_ready_queue.get_item_at(0)->get_state() == SchedulableStatus::state_ready
|| _ready_queue.get_item_at(0)->get_state() == SchedulableStatus::state_running))
if (_ready_queue.size() != 0 && (_ready_queue.get_item_at(0)->get_state() == DynamicSchedulable::state_ready
|| _ready_queue.get_item_at(0)->get_state() == DynamicSchedulable::state_running))
{
//the first ready element IS the running one (if != *running_ptr then there is a CONTEXT SWICH)
_ready_queue.get_item_at(0)->set_state(SchedulableStatus::state_running);
_ready_queue.get_item_at(0)->set_state(DynamicSchedulable::state_running);
_ready_queue.get_item_at(0)->give_cpu_time(1);
}
//all the others are ready
for (uint i = 1; i < _ready_queue.size(); i++)
if (_ready_queue.get_item_at(i)->get_state() == SchedulableStatus::state_running)
_ready_queue.get_item_at(i)->set_state(SchedulableStatus::state_ready);
if (_ready_queue.get_item_at(i)->get_state() == DynamicSchedulable::state_running)
_ready_queue.get_item_at(i)->set_state(DynamicSchedulable::state_ready);
//append blocked, future, and terminated 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)
if(initial->get_item_at(i)->get_state() == DynamicSchedulable::state_blocked
|| initial->get_item_at(i)->get_state() == DynamicSchedulable::state_future
|| initial->get_item_at(i)->get_state() == DynamicSchedulable::state_terminated)
_ready_queue.add_at_bottom(*initial->get_item_at(i));
cout << "\n";

View File

@ -41,14 +41,14 @@ namespace sgpem
{
class Scheduler;
/** \brief Manages the SchedulableStatus objects, implementing a given policy.
/** \brief Manages the DynamicSchedulable objects, implementing a given policy.
Class Scheduler manages the schedulable entities which are ready to run,
ordering them in a queue; it also checks that the current scheduling policy
is well-defined and does not disrupt the application inner mechanism.
It is also responsible for the creation and the destruction of some of
the SchedulableStatus objects (for further details about this, check
class SchedulableStatus).
the DynamicSchedulable objects (for further details about this, check
class DynamicSchedulable).
*/

View File

@ -40,6 +40,11 @@ StaticSchedulable::get_arrival_time() const
return _arrival_time;
}
void
StaticSchedulable::set_arrival_time(unsigned int new_time)
{
_arrival_time = new_time;
}
unsigned int
StaticSchedulable::get_total_cpu_time() const
@ -54,9 +59,20 @@ StaticSchedulable::get_priority() const
return _priority;
}
void
StaticSchedulable::set_priority(int new_priority)
{
_priority = new_priority;
}
Glib::ustring
StaticSchedulable::get_name() const
{
return _name;
}
void
StaticSchedulable::set_name(const Glib::ustring& new_name)
{
_name = new_name;
}

View File

@ -36,7 +36,7 @@ namespace sgpem
* For a reference of a schedulable among its current status see referenced
* class.
*
* \see SchedulableStatus
* \see DynamicSchedulable
*/
class SG_DLLEXPORT StaticSchedulable
{
@ -53,6 +53,11 @@ namespace sgpem
*/
virtual unsigned int get_arrival_time() const;
/**
FIXME make me pure virtual when StaticProcess and StaticThread are completed
*/
void set_arrival_time(unsigned int new_time);
/** \brief Returns the amount of CPU time this process is going to require */
unsigned int get_total_cpu_time() const;
@ -63,6 +68,8 @@ namespace sgpem
*/
int get_priority() const;
void set_priority(int new_priority);
/** \brief Returns a string representing this object
*
* The name of a process is a human readable string assigned to it by the
@ -70,6 +77,8 @@ namespace sgpem
*/
Glib::ustring get_name() const;
void set_name(const Glib::ustring& new_name);
/** \brief Returns the type of the process
*
* This is an abstract method as the schedulable type is defined by the

View File

@ -29,7 +29,7 @@
#include "backend/history.hh"
#include "backend/static_schedulable.hh"
#include "backend/schedulable_queue.hh"
#include "backend/schedulable_status.hh"
#include "backend/dynamic_schedulable.hh"
#include "backend/slice.hh"
#include "backend/static_process.hh"
#include "backend/policy.hh"
@ -112,12 +112,12 @@ main(int argc, char* argv[])
StaticProcess p5("P5", 1,2,3);
StaticProcess p6("P6", 10,2,1);
SchedulableStatus ss1(p1);
SchedulableStatus ss2(p2);
SchedulableStatus ss3(p3);
SchedulableStatus ss4(p4);
SchedulableStatus ss5(p5);
SchedulableStatus ss6(p6);
DynamicSchedulable ss1(p1);
DynamicSchedulable ss2(p2);
DynamicSchedulable ss3(p3);
DynamicSchedulable ss4(p4);
DynamicSchedulable ss5(p5);
DynamicSchedulable ss6(p6);
SchedulableQueue initial;
initial.add_at_bottom(ss1);
@ -166,7 +166,7 @@ main(int argc, char* argv[])
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);
smart_ptr<const sgpem::DynamicSchedulable> quale2 = h.get_scheduled_at(1);
cout << quale2->get_schedulable()->get_name();
h.truncate_at(0);
@ -186,7 +186,7 @@ main(int argc, char* argv[])
h.truncate_at(2);
smart_ptr<const sgpem::SchedulableStatus> quale2;
smart_ptr<const sgpem::DynamicSchedulable> quale2;
quale2 = h.get_scheduled_at(0);
if (quale2) cout << "\n" << quale2->get_schedulable()->get_name(); else cout << "NO";
quale2 = h.get_scheduled_at(1);

View File

@ -100,7 +100,7 @@ Simulation::run() throw(UserInterruptException)
bool all_term = true;
smart_ptr<SchedulableQueue> 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() != SchedulableStatus::state_terminated)
if (left->get_item_at(i)->get_state() != DynamicSchedulable::state_terminated)
{
all_term = false;
break;
@ -143,7 +143,7 @@ Simulation::run() throw(UserInterruptException)
bool all_term = true;
smart_ptr<SchedulableQueue> 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() != SchedulableStatus::state_terminated)
if (left->get_item_at(i)->get_state() != DynamicSchedulable::state_terminated)
{
all_term = false;
break;

View File

@ -36,7 +36,7 @@
#include "backend/slice.hh"
#include "backend/observed_subject.hh"
#include "backend/schedulable_queue.hh"
#include "backend/schedulable_status.hh"
#include "backend/dynamic_schedulable.hh"
#include "templates/smartp.hh"
using namespace sgpem;
@ -83,7 +83,7 @@ public:
int _history_length; // mirrors the correct length of the history
SchedulableQueue* _get_simulation_status_at[400]; // mirrors the correct content of the history
SchedulableStatus* _get_scheduled_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;
@ -104,7 +104,7 @@ public:
{
std::cout << "get_simulation_status_at";
}
if (History::get_instance().get_scheduled_at(i) != memory::smart_ptr<SchedulableStatus>(NULL) && !(*History::get_instance().get_scheduled_at(i) == *_get_scheduled_at[i]))
if (History::get_instance().get_scheduled_at(i) != memory::smart_ptr<DynamicSchedulable>(NULL) && !(*History::get_instance().get_scheduled_at(i) == *_get_scheduled_at[i]))
{
std::cout << "get_simulation_status_at";
}
@ -121,8 +121,8 @@ public:
_history_length = _history_length + 1;
_get_simulation_status_at[_history_length] = new SchedulableQueue(status);
if (History::get_instance().get_scheduled_at(_history_length) != memory::smart_ptr<SchedulableStatus>(NULL))
_get_scheduled_at[_history_length] = new SchedulableStatus(*(status.top()));
if (History::get_instance().get_scheduled_at(_history_length) != memory::smart_ptr<DynamicSchedulable>(NULL))
_get_scheduled_at[_history_length] = new DynamicSchedulable(*(status.top()));
else
_get_scheduled_at[_history_length] = NULL;
return;
@ -149,7 +149,7 @@ public:
{
status.get_item_at(i)->give_cpu_time(i%2);
status.get_item_at(i)->set_last_scheduled(_history_length%30);
status.get_item_at(i)->set_state(i%2 ? SchedulableStatus::state_running : SchedulableStatus::state_ready);
status.get_item_at(i)->set_state(i%2 ? DynamicSchedulable::state_running : DynamicSchedulable::state_ready);
}
return;
}
@ -212,25 +212,25 @@ main(int argc, char** argv)
StaticProcess p19("PK", 10,24,17);
StaticProcess p20("PK2", 11,34,67); // not used!
SchedulableStatus ss1(p1);
SchedulableStatus ss2(p2);
SchedulableStatus ss3(p3);
SchedulableStatus ss4(p4);
SchedulableStatus ss5(p5);
SchedulableStatus ss6(p6);
SchedulableStatus ss7(p7);
SchedulableStatus ss8(p8);
SchedulableStatus ss9(p9);
SchedulableStatus ss10(p10);
SchedulableStatus ss11(p11);
SchedulableStatus ss12(p12);
SchedulableStatus ss13(p13);
SchedulableStatus ss14(p14);
SchedulableStatus ss15(p15);
SchedulableStatus ss16(p16);
SchedulableStatus ss17(p17);
SchedulableStatus ss18(p18);
SchedulableStatus ss19(p19); // not used!
DynamicSchedulable ss1(p1);
DynamicSchedulable ss2(p2);
DynamicSchedulable ss3(p3);
DynamicSchedulable ss4(p4);
DynamicSchedulable ss5(p5);
DynamicSchedulable ss6(p6);
DynamicSchedulable ss7(p7);
DynamicSchedulable ss8(p8);
DynamicSchedulable ss9(p9);
DynamicSchedulable ss10(p10);
DynamicSchedulable ss11(p11);
DynamicSchedulable ss12(p12);
DynamicSchedulable ss13(p13);
DynamicSchedulable ss14(p14);
DynamicSchedulable ss15(p15);
DynamicSchedulable ss16(p16);
DynamicSchedulable ss17(p17);
DynamicSchedulable ss18(p18);
DynamicSchedulable ss19(p19); // not used!
SchedulableQueue initial;
initial.add_at_bottom(ss1);

View File

@ -40,7 +40,7 @@
#include "backend/slice.hh"
#include "backend/observed_subject.hh"
#include "backend/schedulable_queue.hh"
#include "backend/schedulable_status.hh"
#include "backend/dynamic_schedulable.hh"
namespace sgpem
{
@ -51,7 +51,7 @@ namespace sgpem
class TestHistory : public History
{
public:
memory::smart_ptr<sgpem::SchedulableStatus> get_scheduled_at(int time)
memory::smart_ptr<sgpem::DynamicSchedulable> get_scheduled_at(int time)
{
std::cout << "get_scheduled_at" << time;
return History::get_scheduled_at(time);

View File

@ -34,7 +34,7 @@
#include "backend/static_process.hh"
#include "backend/observed_subject.hh"
#include "backend/schedulable_queue.hh"
#include "backend/schedulable_status.hh"
#include "backend/dynamic_schedulable.hh"
#include "templates/smartp.hh"
#include "scheduler.hh"
@ -185,7 +185,7 @@ namespace sgpem
{
public:
memory::smart_ptr<sgpem::SchedulableStatus> get_scheduled_at(int time) const {}
memory::smart_ptr<sgpem::DynamicSchedulable> get_scheduled_at(int time) const {}
memory::smart_ptr<sgpem::SchedulableQueue> get_simulation_status_at(int time) const;
int get_current_time() const {return _total_time_elapsed;}
void enqueue_slice(const sgpem::SchedulableQueue& status);
@ -252,25 +252,25 @@ main(int argc, char** argv) {
StaticProcess p19("PK", 10,24,17);
StaticProcess p20("PK2", 11,34,67); // not used!
SchedulableStatus ss1(p1);
SchedulableStatus ss2(p2);
SchedulableStatus ss3(p3);
SchedulableStatus ss4(p4);
SchedulableStatus ss5(p5);
SchedulableStatus ss6(p6);
SchedulableStatus ss7(p7);
SchedulableStatus ss8(p8);
SchedulableStatus ss9(p9);
SchedulableStatus ss10(p10);
SchedulableStatus ss11(p11);
SchedulableStatus ss12(p12);
SchedulableStatus ss13(p13);
SchedulableStatus ss14(p14);
SchedulableStatus ss15(p15);
SchedulableStatus ss16(p16);
SchedulableStatus ss17(p17);
SchedulableStatus ss18(p18);
SchedulableStatus ss19(p19); // not used!
DynamicSchedulable ss1(p1);
DynamicSchedulable ss2(p2);
DynamicSchedulable ss3(p3);
DynamicSchedulable ss4(p4);
DynamicSchedulable ss5(p5);
DynamicSchedulable ss6(p6);
DynamicSchedulable ss7(p7);
DynamicSchedulable ss8(p8);
DynamicSchedulable ss9(p9);
DynamicSchedulable ss10(p10);
DynamicSchedulable ss11(p11);
DynamicSchedulable ss12(p12);
DynamicSchedulable ss13(p13);
DynamicSchedulable ss14(p14);
DynamicSchedulable ss15(p15);
DynamicSchedulable ss16(p16);
DynamicSchedulable ss17(p17);
DynamicSchedulable ss18(p18);
DynamicSchedulable ss19(p19); // not used!
SchedulableQueue initial;
initial.add_at_bottom(ss1);

View File

@ -390,7 +390,7 @@ TextSimulation::update()
_devices[dev]->write_buffer(temp + ") [RUNS]");
//insert the RUNNING ONE
smart_ptr<SchedulableStatus> running = h.get_scheduled_at(when);
smart_ptr<DynamicSchedulable> running = h.get_scheduled_at(when);
if (running)
{
arr = running->get_schedulable()->get_arrival_time();
@ -401,7 +401,7 @@ TextSimulation::update()
_devices[dev]->write_buffer(" --[READY]");
//insert the READY ones
for (uint i = 0; i < ll->size(); i++)
if (ll->get_item_at(i)->get_state() == SchedulableStatus::state_ready)
if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_ready)
{
arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time();
int_to_string(arr, temp);
@ -411,7 +411,7 @@ TextSimulation::update()
_devices[dev]->write_buffer(" --[BLOCKED]");
//insert the BLOCKED ones
for (uint i = 0; i < ll->size(); i++)
if (ll->get_item_at(i)->get_state() == SchedulableStatus::state_blocked)
if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_blocked)
{
arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time();
int_to_string(arr, temp);
@ -421,7 +421,7 @@ TextSimulation::update()
_devices[dev]->write_buffer(" --[FUTURE]");
//insert the FUTURE ones
for (uint i = 0; i < ll->size(); i++)
if (ll->get_item_at(i)->get_state() == SchedulableStatus::state_future)
if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_future)
{
arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time();
int_to_string(arr, temp);
@ -431,7 +431,7 @@ TextSimulation::update()
_devices[dev]->write_buffer(" --[TERM]");
//insert the TERMINATED ones
for (uint i = 0; i < ll->size(); i++)
if (ll->get_item_at(i)->get_state() == SchedulableStatus::state_terminated)
if (ll->get_item_at(i)->get_state() == DynamicSchedulable::state_terminated)
{
arr = ll->get_item_at(i)->get_schedulable()->get_arrival_time();
int_to_string(arr, temp);