Reformat using clang-format

This commit is contained in:
Matteo Settenvini 2018-09-25 10:20:45 +02:00
parent c1ac6f279b
commit ffd4b6b319
197 changed files with 13059 additions and 13569 deletions

View File

@ -22,191 +22,183 @@
#include <sgpemv2/templates/sequences.tcc>
#include <sgpemv2/history.hh>
#include <sgpemv2/environment.hh>
#include <sgpemv2/simulation.hh>
#include <sgpemv2/history.hh>
#include <sgpemv2/resource.hh>
#include <sgpemv2/simulation.hh>
#include "gettext.h"
#include <gtkmm/spinbutton.h>
#include <cassert>
#include <iostream>
#include <sstream>
#include <cassert>
using namespace sgpem;
using namespace Gtk;
using namespace Glib;
using std::vector;
AddRequestDialog::AddRequestDialog(BaseObjectType* cobject, const RefPtr<Builder>& ui) :
Dialog(cobject), _ui(ui)
AddRequestDialog::AddRequestDialog (BaseObjectType *cobject, const RefPtr<Builder> &ui) : Dialog (cobject), _ui (ui)
{
_ui->get_widget("SubRequests.View", _list);
_ui->get_widget("Add", _add_button);
_ui->get_widget("Remove", _remove_button);
_ui->get_widget("Resource.Combo", _resource_combo);
_ui->get_widget("OK.Button", _ok_button);
_ui->get_widget("Instant.Spin", _instant_spin);
_ui->get_widget("Duration.Spin", _duration_spin);
_ui->get_widget ("SubRequests.View", _list);
_ui->get_widget ("Add", _add_button);
_ui->get_widget ("Remove", _remove_button);
_ui->get_widget ("Resource.Combo", _resource_combo);
_ui->get_widget ("OK.Button", _ok_button);
_ui->get_widget ("Instant.Spin", _instant_spin);
_ui->get_widget ("Duration.Spin", _duration_spin);
/** ATTACH SIGNAL HANDLERS FOR BUTTONS **/
_add_button->signal_clicked().connect(
sigc::mem_fun(*this, &AddRequestDialog::_on_add));
_add_button->signal_clicked ().connect (sigc::mem_fun (*this, &AddRequestDialog::_on_add));
_remove_button->signal_clicked().connect(
sigc::mem_fun(*this, &AddRequestDialog::_on_remove));
_remove_button->signal_clicked ().connect (sigc::mem_fun (*this, &AddRequestDialog::_on_remove));
_ok_button->set_sensitive(false);
_remove_button->set_sensitive(false);
_add_button->set_sensitive(false);
_ok_button->set_sensitive (false);
_remove_button->set_sensitive (false);
_add_button->set_sensitive (false);
/** INITIALIZE COMBOBOX **/
_combo_columns.add(_combo_key_column);
_combo_columns.add(_combo_resource_column);
_combo_columns.add (_combo_key_column);
_combo_columns.add (_combo_resource_column);
_combo_model = ListStore::create(_combo_columns);
_resource_combo->set_model(_combo_model);
_resource_combo->pack_start(_combo_key_column, false);
_resource_combo->pack_start(_combo_resource_column, true);
_combo_model = ListStore::create (_combo_columns);
_resource_combo->set_model (_combo_model);
_resource_combo->pack_start (_combo_key_column, false);
_resource_combo->pack_start (_combo_resource_column, true);
_resource_combo->signal_changed().connect(
sigc::mem_fun(*this, &AddRequestDialog::_on_combo_selection_changed));
_resource_combo->signal_changed ().connect (sigc::mem_fun (*this, &AddRequestDialog::_on_combo_selection_changed));
/** INITIALIZE LISTVIEW **/
_list_columns.add(_list_key_column);
_list_columns.add(_list_resource_column);
_list_columns.add(_list_duration_column);
_list_columns.add (_list_key_column);
_list_columns.add (_list_resource_column);
_list_columns.add (_list_duration_column);
_list_model = ListStore::create(_list_columns);
_list->set_model(_list_model);
_list_model = ListStore::create (_list_columns);
_list->set_model (_list_model);
_list_model->signal_row_deleted().connect(
sigc::mem_fun(*this, &AddRequestDialog::_on_row_removed));
_list_model->signal_row_deleted ().connect (sigc::mem_fun (*this, &AddRequestDialog::_on_row_removed));
_list_model->signal_row_inserted().connect(
sigc::mem_fun(*this, &AddRequestDialog::_on_row_added));
_list_model->signal_row_inserted ().connect (sigc::mem_fun (*this, &AddRequestDialog::_on_row_added));
_list->append_column(_("key"), _list_key_column);
_list->append_column(_("resource"), _list_resource_column);
_list->append_column(_("duration"), _list_duration_column);
_list->append_column (_ ("key"), _list_key_column);
_list->append_column (_ ("resource"), _list_resource_column);
_list->append_column (_ ("duration"), _list_duration_column);
_list->get_selection()->signal_changed().connect(
sigc::mem_fun(*this, &AddRequestDialog::_on_list_selection_changed));
_list->get_selection ()->signal_changed ().connect (sigc::mem_fun (*this, &AddRequestDialog::_on_list_selection_changed));
}
Request*
AddRequestDialog::run_add(sgpem::Thread& owner)
Request *
AddRequestDialog::run_add (sgpem::Thread &owner)
{
update_combo();
update_combo ();
Request* r = nullptr;
Request *r = nullptr;
// reset the dialog data
// _list_model->clear();
// _instant_spin->set_value(0.0);
// _duration_spin->set_value(0.0);
if(run() == RESPONSE_OK)
if (run () == RESPONSE_OK)
{
assert(_list_model->children());
assert (_list_model->children ());
History& h = Simulation::get_instance().get_history();
History &h = Simulation::get_instance ().get_history ();
r = &h.add_request(owner, _instant_spin->get_value_as_int());
r = &h.add_request (owner, _instant_spin->get_value_as_int ());
TreeNodeChildren sreq_container = _list_model->children();
TreeNodeChildren sreq_container = _list_model->children ();
for(Iseq<TreeIter> it = iseq(sreq_container); it; ++it)
h.add_subrequest(*r, (*it)[_list_key_column], (*it)[_list_duration_column]);
for (Iseq<TreeIter> it = iseq (sreq_container); it; ++it)
h.add_subrequest (*r, (*it)[_list_key_column], (*it)[_list_duration_column]);
}
hide();
hide ();
return r;
}
void
AddRequestDialog::run_edit(Request& request)
AddRequestDialog::run_edit (Request &request)
{
update_combo();
update_combo ();
_list_model->clear();
_list_model->clear ();
History& history = Simulation::get_instance().get_history();
const Environment::Resources& resources = history.get_last_environment().get_resources();
History &history = Simulation::get_instance ().get_history ();
const Environment::Resources &resources = history.get_last_environment ().get_resources ();
_instant_spin->set_value(static_cast<double>(request.get_instant()));
_instant_spin->set_value (static_cast<double> (request.get_instant ()));
// PLEASE KEEP THIS A COPY, WE *NEED* TO COPY IT
vector<SubRequest*> subrequests = request.get_subrequests();
vector<SubRequest *> subrequests = request.get_subrequests ();
for(Iseq<vector<SubRequest*>::iterator> it = iseq(subrequests); it; ++it)
for (Iseq<vector<SubRequest *>::iterator> it = iseq (subrequests); it; ++it)
{
SubRequest& sr = *(*it);
SubRequest &sr = *(*it);
TreeModel::Row row = *(_list_model->append());
TreeModel::Row row = *(_list_model->append ());
unsigned int key = sr.get_resource_key();
unsigned int key = sr.get_resource_key ();
row[_list_key_column] = key;
const ustring name = resources.find(key)->second->get_name();
const ustring name = resources.find (key)->second->get_name ();
row[_list_resource_column] = name;
row[_list_duration_column] = sr.get_length();
row[_list_duration_column] = sr.get_length ();
}
if(run() == RESPONSE_OK)
if (run () == RESPONSE_OK)
{
assert(_list_model->children());
assert (_list_model->children ());
History::LockNotify h_lock(history);
History::LockNotify h_lock (history);
// I know it's a bit hack-ish, but do you know an elegant alternative way?
for(Iseq<vector<SubRequest*>::iterator> it = iseq(subrequests); it; ++it)
history.remove(*(*it));
for (Iseq<vector<SubRequest *>::iterator> it = iseq (subrequests); it; ++it)
history.remove (*(*it));
history.edit_request(request, _instant_spin->get_value_as_int());
history.edit_request (request, _instant_spin->get_value_as_int ());
TreeNodeChildren sreq_container = _list_model->children();
TreeNodeChildren sreq_container = _list_model->children ();
for(Iseq<TreeIter> it = iseq(sreq_container); it; ++it)
history.add_subrequest(request, (*it)[_list_key_column], (*it)[_list_duration_column]);
for (Iseq<TreeIter> it = iseq (sreq_container); it; ++it)
history.add_subrequest (request, (*it)[_list_key_column], (*it)[_list_duration_column]);
}
hide();
hide ();
}
void
AddRequestDialog::update_combo()
AddRequestDialog::update_combo ()
{
typedef Environment::Resources::const_iterator ResourceIt;
const Environment::Resources& resources =
Simulation::get_instance().get_history().get_last_environment().get_resources();
const Environment::Resources &resources = Simulation::get_instance ().get_history ().get_last_environment ().get_resources ();
_combo_model->clear();
_combo_model->clear ();
for(Iseq<ResourceIt> it = iseq(resources); it; ++it)
for (Iseq<ResourceIt> it = iseq (resources); it; ++it)
{
TreeModel::Row row = *(_combo_model->append());
TreeModel::Row row = *(_combo_model->append ());
row[_combo_key_column] = it->first;
row[_combo_resource_column] = it->second->get_name();
row[_combo_resource_column] = it->second->get_name ();
}
Dialog::on_show();
Dialog::on_show ();
}
void
AddRequestDialog::_on_add()
AddRequestDialog::_on_add ()
{
TreeModel::iterator sel = _resource_combo->get_active();
TreeModel::iterator sel = _resource_combo->get_active ();
TreeModel::Row row = *(_list_model->append());
TreeModel::Row row = *(_list_model->append ());
const unsigned int key = (*sel)[_combo_key_column];
row[_list_key_column] = key;
@ -214,38 +206,37 @@ AddRequestDialog::_on_add()
const ustring resource = (*sel)[_combo_resource_column];
row[_list_resource_column] = resource;
const unsigned int duration = _duration_spin->get_value_as_int();
const unsigned int duration = _duration_spin->get_value_as_int ();
row[_list_duration_column] = duration;
}
void
AddRequestDialog::_on_remove()
AddRequestDialog::_on_remove ()
{
TreeModel::iterator it = _list->get_selection()->get_selected();
_list_model->erase(it);
TreeModel::iterator it = _list->get_selection ()->get_selected ();
_list_model->erase (it);
}
void
AddRequestDialog::_on_list_selection_changed()
AddRequestDialog::_on_list_selection_changed ()
{
_remove_button->set_sensitive(
_list->get_selection()->count_selected_rows() > 0);
_remove_button->set_sensitive (_list->get_selection ()->count_selected_rows () > 0);
}
void
AddRequestDialog::_on_row_added(const Gtk::TreePath&, const Gtk::TreeIter&)
AddRequestDialog::_on_row_added (const Gtk::TreePath &, const Gtk::TreeIter &)
{
_ok_button->set_sensitive(true);
_ok_button->set_sensitive (true);
}
void
AddRequestDialog::_on_row_removed(const Gtk::TreePath&)
AddRequestDialog::_on_row_removed (const Gtk::TreePath &)
{
_ok_button->set_sensitive(static_cast<bool>(_list_model->children()));
_ok_button->set_sensitive (static_cast<bool> (_list_model->children ()));
}
void
AddRequestDialog::_on_combo_selection_changed()
AddRequestDialog::_on_combo_selection_changed ()
{
_add_button->set_sensitive(static_cast<bool>(_resource_combo->get_active()));
_add_button->set_sensitive (static_cast<bool> (_resource_combo->get_active ()));
}

View File

@ -23,31 +23,31 @@
namespace sgpem
{
class Request;
class Thread;
class AddRequestDialog;
}
class Request;
class Thread;
class AddRequestDialog;
} // namespace sgpem
#include <gtkmm/treeview.h>
#include <gtkmm/liststore.h>
#include <gtkmm/dialog.h>
#include <gtkmm/combobox.h>
#include <gtkmm/spinbutton.h>
#include <gtkmm/builder.h>
#include <gtkmm/combobox.h>
#include <gtkmm/dialog.h>
#include <gtkmm/liststore.h>
#include <gtkmm/spinbutton.h>
#include <gtkmm/treeview.h>
namespace sgpem
{
/** \brief A dialog derived from add-request-dialog.ui
/** \brief A dialog derived from add-request-dialog.ui
*
* Manages the list of subrequests, ensures only "nonempty" requests
* are created, and supports also editing.
*/
class AddRequestDialog : public Gtk::Dialog
{
class AddRequestDialog : public Gtk::Dialog
{
public:
/** \brief Constructor required by gtkbuilder
*/
AddRequestDialog(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& ui);
AddRequestDialog (BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &ui);
/** \brief Attemts to show the dialog, and constructs a new request
* if response is OK
@ -55,76 +55,76 @@ namespace sgpem
* \return A pointer to the created request, or nullptr if the request
* wasn't created
*/
Request* run_add(Thread& owner);
Request *run_add (Thread &owner);
/** \brief Attemts to show the dialog to modify an existing request
* \param request The request to modify
*/
void run_edit(Request& request);
void run_edit (Request &request);
private:
/** \brief Fills the combo model with data from the latest
* Environment
*/
void update_combo();
void update_combo ();
/** \brief Called when the "add subrequest" button is pressed
*/
void _on_add();
void _on_add ();
/** \brief Called when the "remove subrequest" button is pressed
*/
void _on_remove();
void _on_remove ();
/** \brief Called when list selection changes
*
* Ensures the "remove subrequest" button is sensitive only
* if a subrequest is selected
*/
void _on_list_selection_changed();
void _on_list_selection_changed ();
/** \brief Called when a row is added to the subrequest list
*
* Ensures the OK button is sensitive since we are sure there is at
* least a subrequest
*/
void _on_row_added(const Gtk::TreePath& path, const Gtk::TreeIter& it);
void _on_row_added (const Gtk::TreePath &path, const Gtk::TreeIter &it);
/** \brief Called when a row is removed from the subrequest list
*
* Ensures the OK button is no more sensitive if the last item was removed
*/
void _on_row_removed(const Gtk::TreePath& path);
void _on_row_removed (const Gtk::TreePath &path);
/** \brief Called when the combo selection changes
*
* Ensures the "add subrequest" button is sensitive only
* if a resource is selected
*/
void _on_combo_selection_changed();
void _on_combo_selection_changed ();
Glib::RefPtr<Gtk::Builder> _ui;
Gtk::TreeView* _list;
Gtk::TreeView *_list;
Glib::RefPtr<Gtk::ListStore> _list_model;
Gtk::TreeModelColumnRecord _list_columns;
Gtk::TreeModelColumn<unsigned int> _list_key_column;
Gtk::TreeModelColumn<Glib::ustring> _list_resource_column;
Gtk::TreeModelColumn<unsigned int> _list_duration_column;
Gtk::Button* _add_button;
Gtk::Button* _remove_button;
Gtk::Button* _ok_button;
Gtk::SpinButton* _instant_spin;
Gtk::SpinButton* _duration_spin;
Gtk::Button *_add_button;
Gtk::Button *_remove_button;
Gtk::Button *_ok_button;
Gtk::SpinButton *_instant_spin;
Gtk::SpinButton *_duration_spin;
Gtk::ComboBox* _resource_combo;
Gtk::ComboBox *_resource_combo;
Glib::RefPtr<Gtk::ListStore> _combo_model;
Gtk::TreeModelColumnRecord _combo_columns;
Gtk::TreeModelColumn<unsigned int> _combo_key_column;
Gtk::TreeModelColumn<Glib::ustring> _combo_resource_column;
};
};
} //~ namespace sgpem
} // namespace sgpem
#endif //~ ADD_REQUEST_DIALOG_HH

View File

@ -36,14 +36,14 @@
using namespace sgpem;
using namespace std;
ConcreteEnvironment::ConcreteEnvironment()
ConcreteEnvironment::ConcreteEnvironment ()
{
// Nothing to do here. Really.
}
ConcreteEnvironment::ConcreteEnvironment(const ConcreteEnvironment& ce) :
Environment(ce), _resources(ce._resources), _processes(), _sched_queue(), _sreq_queues(ce._sreq_queues)
ConcreteEnvironment::ConcreteEnvironment (const ConcreteEnvironment &ce)
: Environment (ce), _resources (ce._resources), _processes (), _sched_queue (), _sreq_queues (ce._sreq_queues)
{
// The ReadyQueue won't be copied. Pointers to objects contained into
// the ready queue _will_ have changed in the new one. The ready queue
@ -51,62 +51,61 @@ ConcreteEnvironment::ConcreteEnvironment(const ConcreteEnvironment& ce) :
// Update resource pointers in a way you won't like :-)
{
for (Resources::iterator it = _resources.begin(); it != _resources.end(); it++)
it->second = new DynamicResource(down_cast<const DynamicResource&>(*it->second));
for (Resources::iterator it = _resources.begin (); it != _resources.end (); it++)
it->second = new DynamicResource (down_cast<const DynamicResource &> (*it->second));
}
// DynamicProcess object need to be copied.
// The deep copy is guaranteed by the DynamicProcess copy constructor
{
const Processes& ce_proc = ce._processes;
insert_iterator<Processes> dest(_processes, _processes.begin());
for (Iseq<Processes::const_iterator> orig = iseq(ce_proc); orig; orig++)
*dest++ = new DynamicProcess(down_cast<const DynamicProcess&>(**orig));
const Processes &ce_proc = ce._processes;
insert_iterator<Processes> dest (_processes, _processes.begin ());
for (Iseq<Processes::const_iterator> orig = iseq (ce_proc); orig; orig++)
*dest++ = new DynamicProcess (down_cast<const DynamicProcess &> (**orig));
}
// Update the subrequest queues.
// for each subrequest
typedef Processes::const_iterator it1_t;
typedef std::vector<Thread*> v2_t;
typedef std::vector<Thread *> v2_t;
typedef v2_t::const_iterator it2_t;
typedef std::vector<Request*> v3_t;
typedef std::vector<Request *> v3_t;
typedef v3_t::const_iterator it3_t;
typedef std::vector<SubRequest*> v4_t;
typedef std::vector<SubRequest *> v4_t;
typedef v4_t::const_iterator it4_t;
typedef SubRequestQueue::iterator it5_t;
for (it1_t it1 = _processes.begin(); it1 != _processes.end(); it1++)
for (it1_t it1 = _processes.begin (); it1 != _processes.end (); it1++)
{
const v2_t& threads = (*it1)->get_threads();
for (it2_t it2 = threads.begin(); it2 != threads.end(); it2++)
const v2_t &threads = (*it1)->get_threads ();
for (it2_t it2 = threads.begin (); it2 != threads.end (); it2++)
{
const v3_t& reqs = (*it2)->get_requests();
for (it3_t it3 = reqs.begin(); it3 != reqs.end(); it3++)
const v3_t &reqs = (*it2)->get_requests ();
for (it3_t it3 = reqs.begin (); it3 != reqs.end (); it3++)
{
// an optimization here: there is no reason in iterating through
// future or exausted requests. (Do you know why?)
const v4_t& subr = (*it3)->get_subrequests();
for (it4_t it4 = subr.begin(); it4 != subr.end(); it4++)
const v4_t &subr = (*it3)->get_subrequests ();
for (it4_t it4 = subr.begin (); it4 != subr.end (); it4++)
{
SubRequest::state curr_state = (*it4)->get_state();
SubRequest::state curr_state = (*it4)->get_state ();
if (curr_state != Request::state_future && curr_state != Request::state_exhausted)
{
// the subrequest is the following queue:
SubRequestQueue & queue = get_request_queue((*it4)->get_resource_key());
SubRequestQueue &queue = get_request_queue ((*it4)->get_resource_key ());
// we must replace the old pointer:
bool found = false;
for (it5_t it5 = queue.begin(); !found && it5 != queue.end(); it5++)
for (it5_t it5 = queue.begin (); !found && it5 != queue.end (); it5++)
{
DynamicSubRequest& _old = down_cast<DynamicSubRequest&>(**it5);
DynamicSubRequest& _new = down_cast<DynamicSubRequest&>(**it4);
if (&_old.get_core() == &_new.get_core())
DynamicSubRequest &_old = down_cast<DynamicSubRequest &> (**it5);
DynamicSubRequest &_new = down_cast<DynamicSubRequest &> (**it4);
if (&_old.get_core () == &_new.get_core ())
{
found = true;
*it5 = *it4;
@ -117,92 +116,81 @@ ConcreteEnvironment::ConcreteEnvironment(const ConcreteEnvironment& ce) :
}
}
}
}
const Environment::Processes&
ConcreteEnvironment::get_processes() const
const Environment::Processes &
ConcreteEnvironment::get_processes () const
{
return _processes;
}
ConcreteEnvironment::Processes&
ConcreteEnvironment::get_processes()
ConcreteEnvironment::Processes &
ConcreteEnvironment::get_processes ()
{
return _processes;
}
const Environment::Resources&
ConcreteEnvironment::get_resources() const
const Environment::Resources &
ConcreteEnvironment::get_resources () const
{
return _resources;
}
ConcreteEnvironment::Resources&
ConcreteEnvironment::get_resources()
ConcreteEnvironment::Resources &
ConcreteEnvironment::get_resources ()
{
return _resources;
}
const Environment::SubRequestQueue&
ConcreteEnvironment::get_request_queue(resource_key_t resource_key) const
const Environment::SubRequestQueue &
ConcreteEnvironment::get_request_queue (resource_key_t resource_key) const
{
// Should always return something...
return _sreq_queues.find(resource_key)->second;
return _sreq_queues.find (resource_key)->second;
}
Environment::SubRequestQueue&
ConcreteEnvironment::get_request_queue(resource_key_t resource_key)
Environment::SubRequestQueue &
ConcreteEnvironment::get_request_queue (resource_key_t resource_key)
{
// Inserts a new element in none is there!
return _sreq_queues[resource_key];
}
ConcreteEnvironment::SubRequestQueues&
ConcreteEnvironment::get_subrequest_queues()
ConcreteEnvironment::SubRequestQueues &
ConcreteEnvironment::get_subrequest_queues ()
{
return _sreq_queues;
}
const ReadyQueue&
ConcreteEnvironment::get_sorted_queue() const
const ReadyQueue &
ConcreteEnvironment::get_sorted_queue () const
{
return _sched_queue;
}
ReadyQueue&
ConcreteEnvironment::get_sorted_queue()
ReadyQueue &
ConcreteEnvironment::get_sorted_queue ()
{
return _sched_queue;
}
ConcreteEnvironment::~ConcreteEnvironment()
ConcreteEnvironment::~ConcreteEnvironment ()
{
// This call will invoke the DynamicProcess virtual destructor
// Which will delete on cascade all DynamicThreads and so on.
for_each(_processes.begin(), _processes.end(),
[] (auto *p) { delete p; });
for_each (_processes.begin (), _processes.end (), [](auto *p) { delete p; });
// We do the same with Resources.
for (Resources::iterator it = _resources.begin(); it != _resources.end(); it++)
for (Resources::iterator it = _resources.begin (); it != _resources.end (); it++)
delete it->second;
// After this, the destructor of _sched_queue is invoked (only invalid pointers)
@ -211,7 +199,4 @@ ConcreteEnvironment::~ConcreteEnvironment()
}
// -------------------------------- TO BE FIXED ----------------

View File

@ -23,48 +23,48 @@
namespace sgpem
{
class ConcreteEnvironment;
class SerializeVisitor;
}
class ConcreteEnvironment;
class SerializeVisitor;
} // namespace sgpem
#include "dynamic_process.hh"
#include "dynamic_request.hh"
#include <sgpemv2/environment.hh>
#include <sgpemv2/resource.hh>
#include <sgpemv2/ready_queue.hh>
#include <sgpemv2/resource.hh>
namespace sgpem
{
/// \brief An implementation of the Environment class.
///
/// Class ConcreteEnvironment implements the Environment
/// abstract class.
///
/// This implementation actually contains the collections
/// of snapshots accessed by the function members defined
/// in the Environment class.
///
/// \see Environment
class SG_DLLLOCAL ConcreteEnvironment : public Environment
{
/// \brief An implementation of the Environment class.
///
/// Class ConcreteEnvironment implements the Environment
/// abstract class.
///
/// This implementation actually contains the collections
/// of snapshots accessed by the function members defined
/// in the Environment class.
///
/// \see Environment
class SG_DLLLOCAL ConcreteEnvironment : public Environment
{
public:
typedef std::map<resource_key_t, SubRequestQueue> SubRequestQueues;
/// \brief Standard constructor.
///
/// Builds an empty environment.
ConcreteEnvironment();
ConcreteEnvironment ();
/// \brief Copy constructor.
///
/// Performs a deep copy of all structures.
ConcreteEnvironment(const ConcreteEnvironment& c);
ConcreteEnvironment (const ConcreteEnvironment &c);
/// \brief The standard virtual destructor.
///
/// The standard virtual destructor.
virtual ~ConcreteEnvironment();
virtual ~ConcreteEnvironment ();
/// \brief Returns an indexed set of snapshots of the processes
///
@ -77,13 +77,13 @@ namespace sgpem
/// always safe.
///
/// \return a constant set of snapshots of processes
virtual const Processes& get_processes() const;
virtual const Processes &get_processes () const;
/// \brief Non-constant version of get_processes()
///
/// \return a set of snapshots of processes
/// \see get_processes()
virtual Processes& get_processes();
virtual Processes &get_processes ();
/// \brief Returns an indexed set of snapshots of the resources
///
@ -104,13 +104,13 @@ namespace sgpem
///
/// \return a indexed constant set of snapshot of resources.
/// \see DynamicSybrequest::get_resource()
virtual const Resources& get_resources() const;
virtual const Resources &get_resources () const;
/// \brief Non-constant version of get_resources()
///
/// \return an indexed set of snapshots of resources
/// \see get_resources()
virtual Resources& get_resources();
virtual Resources &get_resources ();
/// \brief Returns a snapshot of the current request queue for a resource.
///
@ -124,16 +124,16 @@ namespace sgpem
///
/// \param resource The resource the requests are for
/// \return The current ready requests queue.
virtual const SubRequestQueue& get_request_queue(resource_key_t resource_key) const;
virtual const SubRequestQueue &get_request_queue (resource_key_t resource_key) const;
SubRequestQueue& get_request_queue(resource_key_t resource_key);
SubRequestQueue &get_request_queue (resource_key_t resource_key);
/// \brief Returns the set of request queues.
///
/// Returns a reference to the map from resources to subreuqest queues.
/// It is needed by history to delete the queue associated to a deleted
/// resource.
SubRequestQueues& get_subrequest_queues();
SubRequestQueues &get_subrequest_queues ();
/// \brief Returns a snapshot of the current scheduler's ready queue.
///
@ -143,16 +143,15 @@ namespace sgpem
/// of the CPU.
///
/// \return the current ready queue (constant).
virtual const ReadyQueue& get_sorted_queue() const;
virtual const ReadyQueue &get_sorted_queue () const;
/// \brief Non-constant version of get_sorted_queue()
///
/// \return the current ready queue.
/// \see get_sorted_queue()
virtual ReadyQueue& get_sorted_queue();
virtual ReadyQueue &get_sorted_queue ();
private:
/// \brief The container of all Resource objecs.
///
/// Actually contains only DynamicResource objects.
@ -172,8 +171,8 @@ namespace sgpem
SubRequestQueues _sreq_queues;
}; //~ class ConcreteEnvironment
}; //~ class ConcreteEnvironment
} //~ namespace sgpem
} // namespace sgpem
#endif

View File

@ -18,19 +18,17 @@
// along with SGPEMv2. If not, see http://www.gnu.org/licenses/.
#include "dynamic_process.hh"
#include "dynamic_thread.hh"
#include "dynamic_resource.hh"
#include "dynamic_request.hh"
#include "dynamic_resource.hh"
#include "dynamic_sub_request.hh"
#include "dynamic_thread.hh"
#include "static_process.hh"
#include "static_thread.hh"
#include "static_resource.hh"
#include "static_request.hh"
#include "static_resource.hh"
#include "static_sub_request.hh"
#include "static_thread.hh"
#include "concrete_history.hh"
@ -54,15 +52,16 @@ using namespace std;
// For all you evil-doers on Earth, this is your mighty punishment!
// remove a template object from vector of pointers
template<typename T>
static bool deep_remove(std::vector<T*>& v, const T& obj)
template <typename T>
static bool
deep_remove (std::vector<T *> &v, const T &obj)
{
typedef typename std::vector<T*> Vector;
for (typename Vector::iterator it = v.begin(); it != v.end(); it++)
typedef typename std::vector<T *> Vector;
for (typename Vector::iterator it = v.begin (); it != v.end (); it++)
if (**it == obj)
{
delete *it;
v.erase(it);
v.erase (it);
return true;
}
return false;
@ -70,11 +69,12 @@ static bool deep_remove(std::vector<T*>& v, const T& obj)
// find a template T object into a vector of T pointers
template<typename T>
static T* deep_find(const std::vector<T*>& v, const T& obj)
template <typename T>
static T *
deep_find (const std::vector<T *> &v, const T &obj)
{
typedef typename std::vector<T*> Vector;
for (typename Vector::const_iterator it = v.begin(); it != v.end(); it++)
typedef typename std::vector<T *> Vector;
for (typename Vector::const_iterator it = v.begin (); it != v.end (); it++)
if (**it == obj)
{
return *it;
@ -85,105 +85,102 @@ static T* deep_find(const std::vector<T*>& v, const T& obj)
// -----------------
ConcreteHistory::ConcreteHistory()
: History(), _snapshots(), _sealed(false)
ConcreteHistory::ConcreteHistory () : History (), _snapshots (), _sealed (false)
{
_snapshots.push_back(new ConcreteEnvironment());
_snapshots.push_back (new ConcreteEnvironment ());
}
ConcreteHistory::~ConcreteHistory()
ConcreteHistory::~ConcreteHistory ()
{
for_each(_snapshots.begin(), _snapshots.end(),
[] (auto *p) { delete p; });
for_each (_snapshots.begin (), _snapshots.end (), [](auto *p) { delete p; });
}
ConcreteHistory::ConcreteHistory(const ConcreteHistory& h) :
History(h), _sealed(h._sealed)
ConcreteHistory::ConcreteHistory (const ConcreteHistory &h) : History (h), _sealed (h._sealed)
{
typedef Snapshots::const_iterator SnapIt;
for (SnapIt it = h._snapshots.begin(); it != h._snapshots.end(); ++it)
_snapshots.push_back(new ConcreteEnvironment(*(*it)));
for (SnapIt it = h._snapshots.begin (); it != h._snapshots.end (); ++it)
_snapshots.push_back (new ConcreteEnvironment (*(*it)));
}
void
ConcreteHistory::append_new_environment(ConcreteEnvironment* environment)
ConcreteHistory::append_new_environment (ConcreteEnvironment *environment)
{
_snapshots.push_back(environment);
notify_change();
_snapshots.push_back (environment);
notify_change ();
}
ConcreteHistory::size_t
ConcreteHistory::get_size() const
ConcreteHistory::get_size () const
{
return _snapshots.size();
return _snapshots.size ();
}
const ConcreteEnvironment&
ConcreteHistory::get_last_environment() const
const ConcreteEnvironment &
ConcreteHistory::get_last_environment () const
{
// Should always be true:
assert(_snapshots.size() > 0);
return get_environment_at(get_front());
assert (_snapshots.size () > 0);
return get_environment_at (get_front ());
}
const ConcreteEnvironment&
ConcreteHistory::get_environment_at(position index) const
const ConcreteEnvironment &
ConcreteHistory::get_environment_at (position index) const
{
return *_snapshots.at(index);
return *_snapshots.at (index);
}
void
ConcreteHistory::remove(resource_key_t resource_key)
ConcreteHistory::remove (resource_key_t resource_key)
{
// Pay attention that initial isn't deleted by reset()
ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Resources& resources = initial.get_resources();
ConcreteEnvironment::Resources::iterator found = resources.find(resource_key);
if (found == resources.end())
ConcreteEnvironment &initial = *_snapshots.front ();
ConcreteEnvironment::Resources &resources = initial.get_resources ();
ConcreteEnvironment::Resources::iterator found = resources.find (resource_key);
if (found == resources.end ())
return;
delete found->second;
resources.erase(found);
resources.erase (found);
// Delete the queue associated with the resource.
ConcreteEnvironment::SubRequestQueues& srq = initial.get_subrequest_queues();
ConcreteEnvironment::SubRequestQueues::iterator qfound = srq.find(resource_key);
ConcreteEnvironment::SubRequestQueues &srq = initial.get_subrequest_queues ();
ConcreteEnvironment::SubRequestQueues::iterator qfound = srq.find (resource_key);
// There is always one!
assert(qfound != srq.end());
srq.erase(qfound);
assert (qfound != srq.end ());
srq.erase (qfound);
// Now search and erase subrequest that had a ref to the
// removed resource
typedef std::vector<DynamicThread*> Threads;
typedef std::vector<DynamicRequest*> Requests;
typedef std::vector<DynamicSubRequest*> SubRequests;
typedef std::vector<DynamicThread *> Threads;
typedef std::vector<DynamicRequest *> Requests;
typedef std::vector<DynamicSubRequest *> SubRequests;
// Listening to "The Thing That Should Not Be"...
// all hail the cyclomatic complexity!
ConcreteEnvironment::Processes& processes = initial.get_processes();
ConcreteEnvironment::Processes &processes = initial.get_processes ();
typedef ConcreteEnvironment::Processes::iterator ProcIt;
for (ProcIt it1 = processes.begin(); it1 != processes.end(); it1++)
for (ProcIt it1 = processes.begin (); it1 != processes.end (); it1++)
{
Threads& threads = down_cast<DynamicProcess&>(**it1).get_dynamic_threads();
for (Threads::iterator it2 = threads.begin(); it2 != threads.end(); it2++)
Threads &threads = down_cast<DynamicProcess &> (**it1).get_dynamic_threads ();
for (Threads::iterator it2 = threads.begin (); it2 != threads.end (); it2++)
{
Requests& reqs = (*it2)->get_dynamic_requests();
for (Requests::iterator it3 = reqs.begin(); it3 != reqs.end(); it3++)
Requests &reqs = (*it2)->get_dynamic_requests ();
for (Requests::iterator it3 = reqs.begin (); it3 != reqs.end (); it3++)
{
SubRequests& subr = (*it3)->get_dynamic_subrequests();
SubRequests::iterator it4 = subr.begin();
while (it4 != subr.end())
if ((*it4)->get_resource_key() == resource_key)
SubRequests &subr = (*it3)->get_dynamic_subrequests ();
SubRequests::iterator it4 = subr.begin ();
while (it4 != subr.end ())
if ((*it4)->get_resource_key () == resource_key)
{
delete *it4;
it4 = subr.erase(it4);
it4 = subr.erase (it4);
}
else
it4++;
@ -194,354 +191,333 @@ ConcreteHistory::remove(resource_key_t resource_key)
// for example. Or hangovers. Or being read poetry by a Vogon.
// Although the above construct really rates between the first tens.
reset();
reset ();
}
void
ConcreteHistory::remove(Process& process)
ConcreteHistory::remove (Process &process)
{
// Pay attention that initial isn't deleted by reset()
ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Processes& processes = initial.get_processes();
bool found = deep_remove<Process>(processes, process);
ConcreteEnvironment &initial = *_snapshots.front ();
ConcreteEnvironment::Processes &processes = initial.get_processes ();
bool found = deep_remove<Process> (processes, process);
if (found)
reset();
reset ();
}
void
ConcreteHistory::remove(Thread& thread)
ConcreteHistory::remove (Thread &thread)
{
DynamicThread& dyn_thr = down_cast<DynamicThread&>(thread);
DynamicThread &dyn_thr = down_cast<DynamicThread &> (thread);
// Pay attention that initial isn't deleted by reset()
ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Processes& processes = initial.get_processes();
ConcreteEnvironment &initial = *_snapshots.front ();
ConcreteEnvironment::Processes &processes = initial.get_processes ();
Process* found = deep_find<Process>(processes, dyn_thr.get_process());
Process *found = deep_find<Process> (processes, dyn_thr.get_process ());
if (found == nullptr)
return; // not found, just return.
DynamicProcess& dynamic_found = down_cast<DynamicProcess&>(*found);
bool removed = deep_remove<DynamicThread>(dynamic_found.get_dynamic_threads(), dyn_thr);
DynamicProcess &dynamic_found = down_cast<DynamicProcess &> (*found);
bool removed = deep_remove<DynamicThread> (dynamic_found.get_dynamic_threads (), dyn_thr);
if (removed)
reset();
reset ();
}
void
ConcreteHistory::remove(Request& request)
ConcreteHistory::remove (Request &request)
{
DynamicRequest& dyn_req = down_cast<DynamicRequest&>(request);
DynamicThread& dyn_thr = dyn_req.get_thread();
DynamicProcess& dyn_proc = dyn_thr.get_process();
DynamicRequest &dyn_req = down_cast<DynamicRequest &> (request);
DynamicThread &dyn_thr = dyn_req.get_thread ();
DynamicProcess &dyn_proc = dyn_thr.get_process ();
// Pay attention that initial isn't deleted by reset()
ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Processes& processes = initial.get_processes();
ConcreteEnvironment &initial = *_snapshots.front ();
ConcreteEnvironment::Processes &processes = initial.get_processes ();
Process* proc_ref = deep_find<Process>(processes, dyn_proc);
DynamicProcess* dyn_proc_ref = down_cast<DynamicProcess*>(proc_ref);
Process *proc_ref = deep_find<Process> (processes, dyn_proc);
DynamicProcess *dyn_proc_ref = down_cast<DynamicProcess *> (proc_ref);
if (dyn_proc_ref == nullptr)
return; // not found, just return.
DynamicThread* thr_ref = deep_find<DynamicThread>(dyn_proc_ref->get_dynamic_threads(), dyn_thr);
DynamicThread *thr_ref = deep_find<DynamicThread> (dyn_proc_ref->get_dynamic_threads (), dyn_thr);
if (thr_ref == nullptr)
return; // not found, just return.
bool removed = deep_remove<DynamicRequest>(thr_ref->get_dynamic_requests(), dyn_req);
bool removed = deep_remove<DynamicRequest> (thr_ref->get_dynamic_requests (), dyn_req);
if (removed)
reset();
reset ();
}
void
ConcreteHistory::remove(SubRequest& subrequest)
ConcreteHistory::remove (SubRequest &subrequest)
{
// this function makes one relevant assumption:
// the initial environment does contain empty request queues only.
DynamicSubRequest& dyn_sub = down_cast<DynamicSubRequest&>(subrequest);
DynamicRequest& dyn_req = dyn_sub.get_request();
DynamicThread& dyn_thr = dyn_req.get_thread();
DynamicProcess& dyn_proc = dyn_thr.get_process();
DynamicSubRequest &dyn_sub = down_cast<DynamicSubRequest &> (subrequest);
DynamicRequest &dyn_req = dyn_sub.get_request ();
DynamicThread &dyn_thr = dyn_req.get_thread ();
DynamicProcess &dyn_proc = dyn_thr.get_process ();
// Pay attention that initial isn't deleted by reset()
ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Processes& processes = initial.get_processes();
ConcreteEnvironment &initial = *_snapshots.front ();
ConcreteEnvironment::Processes &processes = initial.get_processes ();
Process* proc_ref = deep_find<Process>(processes, dyn_proc);
DynamicProcess* dyn_proc_ref = down_cast<DynamicProcess*>(proc_ref);
Process *proc_ref = deep_find<Process> (processes, dyn_proc);
DynamicProcess *dyn_proc_ref = down_cast<DynamicProcess *> (proc_ref);
if (dyn_proc_ref == nullptr)
return; // not found, just return.
DynamicThread* thr_ref = deep_find<DynamicThread>(dyn_proc_ref->get_dynamic_threads(), dyn_thr);
DynamicThread *thr_ref = deep_find<DynamicThread> (dyn_proc_ref->get_dynamic_threads (), dyn_thr);
if (thr_ref == nullptr)
return; // not found, just return.
DynamicRequest* req_ref = deep_find<DynamicRequest>(thr_ref->get_dynamic_requests(), dyn_req);
DynamicRequest *req_ref = deep_find<DynamicRequest> (thr_ref->get_dynamic_requests (), dyn_req);
if (req_ref == nullptr)
return; // not found, just return.
bool removed = deep_remove<DynamicSubRequest>(req_ref->get_dynamic_subrequests(), dyn_sub);
bool removed = deep_remove<DynamicSubRequest> (req_ref->get_dynamic_subrequests (), dyn_sub);
if (removed)
reset();
reset ();
}
void
ConcreteHistory::clear()
ConcreteHistory::clear ()
{
delete _snapshots.front();
_snapshots.front() = new ConcreteEnvironment();
reset();
delete _snapshots.front ();
_snapshots.front () = new ConcreteEnvironment ();
reset ();
}
ConcreteHistory::ResourcePair
ConcreteHistory::add_resource(const Glib::ustring& name,
bool /*preemptable*/,
size_t places,
size_t /*availability*/)
ConcreteHistory::add_resource (const Glib::ustring &name, bool /*preemptable*/, size_t places, size_t /*availability*/)
{
typedef ConcreteEnvironment::Resources Resources;
typedef ConcreteEnvironment::SubRequestQueue SubRequestQueue;
// And preemptable and availability?? FIXME!
StaticResource* core = new StaticResource(name, places);
DynamicResource* resource = new DynamicResource(core);
StaticResource *core = new StaticResource (name, places);
DynamicResource *resource = new DynamicResource (core);
ConcreteEnvironment::Resources& resources = _snapshots.front()->get_resources();
ConcreteEnvironment::Resources &resources = _snapshots.front ()->get_resources ();
// alakazam! Black magic at work... get a unique index for this resource
resource_key_t index = 0;
while (resources.find(index) != resources.end())
while (resources.find (index) != resources.end ())
index++;
// Found a hole in the map, fill it like little Hans,
// its finger and the spilling dam.
Resources::iterator temp = resources.insert(pair<resource_key_t, Resource*>(index, resource)).first;
Resources::iterator temp = resources.insert (pair<resource_key_t, Resource *> (index, resource)).first;
// The same for request queues.
SubRequestQueue emptysrq;
_snapshots.front()->get_subrequest_queues().insert(pair<resource_key_t, SubRequestQueue>(index, emptysrq));
_snapshots.front ()->get_subrequest_queues ().insert (pair<resource_key_t, SubRequestQueue> (index, emptysrq));
reset();
reset ();
return *temp;
}
void
ConcreteHistory::edit_resource(Resource& resource,
const Glib::ustring& name,
bool /*preemptable*/,
size_t places,
size_t /*availability*/)
ConcreteHistory::edit_resource (Resource &resource, const Glib::ustring &name, bool /*preemptable*/, size_t places, size_t /*availability*/)
{
// And preemptable and availability?? FIXME!
DynamicResource* res = down_cast<DynamicResource*>(&resource);
StaticResource& core = res->get_core();
core.set_name(name);
core.set_places(places);
DynamicResource *res = down_cast<DynamicResource *> (&resource);
StaticResource &core = res->get_core ();
core.set_name (name);
core.set_places (places);
reset();
reset ();
}
DynamicProcess&
ConcreteHistory::add_process(const Glib::ustring& name,
time_t arrival_time,
prio_t base_priority)
DynamicProcess &
ConcreteHistory::add_process (const Glib::ustring &name, time_t arrival_time, prio_t base_priority)
{
StaticProcess* core = new StaticProcess(name, arrival_time, base_priority);
DynamicProcess* proc = new DynamicProcess(core);
StaticProcess *core = new StaticProcess (name, arrival_time, base_priority);
DynamicProcess *proc = new DynamicProcess (core);
ConcreteEnvironment::Processes& processes = _snapshots.front()->get_processes();
processes.push_back(proc);
ConcreteEnvironment::Processes &processes = _snapshots.front ()->get_processes ();
processes.push_back (proc);
reset();
reset ();
return *proc;
}
void
ConcreteHistory::edit_process(Process& process,
const Glib::ustring& name,
time_t arrival_time,
prio_t base_priority)
ConcreteHistory::edit_process (Process &process, const Glib::ustring &name, time_t arrival_time, prio_t base_priority)
{
DynamicProcess* proc = down_cast<DynamicProcess*>(&process);
StaticProcess& core = proc->get_core();
core.set_name(name);
core.set_arrival_time(arrival_time);
core.set_priority(base_priority);
DynamicProcess *proc = down_cast<DynamicProcess *> (&process);
StaticProcess &core = proc->get_core ();
core.set_name (name);
core.set_arrival_time (arrival_time);
core.set_priority (base_priority);
reset();
reset ();
}
DynamicThread&
ConcreteHistory::add_thread(const Glib::ustring& name,
Process& parent,
time_t cpu_time,
time_t arrival_time,
prio_t base_priority)
DynamicThread &
ConcreteHistory::add_thread (const Glib::ustring &name, Process &parent, time_t cpu_time, time_t arrival_time, prio_t base_priority)
{
ConcreteEnvironment::Processes& processes = _snapshots.front()->get_processes();
Process* p = deep_find<Process>(processes, parent);
if(!p) throw std::runtime_error(_("History::add_thread() : Parent process not part of this History"));
ConcreteEnvironment::Processes &processes = _snapshots.front ()->get_processes ();
Process *p = deep_find<Process> (processes, parent);
if (!p)
throw std::runtime_error (_ ("History::add_thread() : Parent process not part of this History"));
DynamicProcess& parent_process = down_cast<DynamicProcess&>(*p);
StaticProcess& parent_core = parent_process.get_core();
StaticThread* core = new StaticThread(name, parent_core, cpu_time, arrival_time, base_priority);
DynamicThread* thread = new DynamicThread(core, &parent_process);
DynamicProcess &parent_process = down_cast<DynamicProcess &> (*p);
StaticProcess &parent_core = parent_process.get_core ();
StaticThread *core = new StaticThread (name, parent_core, cpu_time, arrival_time, base_priority);
DynamicThread *thread = new DynamicThread (core, &parent_process);
reset();
reset ();
return *thread;
}
void
ConcreteHistory::edit_thread(Thread& thread,
const Glib::ustring& name,
time_t cpu_time,
time_t arrival_time,
prio_t base_priority)
ConcreteHistory::edit_thread (Thread &thread, const Glib::ustring &name, time_t cpu_time, time_t arrival_time, prio_t base_priority)
{
DynamicThread* thre = down_cast<DynamicThread*>(&thread);
StaticThread& core = thre->get_core();
core.set_name(name);
core.set_total_cpu_time(cpu_time);
core.set_arrival_time(arrival_time);
core.set_priority(base_priority);
DynamicThread *thre = down_cast<DynamicThread *> (&thread);
StaticThread &core = thre->get_core ();
core.set_name (name);
core.set_total_cpu_time (cpu_time);
core.set_arrival_time (arrival_time);
core.set_priority (base_priority);
reset();
reset ();
}
DynamicRequest&
ConcreteHistory::add_request(Thread& owner,
time_t instant)
DynamicRequest &
ConcreteHistory::add_request (Thread &owner, time_t instant)
{
ConcreteEnvironment::Processes& processes = _snapshots.front()->get_processes();
ConcreteEnvironment::Processes &processes = _snapshots.front ()->get_processes ();
Process* p = deep_find(processes, owner.get_process());
if(!p) throw std::runtime_error(_("History::add_request() : Parent process not part of this History"));
Thread* t = deep_find(p->get_threads(), owner);
if(!t) throw std::runtime_error(_("History::add_request() : Parent thread not part of this History"));
Process *p = deep_find (processes, owner.get_process ());
if (!p)
throw std::runtime_error (_ ("History::add_request() : Parent process not part of this History"));
Thread *t = deep_find (p->get_threads (), owner);
if (!t)
throw std::runtime_error (_ ("History::add_request() : Parent thread not part of this History"));
DynamicThread& dyn_owner = down_cast<DynamicThread&>(*t);
StaticThread& owner_core = dyn_owner.get_core();
DynamicThread &dyn_owner = down_cast<DynamicThread &> (*t);
StaticThread &owner_core = dyn_owner.get_core ();
StaticRequest* core = new StaticRequest(&owner_core, instant);
DynamicRequest* req = new DynamicRequest(core, &dyn_owner);
StaticRequest *core = new StaticRequest (&owner_core, instant);
DynamicRequest *req = new DynamicRequest (core, &dyn_owner);
reset();
reset ();
return *req;
}
void
ConcreteHistory::edit_request(Request& request,
time_t instant)
ConcreteHistory::edit_request (Request &request, time_t instant)
{
DynamicRequest* req = down_cast<DynamicRequest*>(&request);
StaticRequest& core = req->get_core();
core.set_instant(instant);
DynamicRequest *req = down_cast<DynamicRequest *> (&request);
StaticRequest &core = req->get_core ();
core.set_instant (instant);
reset();
reset ();
}
DynamicSubRequest&
ConcreteHistory::add_subrequest(Request& request,
resource_key_t resource_key,
time_t duration)
DynamicSubRequest &
ConcreteHistory::add_subrequest (Request &request, resource_key_t resource_key, time_t duration)
{
ConcreteEnvironment::Processes& processes = _snapshots.front()->get_processes();
ConcreteEnvironment::Processes &processes = _snapshots.front ()->get_processes ();
Process* p = deep_find(processes, request.get_thread().get_process());
if(!p) throw std::runtime_error(_("History::add_subrequest() : Parent process not part of this History"));
Thread* t = deep_find(p->get_threads(), request.get_thread());
if(!t) throw std::runtime_error(_("History::add_subrequest() : Parent thread not part of this History"));
Request* r = deep_find(t->get_requests(), request);
if(!r) throw std::runtime_error(_("History::add_subrequest() : Parent request not part of this History"));
Process *p = deep_find (processes, request.get_thread ().get_process ());
if (!p)
throw std::runtime_error (_ ("History::add_subrequest() : Parent process not part of this History"));
Thread *t = deep_find (p->get_threads (), request.get_thread ());
if (!t)
throw std::runtime_error (_ ("History::add_subrequest() : Parent thread not part of this History"));
Request *r = deep_find (t->get_requests (), request);
if (!r)
throw std::runtime_error (_ ("History::add_subrequest() : Parent request not part of this History"));
DynamicRequest& dyn_request = down_cast<DynamicRequest&>(*r);
DynamicRequest &dyn_request = down_cast<DynamicRequest &> (*r);
StaticSubRequest* core = new StaticSubRequest(resource_key, duration);
DynamicSubRequest* subreq = new DynamicSubRequest(core, &dyn_request);
StaticSubRequest *core = new StaticSubRequest (resource_key, duration);
DynamicSubRequest *subreq = new DynamicSubRequest (core, &dyn_request);
reset();
reset ();
return *subreq;
}
void
ConcreteHistory::edit_subrequest(SubRequest& subrequest,
resource_key_t resource_key,
time_t duration)
ConcreteHistory::edit_subrequest (SubRequest &subrequest, resource_key_t resource_key, time_t duration)
{
DynamicSubRequest* sreq = down_cast<DynamicSubRequest*>(&subrequest);
StaticSubRequest& core = sreq->get_core();
core.set_resource_key(resource_key);
core.set_length(duration);
DynamicSubRequest *sreq = down_cast<DynamicSubRequest *> (&subrequest);
StaticSubRequest &core = sreq->get_core ();
core.set_resource_key (resource_key);
core.set_length (duration);
reset();
reset ();
}
void
ConcreteHistory::set_front(position p)
ConcreteHistory::set_front (position p)
{
position old_front = _front;
if (p > _snapshots.size() - 1)
if (p > _snapshots.size () - 1)
{
_front = _snapshots.size() - 1;
_front = _snapshots.size () - 1;
}
else
{
_front = p;
}
if(old_front != _front)
notify_change();
if (old_front != _front)
notify_change ();
}
void
ConcreteHistory::reset()
ConcreteHistory::reset ()
{
#ifndef NDEBUG
static unsigned int n = 0;
std::cerr << "ConcreteHistory::reset() called for the " << ++n << "-th time." << std::endl;
#endif
assert(_snapshots.size() > 0);
Snapshots::iterator it = _snapshots.begin();
assert (_snapshots.size () > 0);
Snapshots::iterator it = _snapshots.begin ();
it++; // Skip first environment that we saved
for_each(it, _snapshots.end(), [] (auto *p) { delete p; });
_snapshots.resize(1); // Truncate to keep only our "model"
for_each (it, _snapshots.end (), [](auto *p) { delete p; });
_snapshots.resize (1); // Truncate to keep only our "model"
_front = 0;
_sealed = false;
notify_change();
notify_change ();
}
bool
ConcreteHistory::is_sealed() const
ConcreteHistory::is_sealed () const
{
return _sealed;
}
bool
ConcreteHistory::seal()
ConcreteHistory::seal ()
{
bool t = _sealed;
_sealed = true;

View File

@ -23,7 +23,7 @@
namespace sgpem
{
class ConcreteHistory;
class ConcreteHistory;
}
#include "concrete_environment.hh"
@ -44,97 +44,72 @@ namespace sgpem
namespace sgpem
{
class SG_DLLLOCAL ConcreteHistory : public History
{
class SG_DLLLOCAL ConcreteHistory : public History
{
public:
ConcreteHistory();
ConcreteHistory(const ConcreteHistory&);
virtual ~ConcreteHistory();
ConcreteHistory ();
ConcreteHistory (const ConcreteHistory &);
virtual ~ConcreteHistory ();
virtual void append_new_environment(ConcreteEnvironment* environment);
virtual size_t get_size() const;
virtual const ConcreteEnvironment& get_last_environment() const;
virtual const ConcreteEnvironment& get_environment_at(position index) const;
virtual void append_new_environment (ConcreteEnvironment *environment);
virtual size_t get_size () const;
virtual const ConcreteEnvironment &get_last_environment () const;
virtual const ConcreteEnvironment &get_environment_at (position index) const;
virtual void remove(resource_key_t resource_key);
virtual void remove(Process& process);
virtual void remove(Thread& thread);
virtual void remove(Request& request);
virtual void remove(SubRequest& subrequest);
virtual void remove (resource_key_t resource_key);
virtual void remove (Process &process);
virtual void remove (Thread &thread);
virtual void remove (Request &request);
virtual void remove (SubRequest &subrequest);
virtual void clear();
virtual void clear ();
virtual ResourcePair add_resource(const Glib::ustring& name,
bool preemptable = false,
size_t places = 1,
size_t availability = 0);
virtual ResourcePair
add_resource (const Glib::ustring &name, bool preemptable = false, size_t places = 1, size_t availability = 0);
virtual void edit_resource(Resource& resource,
const Glib::ustring& name,
bool preemptable = false,
size_t places = 1,
size_t availability = 0);
virtual void edit_resource (Resource &resource, const Glib::ustring &name, bool preemptable = false,
size_t places = 1, size_t availability = 0);
virtual DynamicProcess& add_process(const Glib::ustring& name,
time_t arrival_time,
prio_t base_priority = 0);
virtual DynamicProcess &add_process (const Glib::ustring &name, time_t arrival_time, prio_t base_priority = 0);
virtual void edit_process(Process& process,
const Glib::ustring& name,
time_t arrival_time,
prio_t base_priority = 0);
virtual void edit_process (Process &process, const Glib::ustring &name, time_t arrival_time, prio_t base_priority = 0);
virtual DynamicThread& add_thread(const Glib::ustring& name,
Process& parent,
time_t cpu_time,
time_t arrival_time = 0,
prio_t base_priority = 0);
virtual DynamicThread &add_thread (const Glib::ustring &name, Process &parent, time_t cpu_time,
time_t arrival_time = 0, prio_t base_priority = 0);
virtual void edit_thread(Thread& thread,
const Glib::ustring& name,
time_t cpu_time,
time_t arrival_time = 0,
virtual void edit_thread (Thread &thread, const Glib::ustring &name, time_t cpu_time, time_t arrival_time = 0,
prio_t base_priority = 0);
virtual DynamicRequest& add_request(Thread& owner,
time_t instant);
virtual DynamicRequest &add_request (Thread &owner, time_t instant);
virtual void edit_request(Request& request,
time_t instant);
virtual void edit_request (Request &request, time_t instant);
virtual DynamicSubRequest& add_subrequest(Request& request,
resource_key_t resource_key,
time_t duration);
virtual DynamicSubRequest &add_subrequest (Request &request, resource_key_t resource_key, time_t duration);
virtual void edit_subrequest(SubRequest& subrequest,
resource_key_t resource_key,
time_t duration);
virtual void edit_subrequest (SubRequest &subrequest, resource_key_t resource_key, time_t duration);
// sets the front to position p
virtual void set_front(position p);
virtual void set_front (position p);
bool is_sealed() const;
bool is_sealed () const;
// (Returns if the History was sealed before this call)
bool seal();
bool seal ();
void reset(); // Implements a virtual method
void reset (); // Implements a virtual method
protected:
typedef std::vector<ConcreteEnvironment*> Snapshots;
typedef std::vector<ConcreteEnvironment *> Snapshots;
Snapshots _snapshots;
private:
// Disable assignment, implement it only if needed
ConcreteHistory& operator=(const ConcreteHistory& op2);
ConcreteHistory &operator= (const ConcreteHistory &op2);
bool _sealed;
}
; //~ class ConcreteHistory
}; //~ class ConcreteHistory
}//~ namespace sgpem
} // namespace sgpem
#endif //~ CONCRETE_HISTORY_HH

View File

@ -20,11 +20,11 @@
#include "concrete_process_statistics.hh"
#include "concrete_thread_statistics.hh"
#include <sgpemv2/simulation.hh>
#include <sgpemv2/history.hh>
#include <sgpemv2/environment.hh>
#include <sgpemv2/schedulable.hh>
#include <sgpemv2/history.hh>
#include <sgpemv2/process.hh>
#include <sgpemv2/schedulable.hh>
#include <sgpemv2/simulation.hh>
#include <sgpemv2/thread.hh>
#include <iostream>
@ -41,13 +41,12 @@ using namespace sgpem;
\param _threads_stats The statistics of the threads belonging to "core"
*/
ConcreteProcessStatistics::ConcreteProcessStatistics(const Process* core, const int& instant):
_core(core)
ConcreteProcessStatistics::ConcreteProcessStatistics (const Process *core, const int &instant) : _core (core)
{
//retrieve threads statistics necessary to calculate "core"'s statistics
vector<const Thread*> threads = core->get_threads();
for (unsigned int i_t = 0; i_t < threads.size(); i_t++)
_threads_stats.push_back(ConcreteThreadStatistics(threads[i_t], instant));
vector<const Thread *> threads = core->get_threads ();
for (unsigned int i_t = 0; i_t < threads.size (); i_t++)
_threads_stats.push_back (ConcreteThreadStatistics (threads[i_t], instant));
//inizialize variables
@ -64,54 +63,53 @@ ConcreteProcessStatistics::ConcreteProcessStatistics(const Process* core, const
//iterate through threads statistics
vector<ConcreteThreadStatistics>::const_iterator i;
for(i = _threads_stats.begin(); i != _threads_stats.end(); i++)
for (i = _threads_stats.begin (); i != _threads_stats.end (); i++)
{
Thread* t = const_cast<Thread*>((*i).get_core());
if (t->get_process() == *core)
Thread *t = const_cast<Thread *> ((*i).get_core ());
if (t->get_process () == *core)
{ //found a thread belonging to "core"
_execution_time += (*i).get_execution_time();
_resource_usage_time += (*i).get_resource_usage_time();
_execution_time += (*i).get_execution_time ();
_resource_usage_time += (*i).get_resource_usage_time ();
if ((*i).get_response_time() != -1)
if ((*i).get_response_time () != -1)
{
_average_response_time += (*i).get_response_time();
_average_response_time += (*i).get_response_time ();
arrived_threads++;
}
if ((*i).get_response_time() != -1 && someone_began == false)
if ((*i).get_response_time () != -1 && someone_began == false)
{
someone_began = true;
min_reponse = (*i).get_response_time();
min_reponse = (*i).get_response_time ();
}
if(someone_began && (*i).get_response_time() != -1 && (*i).get_response_time() + (*i).get_real_arrival_time() < min_reponse)
min_reponse = (*i).get_response_time() + (*i).get_real_arrival_time();
if (someone_began && (*i).get_response_time () != -1 && (*i).get_response_time () + (*i).get_real_arrival_time () < min_reponse)
min_reponse = (*i).get_response_time () + (*i).get_real_arrival_time ();
if ((*i).get_real_arrival_time() + (*i).get_execution_time() + (*i).get_total_inactivity() > _turn_around)
_turn_around = (*i).get_real_arrival_time() + (*i).get_execution_time() + (*i).get_total_inactivity();
if ((*i).get_real_arrival_time () + (*i).get_execution_time () + (*i).get_total_inactivity () > _turn_around)
_turn_around = (*i).get_real_arrival_time () + (*i).get_execution_time () + (*i).get_total_inactivity ();
}
}
//******* AAARRRGGHH!!!
//We have to iterate the whole History ONLY to retreive _resource_waitings_time !!
//
const History& hist = Simulation::get_instance().get_history();
for (int time=0; time < instant; time++)
const History &hist = Simulation::get_instance ().get_history ();
for (int time = 0; time < instant; time++)
{
const Environment& env = hist.get_environment_at(time);
const vector<Process*> procs = env.get_processes();
const Environment &env = hist.get_environment_at (time);
const vector<Process *> procs = env.get_processes ();
for (unsigned int i_p=0; i_p < procs.size(); i_p++)
if (*procs[i_p] == *core && procs[i_p]->get_state() == Schedulable::state_blocked)
for (unsigned int i_p = 0; i_p < procs.size (); i_p++)
if (*procs[i_p] == *core && procs[i_p]->get_state () == Schedulable::state_blocked)
_resource_waitings_time++;
}
//set other variables
if(core->get_total_cpu_time() != 0)
_execution_progress = (_execution_time*100) / core->get_total_cpu_time();
if (core->get_total_cpu_time () != 0)
_execution_progress = (_execution_time * 100) / core->get_total_cpu_time ();
else
_execution_progress = 0;
@ -120,75 +118,75 @@ ConcreteProcessStatistics::ConcreteProcessStatistics(const Process* core, const
if (_turn_around == 0)
_efficiency = -1;
else
_efficiency = (_execution_time*100)/_turn_around;
_efficiency = (_execution_time * 100) / _turn_around;
_response_time = min_reponse;
if (arrived_threads != 0)
_average_response_time = (float)((int)((_average_response_time/arrived_threads)*100))/100;
_average_response_time = (float) ((int) ((_average_response_time / arrived_threads) * 100)) / 100;
}
ConcreteProcessStatistics::~ConcreteProcessStatistics()
ConcreteProcessStatistics::~ConcreteProcessStatistics ()
{
}
int
ConcreteProcessStatistics::get_execution_time() const
ConcreteProcessStatistics::get_execution_time () const
{
return _execution_time;
}
int
ConcreteProcessStatistics::get_execution_progress() const
ConcreteProcessStatistics::get_execution_progress () const
{
return _execution_progress;
}
int
ConcreteProcessStatistics::get_total_inactivity() const
ConcreteProcessStatistics::get_total_inactivity () const
{
return _total_inactivity;
}
int
ConcreteProcessStatistics::get_response_time() const
ConcreteProcessStatistics::get_response_time () const
{
return _response_time;
}
int
ConcreteProcessStatistics::get_turn_around() const
ConcreteProcessStatistics::get_turn_around () const
{
return _turn_around;
}
int
ConcreteProcessStatistics::get_efficiency() const
ConcreteProcessStatistics::get_efficiency () const
{
return _efficiency;
}
int
ConcreteProcessStatistics::get_resource_usage_time() const
ConcreteProcessStatistics::get_resource_usage_time () const
{
return _resource_usage_time;
}
int
ConcreteProcessStatistics::get_resource_waitings_time() const
ConcreteProcessStatistics::get_resource_waitings_time () const
{
return _resource_waitings_time;
}
float
ConcreteProcessStatistics::get_average_response_time() const
ConcreteProcessStatistics::get_average_response_time () const
{
return _average_response_time;
}
const Process*
ConcreteProcessStatistics::get_core() const
const Process *
ConcreteProcessStatistics::get_core () const
{
return _core;
}
@ -197,11 +195,11 @@ ConcreteProcessStatistics::get_core() const
\warning Don't delete these pointers!!
\warning These pointers are not valid anymore after the destruction of "this"
*/
vector<const ThreadStatistics*>
ConcreteProcessStatistics::get_threads_statistics() const
vector<const ThreadStatistics *>
ConcreteProcessStatistics::get_threads_statistics () const
{
vector<const ThreadStatistics*> rit;
for (unsigned int i=0; i < _threads_stats.size(); i++)
rit.push_back(&_threads_stats[i]);
vector<const ThreadStatistics *> rit;
for (unsigned int i = 0; i < _threads_stats.size (); i++)
rit.push_back (&_threads_stats[i]);
return rit;
}

View File

@ -22,47 +22,47 @@
#define CONCRETE_PROCESS_STATISTICS_HH 1
#include "concrete_thread_statistics.hh"
#include <sgpemv2/process_statistics.hh>
#include <sgpemv2/thread_statistics.hh>
#include "concrete_thread_statistics.hh"
namespace sgpem
{
class ConcreteStatistics;
class ConcreteStatistics;
/** \brief Represents the statistics of a Process
/** \brief Represents the statistics of a Process
This class is a direct subclass of the abstract class ProcessStatistics.
For the documentation af all methods refere to it.
*/
class SG_DLLLOCAL ConcreteProcessStatistics : public ProcessStatistics
{
class SG_DLLLOCAL ConcreteProcessStatistics : public ProcessStatistics
{
public:
friend class ConcreteStatistics;
~ConcreteProcessStatistics ();
int get_execution_time() const;
int get_execution_progress() const;
int get_total_inactivity() const;
int get_response_time() const;
float get_average_response_time() const;
int get_turn_around() const;
int get_efficiency() const;
int get_resource_usage_time() const;
int get_resource_waitings_time() const;
int get_execution_time () const;
int get_execution_progress () const;
int get_total_inactivity () const;
int get_response_time () const;
float get_average_response_time () const;
int get_turn_around () const;
int get_efficiency () const;
int get_resource_usage_time () const;
int get_resource_waitings_time () const;
const Process* get_core() const;
const Process *get_core () const;
std::vector<const ThreadStatistics *> get_threads_statistics () const;
std::vector<const ThreadStatistics*> get_threads_statistics() const;
private:
ConcreteProcessStatistics (const Process* core, const int& instant);
ConcreteProcessStatistics (const Process *core, const int &instant);
const Process* _core;
const Process *_core;
float _average_response_time;
std::vector<ConcreteThreadStatistics> _threads_stats;
};
}
};
} // namespace sgpem
#endif

View File

@ -20,41 +20,40 @@
#include "concrete_simulation.hh"
#include <sgpemv2/simulation_observer.hh>
#include <sgpemv2/scheduler.hh>
#include <sgpemv2/cpu_policies_gatekeeper.hh>
#include <sgpemv2/resource_policies_gatekeeper.hh>
#include <sgpemv2/scheduler.hh>
#include <sgpemv2/simulation_observer.hh>
#include <cassert>
#include <algorithm>
#include <cassert>
#include <functional>
#include <string>
#include <iostream>
#include <string>
using namespace sgpem;
ConcreteSimulation::ConcreteSimulation() :
Simulation(), _state(state_stopped),
_mode(mode_continuous), _policy(NULL), _resource_policy(NULL)
ConcreteSimulation::ConcreteSimulation ()
: Simulation (), _state (state_stopped), _mode (mode_continuous), _policy (NULL), _resource_policy (NULL)
{
}
void
ConcreteSimulation::set_mode(const mode new_mode)
ConcreteSimulation::set_mode (const mode new_mode)
{
_mode = new_mode;
}
Simulation::mode
ConcreteSimulation::get_mode() const
ConcreteSimulation::get_mode () const
{
return _mode;
}
void
ConcreteSimulation::jump_to(History::position p)
ConcreteSimulation::jump_to (History::position p)
{
switch (_state)
{
@ -62,7 +61,7 @@ ConcreteSimulation::jump_to(History::position p)
// pauses the simulation (done below)
break;
case state_stopped:
_history.set_front(0);
_history.set_front (0);
break;
default:
break;
@ -70,51 +69,51 @@ ConcreteSimulation::jump_to(History::position p)
// Disable momentarily updates for registered observers on
// sgpem::Simulation and sgpem::History.
History::LockNotify h_lock(_history);
Simulation::LockNotify s_lock(*this);
History::LockNotify h_lock (_history);
Simulation::LockNotify s_lock (*this);
pause();
pause ();
bool yet_to_finish = true;
History::position increment = 0;
while (yet_to_finish && p > _history.get_front() + increment)
while (yet_to_finish && p > _history.get_front () + increment)
{
yet_to_finish = step();
yet_to_finish = step ();
increment++;
}
get_history().set_front(std::min(p, _history.get_size()));
get_history ().set_front (std::min (p, _history.get_size ()));
if (!yet_to_finish)
stop();
stop ();
}
void
ConcreteSimulation::pause()
ConcreteSimulation::pause ()
{
if(_state != state_paused)
if (_state != state_paused)
{
_state = state_paused;
notify_change();
notify_change ();
}
}
void
ConcreteSimulation::stop()
ConcreteSimulation::stop ()
{
if(_state != state_stopped)
if (_state != state_stopped)
{
_state = state_stopped;
notify_change();
notify_change ();
}
}
void
ConcreteSimulation::run()
ConcreteSimulation::run ()
{
switch (_state)
{
case state_stopped:
_history.set_front(0);
_history.set_front (0);
break;
default:
break;
@ -123,13 +122,12 @@ ConcreteSimulation::run()
_state = state_running;
//step forward
bool yet_to_finish = step();
_history.set_front(_history.get_front() + 1);
bool yet_to_finish = step ();
_history.set_front (_history.get_front () + 1);
if (yet_to_finish)
{
if(_mode == mode_step_by_step)
pause();
if (_mode == mode_step_by_step)
pause ();
else
// We remain in running state, and we notify everybody!
// This is non-trivial, and we must do so since we
@ -137,131 +135,132 @@ ConcreteSimulation::run()
// touch this if you don't provide another way to tell
// a SimulationObserver that the simulation advanced
// and *yet* it is in running state!
notify_change();
notify_change ();
}
else
// Simulation ended
stop();
stop ();
}
bool
ConcreteSimulation::step()
ConcreteSimulation::step ()
{
if (get_policy() == nullptr)
if (get_policy () == nullptr)
{
stop();
throw NullPolicyException("no CPU policy selected");
stop ();
throw NullPolicyException ("no CPU policy selected");
}
if (get_resource_policy() == nullptr)
if (get_resource_policy () == nullptr)
{
stop();
throw NullPolicyException("no resource policy selected");
stop ();
throw NullPolicyException ("no resource policy selected");
}
try
{
// step forward
bool yet_to_finish = true;
if (_history.get_front() == _history.get_size() - 1)
if (_history.get_front () == _history.get_size () - 1)
{
if(!_history.is_sealed())
yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy(), *get_resource_policy());
if (!_history.is_sealed ())
yet_to_finish = Scheduler::get_instance ().step_forward (_history, *get_policy (), *get_resource_policy ());
else
yet_to_finish = false;
}
if (!yet_to_finish) _history.seal();
if (!yet_to_finish)
_history.seal ();
// since the simulation expects to be notified
// of simulation termination when reaching the last environment
// and the front will be updated just out of this method,
// we have to make this horrible thing
if (_history.get_front() == _history.get_size() - 2 && _history.is_sealed())
if (_history.get_front () == _history.get_size () - 2 && _history.is_sealed ())
yet_to_finish = false;
return yet_to_finish;
}
catch (const CPUPolicyException& e)
catch (const CPUPolicyException &e)
{
stop();
stop ();
throw;
}
}
Simulation::state
ConcreteSimulation::get_state() const
ConcreteSimulation::get_state () const
{
return _state;
}
ConcreteHistory&
ConcreteSimulation::get_history()
ConcreteHistory &
ConcreteSimulation::get_history ()
{
return _history;
}
const ConcreteHistory&
ConcreteSimulation::get_history() const
const ConcreteHistory &
ConcreteSimulation::get_history () const
{
return _history;
}
void
ConcreteSimulation::set_policy(CPUPolicy* p)
ConcreteSimulation::set_policy (CPUPolicy *p)
{
stop();
stop ();
try
{
CPUPoliciesGatekeeper::get_instance().activate_policy(&_history, p);
CPUPoliciesGatekeeper::get_instance ().activate_policy (&_history, p);
_policy = p;
}
catch(const CPUPolicyException& e1)
catch (const CPUPolicyException &e1)
{
try
{
// this is a no-op if _policy is nullptr
CPUPoliciesGatekeeper::get_instance().activate_policy(&_history, _policy);
CPUPoliciesGatekeeper::get_instance ().activate_policy (&_history, _policy);
}
catch(const CPUPolicyException& e2)
catch (const CPUPolicyException &e2)
{
_policy = nullptr;
std::string msg = _("unable to change policy and to restore the previous: ");
msg += e2.what();
std::string msg = _ ("unable to change policy and to restore the previous: ");
msg += e2.what ();
throw CPUPolicyException(msg);
throw CPUPolicyException (msg);
}
std::string msg = _("unable to change policy: ");
msg+= e1.what();
std::string msg = _ ("unable to change policy: ");
msg += e1.what ();
throw CPUPolicyException(msg);
throw CPUPolicyException (msg);
}
}
CPUPolicy*
ConcreteSimulation::get_policy()
CPUPolicy *
ConcreteSimulation::get_policy ()
{
return _policy;
}
void
ConcreteSimulation::set_resource_policy(ResourcePolicy* p)
ConcreteSimulation::set_resource_policy (ResourcePolicy *p)
{
stop();
ResourcePoliciesGatekeeper::get_instance().activate_policy(&_history, p);
stop ();
ResourcePoliciesGatekeeper::get_instance ().activate_policy (&_history, p);
_resource_policy = p;
}
ResourcePolicy*
ConcreteSimulation::get_resource_policy()
ResourcePolicy *
ConcreteSimulation::get_resource_policy ()
{
return _resource_policy;
}

View File

@ -22,8 +22,8 @@
#define CONCRETE_SIMULATION_HH 1
#include <sgpemv2/simulation.hh>
#include "concrete_history.hh"
#include <sgpemv2/simulation.hh>
#include <map>
#include <stdexcept>
@ -32,12 +32,12 @@
namespace sgpem
{
class ConcreteSimulation;
class ConcreteSimulation;
class SG_DLLLOCAL ConcreteSimulation : public Simulation
{
class SG_DLLLOCAL ConcreteSimulation : public Simulation
{
public:
ConcreteSimulation();
ConcreteSimulation ();
/**
* \brief Runs the simulation.
@ -45,7 +45,7 @@ namespace sgpem
* Advances the simulation by one or more steps, depending on the
* actual state and on the value set with set_mode().
*/
void run();
void run ();
/**
\brief Pauses a running simulation.
@ -54,7 +54,7 @@ namespace sgpem
Calling again run() will cause the simulation to start from the current
simulation step.
*/
void pause();
void pause ();
/**
\brief Jumps the simulation to the specified instant
@ -62,7 +62,7 @@ namespace sgpem
Pauses the simulation and jumps to the specified instant
\throw UserInterruptException, NullPolicyException, MalformedPolicyException
*/
void jump_to(History::position p);
void jump_to (History::position p);
/**
\brief Stops the simulation.
@ -70,7 +70,7 @@ namespace sgpem
Behaves in the same way as pause(), except that the next call to run()
will cause the simulation to start from the beginning.
*/
void stop();
void stop ();
/**
\brief This methods allows to change the way the simulation progresses.
@ -81,62 +81,61 @@ namespace sgpem
waiting the time defined with set_timer() between each step, until all
processes have terminated, or some error happens.
*/
void set_mode(mode new_mode);
void set_mode (mode new_mode);
/**
\return The simulation advancement mode: 0 if step-to-step, 1 if
continue.
*/
mode get_mode() const;
mode get_mode () const;
/**
\return The curent simulation state.
\see Simulation::state
*/
state get_state() const;
state get_state () const;
/**
\throw An instance of CPUPolicyException, \b not a derived class!!!
*/
void set_policy(CPUPolicy*);
void set_policy (CPUPolicy *);
/**
\brief Setup the resource policy to be used by the system.
*/
void set_resource_policy(ResourcePolicy*);
void set_resource_policy (ResourcePolicy *);
/**
\return A reference to the ConcreteHistory associated with this simulation.
*/
ConcreteHistory& get_history();
ConcreteHistory &get_history ();
/**
\return A const reference to the ConcreteHistory associated with this simulation.
*/
const ConcreteHistory& get_history() const;
const ConcreteHistory &get_history () const;
/**
\return The CPU policy currently in use.
*/
CPUPolicy* get_policy();
CPUPolicy *get_policy ();
/**
\return The resource policy currently in use.
*/
ResourcePolicy * get_resource_policy();
ResourcePolicy *get_resource_policy ();
private:
state _state;
mode _mode;
ConcreteHistory _history;
CPUPolicy* _policy;
ResourcePolicy* _resource_policy;
CPUPolicy *_policy;
ResourcePolicy *_resource_policy;
bool step();
};
bool step ();
};
}
} // namespace sgpem
#endif

View File

@ -19,10 +19,10 @@
#include "concrete_simulation_statistics.hh"
#include <sgpemv2/statistics.hh>
#include <sgpemv2/simulation.hh>
#include <sgpemv2/history.hh>
#include <sgpemv2/environment.hh>
#include <sgpemv2/history.hh>
#include <sgpemv2/simulation.hh>
#include <sgpemv2/statistics.hh>
#include <iostream>
#include <math.h>
@ -30,11 +30,11 @@
using namespace std;
using namespace sgpem;
ConcreteSimulationStatistics::~ConcreteSimulationStatistics()
ConcreteSimulationStatistics::~ConcreteSimulationStatistics ()
{
}
ConcreteSimulationStatistics::ConcreteSimulationStatistics(const std::vector<ConcreteProcessStatistics>& proc_stats, const int& instant)
ConcreteSimulationStatistics::ConcreteSimulationStatistics (const std::vector<ConcreteProcessStatistics> &proc_stats, const int &instant)
{
_average_inactivity_time = 0;
_average_turn_around = 0;
@ -42,7 +42,7 @@ ConcreteSimulationStatistics::ConcreteSimulationStatistics(const std::vector<Con
_average_efficiency = 0;
_terminated_processes = 0;
_terminated_threads = 0;
_average_execution_progress = 0 ;
_average_execution_progress = 0;
_average_processes_throughput = 0;
_average_threads_throughput = 0;
@ -55,15 +55,15 @@ ConcreteSimulationStatistics::ConcreteSimulationStatistics(const std::vector<Con
//but on the current environment:
//iterate through all processes
vector<Process*> procs = Simulation::get_instance().get_history().get_environment_at(instant).get_processes();
for (unsigned int i=0; i < procs.size(); i++)
vector<Process *> procs = Simulation::get_instance ().get_history ().get_environment_at (instant).get_processes ();
for (unsigned int i = 0; i < procs.size (); i++)
{
if (procs[i]->get_state() == Schedulable::state_terminated)
if (procs[i]->get_state () == Schedulable::state_terminated)
_terminated_processes++;
vector<Thread*> threads = procs[i]->get_threads();
vector<Thread *> threads = procs[i]->get_threads ();
//iterate through all threads of this process
for (unsigned int ii=0; ii < threads.size(); ii++)
if (threads[ii]->get_state() == Schedulable::state_terminated)
for (unsigned int ii = 0; ii < threads.size (); ii++)
if (threads[ii]->get_state () == Schedulable::state_terminated)
_terminated_threads++;
}
@ -71,106 +71,100 @@ ConcreteSimulationStatistics::ConcreteSimulationStatistics(const std::vector<Con
//SUM all values from processes and threads
vector<ConcreteProcessStatistics>::const_iterator p;
for (p = proc_stats.begin(); p != proc_stats.end(); p++)
for (p = proc_stats.begin (); p != proc_stats.end (); p++)
{
if (p->get_response_time() != -1)
if (p->get_response_time () != -1)
{
started_schedulables_count++;
_average_response_time += p->get_response_time();
_average_efficiency += p->get_efficiency();
_average_inactivity_time += p->get_total_inactivity();
_average_turn_around += p->get_turn_around();
_average_execution_progress += p->get_execution_progress();
_average_response_time += p->get_response_time ();
_average_efficiency += p->get_efficiency ();
_average_inactivity_time += p->get_total_inactivity ();
_average_turn_around += p->get_turn_around ();
_average_execution_progress += p->get_execution_progress ();
}
//iterate through all threads of this process
vector<const ThreadStatistics*> thread_stats = p->get_threads_statistics();
vector<const ThreadStatistics*>::const_iterator t;
for (t=thread_stats.begin(); t != thread_stats.end(); t++)
if ((*t)->get_response_time() != -1)
vector<const ThreadStatistics *> thread_stats = p->get_threads_statistics ();
vector<const ThreadStatistics *>::const_iterator t;
for (t = thread_stats.begin (); t != thread_stats.end (); t++)
if ((*t)->get_response_time () != -1)
{
started_schedulables_count++;
_average_response_time += (*t)->get_response_time();
_average_efficiency += (*t)->get_efficiency();
_average_inactivity_time += (*t)->get_total_inactivity();
_average_turn_around += (*t)->get_turn_around();
_average_execution_progress += (*t)->get_execution_progress();
_average_response_time += (*t)->get_response_time ();
_average_efficiency += (*t)->get_efficiency ();
_average_inactivity_time += (*t)->get_total_inactivity ();
_average_turn_around += (*t)->get_turn_around ();
_average_execution_progress += (*t)->get_execution_progress ();
}
}
//make the AVERAGE and ROUND the values
if (started_schedulables_count != 0)
{
modff(((_average_response_time / started_schedulables_count) * 100.0f) / 100.0f, &_average_response_time);
modff(((_average_efficiency / started_schedulables_count) * 100.0f) / 100.0f, &_average_efficiency);
modff(((_average_inactivity_time / started_schedulables_count) * 100.0f) / 100.0f, &_average_inactivity_time);
modff(((_average_turn_around / started_schedulables_count) * 100.0f) / 100.0f, &_average_turn_around);
modff(((_average_execution_progress / started_schedulables_count) * 100.0f) / 100.0f, &_average_execution_progress);
modff (((_average_response_time / started_schedulables_count) * 100.0f) / 100.0f, &_average_response_time);
modff (((_average_efficiency / started_schedulables_count) * 100.0f) / 100.0f, &_average_efficiency);
modff (((_average_inactivity_time / started_schedulables_count) * 100.0f) / 100.0f, &_average_inactivity_time);
modff (((_average_turn_around / started_schedulables_count) * 100.0f) / 100.0f, &_average_turn_around);
modff (((_average_execution_progress / started_schedulables_count) * 100.0f) / 100.0f, &_average_execution_progress);
}
if (instant != 0)
{
modff((((float)_terminated_processes / (float)instant) * 1000.0f) / 1000.0f, &_average_processes_throughput);
modff((((float)_terminated_threads / (float)instant) * 1000.0f) / 1000.0f, &_average_threads_throughput);
modff ((((float) _terminated_processes / (float) instant) * 1000.0f) / 1000.0f, &_average_processes_throughput);
modff ((((float) _terminated_threads / (float) instant) * 1000.0f) / 1000.0f, &_average_threads_throughput);
}
}
float
ConcreteSimulationStatistics::get_average_inactivity_time() const
ConcreteSimulationStatistics::get_average_inactivity_time () const
{
return _average_inactivity_time;
}
float
ConcreteSimulationStatistics::get_average_execution_progress() const
ConcreteSimulationStatistics::get_average_execution_progress () const
{
return _average_execution_progress;
}
float
ConcreteSimulationStatistics::get_average_turn_around() const
ConcreteSimulationStatistics::get_average_turn_around () const
{
return _average_turn_around;
}
float
ConcreteSimulationStatistics::get_average_response_time() const
ConcreteSimulationStatistics::get_average_response_time () const
{
return _average_response_time;
}
float
ConcreteSimulationStatistics::get_average_efficiency() const
ConcreteSimulationStatistics::get_average_efficiency () const
{
return _average_efficiency;
}
int
ConcreteSimulationStatistics::get_terminated_processes() const
ConcreteSimulationStatistics::get_terminated_processes () const
{
return _terminated_processes;
}
int
ConcreteSimulationStatistics::get_terminated_threads() const
ConcreteSimulationStatistics::get_terminated_threads () const
{
return _terminated_threads;
}
float
ConcreteSimulationStatistics::get_average_processes_throughput() const
ConcreteSimulationStatistics::get_average_processes_throughput () const
{
return _average_processes_throughput;
}
float
ConcreteSimulationStatistics::get_average_threads_throughput() const
ConcreteSimulationStatistics::get_average_threads_throughput () const
{
return _average_threads_throughput;
}

View File

@ -22,54 +22,50 @@
#define CONCRETE_SIMULATION_STATISTICS_HH 1
#include <sgpemv2/simulation_statistics.hh>
#include "concrete_process_statistics.hh"
#include <sgpemv2/simulation_statistics.hh>
namespace sgpem
{
class ConcreteStatistics;
class ConcreteStatistics;
/** \brief Represents the statistics of a Simulation
/** \brief Represents the statistics of a Simulation
This class is a direct subclass of the abstract class SimulationStatistics.
For the documentation af all methods refere to it.
*/
class SG_DLLLOCAL ConcreteSimulationStatistics : public SimulationStatistics
{
class SG_DLLLOCAL ConcreteSimulationStatistics : public SimulationStatistics
{
public:
friend class ConcreteStatistics;
~ConcreteSimulationStatistics();
~ConcreteSimulationStatistics ();
float get_average_inactivity_time() const ;
float get_average_execution_progress() const;
float get_average_turn_around() const ;
float get_average_response_time() const ;
float get_average_efficiency() const ;
int get_terminated_processes() const ;
int get_terminated_threads() const ;
float get_average_processes_throughput() const ;
float get_average_threads_throughput() const ;
float get_average_inactivity_time () const;
float get_average_execution_progress () const;
float get_average_turn_around () const;
float get_average_response_time () const;
float get_average_efficiency () const;
int get_terminated_processes () const;
int get_terminated_threads () const;
float get_average_processes_throughput () const;
float get_average_threads_throughput () const;
protected:
ConcreteSimulationStatistics(const std::vector<ConcreteProcessStatistics>& proc_stats, const int& instant);
ConcreteSimulationStatistics (const std::vector<ConcreteProcessStatistics> &proc_stats, const int &instant);
float _average_inactivity_time ;
float _average_execution_progress ;
float _average_turn_around ;
float _average_response_time ;
float _average_efficiency ;
int _terminated_processes ;
int _terminated_threads ;
float _average_processes_throughput ;
float _average_threads_throughput ;
};
}
float _average_inactivity_time;
float _average_execution_progress;
float _average_turn_around;
float _average_response_time;
float _average_efficiency;
int _terminated_processes;
int _terminated_threads;
float _average_processes_throughput;
float _average_threads_throughput;
};
} // namespace sgpem
#endif

View File

@ -19,14 +19,14 @@
#include "concrete_statistics.hh"
#include <sgpemv2/simulation.hh>
#include <sgpemv2/history.hh>
#include <sgpemv2/environment.hh>
#include <sgpemv2/schedulable.hh>
#include <sgpemv2/process.hh>
#include <sgpemv2/thread.hh>
#include "concrete_thread_statistics.hh"
#include "concrete_process_statistics.hh"
#include "concrete_thread_statistics.hh"
#include <sgpemv2/environment.hh>
#include <sgpemv2/history.hh>
#include <sgpemv2/process.hh>
#include <sgpemv2/schedulable.hh>
#include <sgpemv2/simulation.hh>
#include <sgpemv2/thread.hh>
#include <iostream>
@ -34,31 +34,30 @@ using namespace sgpem;
using namespace std;
ConcreteStatistics::ConcreteStatistics(): _sim_stats(0)
ConcreteStatistics::ConcreteStatistics () : _sim_stats (0)
{
calculateStatisticsAt(-1);
calculateStatisticsAt (-1);
}
void
ConcreteStatistics::calculateStatisticsAt(const int& instant)
ConcreteStatistics::calculateStatisticsAt (const int &instant)
{
//retrieve all processes
vector<Process*> procs = Simulation::get_instance().get_history().get_environment_at(0).get_processes();
vector<Process *> procs = Simulation::get_instance ().get_history ().get_environment_at (0).get_processes ();
//create all process statistics (which themselves create their thread statistics)
_proc_stats.clear();
for (unsigned int p = 0; p < procs.size(); p++)
_proc_stats.push_back(ConcreteProcessStatistics(procs[p], instant));
_proc_stats.clear ();
for (unsigned int p = 0; p < procs.size (); p++)
_proc_stats.push_back (ConcreteProcessStatistics (procs[p], instant));
if (_sim_stats)
delete _sim_stats;
//create simulation statistics using just obtained process statistics
_sim_stats = new ConcreteSimulationStatistics(_proc_stats, instant);
_sim_stats = new ConcreteSimulationStatistics (_proc_stats, instant);
}
const SimulationStatistics*
ConcreteStatistics::get_simulation_statistics() const
const SimulationStatistics *
ConcreteStatistics::get_simulation_statistics () const
{
return _sim_stats;
}
@ -67,13 +66,11 @@ ConcreteStatistics::get_simulation_statistics() const
\warning Don't delete these pointers!!
\warning These pointers are not valid anymore AFTER a call to calculateStatisticsAt
*/
std::vector<const ProcessStatistics*>
ConcreteStatistics::get_process_statistics() const
std::vector<const ProcessStatistics *>
ConcreteStatistics::get_process_statistics () const
{
vector<const ProcessStatistics*> rit;
for (unsigned int i=0; i < _proc_stats.size(); i++)
rit.push_back(&_proc_stats[i]);
vector<const ProcessStatistics *> rit;
for (unsigned int i = 0; i < _proc_stats.size (); i++)
rit.push_back (&_proc_stats[i]);
return rit;
}

View File

@ -22,39 +22,34 @@
#define CONCRETE_STATISTICS_HH 1
#include <sgpemv2/statistics.hh>
#include "concrete_process_statistics.hh"
#include "concrete_simulation_statistics.hh"
#include <sgpemv2/statistics.hh>
#include <glibmm/ustring.h>
#include <vector>
namespace sgpem
{
/** \brief Implements the abstract class Statistics
/** \brief Implements the abstract class Statistics
This class is a direct subclass of the abstract class Statistics.
For the documentation af all methods refere to it.
*/
class SG_DLLLOCAL ConcreteStatistics : public Statistics
{
class SG_DLLLOCAL ConcreteStatistics : public Statistics
{
public:
ConcreteStatistics();
ConcreteStatistics ();
void calculateStatisticsAt(const int& instant);
void calculateStatisticsAt (const int &instant);
const SimulationStatistics* get_simulation_statistics() const;
std::vector<const ProcessStatistics*> get_process_statistics() const;
const SimulationStatistics *get_simulation_statistics () const;
std::vector<const ProcessStatistics *> get_process_statistics () const;
private:
ConcreteSimulationStatistics* _sim_stats;
ConcreteSimulationStatistics *_sim_stats;
std::vector<ConcreteProcessStatistics> _proc_stats;
};
}
};
} // namespace sgpem
#endif

View File

@ -19,15 +19,15 @@
#include "concrete_thread_statistics.hh"
#include <sgpemv2/simulation.hh>
#include <sgpemv2/history.hh>
#include <sgpemv2/environment.hh>
#include <sgpemv2/schedulable.hh>
#include <sgpemv2/process.hh>
#include <sgpemv2/thread.hh>
#include <sgpemv2/resource.hh>
#include <sgpemv2/request.hh>
#include <iostream>
#include <sgpemv2/environment.hh>
#include <sgpemv2/history.hh>
#include <sgpemv2/process.hh>
#include <sgpemv2/request.hh>
#include <sgpemv2/resource.hh>
#include <sgpemv2/schedulable.hh>
#include <sgpemv2/simulation.hh>
#include <sgpemv2/thread.hh>
using namespace std;
using namespace sgpem;
@ -37,7 +37,7 @@ using namespace sgpem;
or the whole History
*/
ConcreteThreadStatistics::ConcreteThreadStatistics(const Thread* core, const int& instant): _core(core)
ConcreteThreadStatistics::ConcreteThreadStatistics (const Thread *core, const int &instant) : _core (core)
{
//initializations
_total_inactivity = 0;
@ -50,52 +50,50 @@ ConcreteThreadStatistics::ConcreteThreadStatistics(const Thread* core, const int
bool iniziato = false; //useful for _response_time
const History& hist = Simulation::get_instance().get_history(); //prendo la lista delle risorse
const map<Environment::resource_key_t, Resource*> res = hist.get_environment_at(0).get_resources();
const History &hist = Simulation::get_instance ().get_history (); //prendo la lista delle risorse
const map<Environment::resource_key_t, Resource *> res = hist.get_environment_at (0).get_resources ();
//****** iterate through HISTORY to retreive informations
for (int time=0; time < instant; time++)
for (int time = 0; time < instant; time++)
{
const Environment& env = hist.get_environment_at(time);
const vector<Process*> procs = env.get_processes();
const Environment &env = hist.get_environment_at (time);
const vector<Process *> procs = env.get_processes ();
//looks for the process that owns this thread
for (unsigned int i_p=0; i_p < procs.size(); i_p++)
for (unsigned int i_p = 0; i_p < procs.size (); i_p++)
{
const vector<Thread*> threads = procs[i_p]->get_threads();
const vector<Thread *> threads = procs[i_p]->get_threads ();
//looks for the thread "core"
for (unsigned int i_t = 0; i_t < threads.size(); i_t++)
for (unsigned int i_t = 0; i_t < threads.size (); i_t++)
{
if ( (*threads[i_t]) == (*core) ) //FOUND!!
if ((*threads[i_t]) == (*core)) //FOUND!!
{
if (threads[i_t]->get_state() == Schedulable::state_running)
if (threads[i_t]->get_state () == Schedulable::state_running)
{
iniziato = true;
if( _response_time == -1) //arrives and runs immediately
if (_response_time == -1) //arrives and runs immediately
{
_response_time = 0;
_real_arrival_time = time - procs[i_p]->get_arrival_time() -1;
_real_arrival_time = time - procs[i_p]->get_arrival_time () - 1;
}
_execution_time++;
}
if (threads[i_t]->get_state() != Schedulable::state_future &&
threads[i_t]->get_state() != Schedulable::state_terminated)
if (threads[i_t]->get_state () != Schedulable::state_future && threads[i_t]->get_state () != Schedulable::state_terminated)
{
_turn_around++;
if (!iniziato && _response_time == -1) //arrives and doesn't run
{
_response_time = 0;
_real_arrival_time = time - procs[i_p]->get_arrival_time() -1;
_real_arrival_time = time - procs[i_p]->get_arrival_time () - 1;
}
}
if (threads[i_t]->get_state() == Schedulable::state_blocked
|| threads[i_t]->get_state() == Schedulable::state_ready)
if (threads[i_t]->get_state () == Schedulable::state_blocked || threads[i_t]->get_state () == Schedulable::state_ready)
{
_total_inactivity++;
if (!iniziato && _response_time != -1)
_response_time++;
if (threads[i_t]->get_state() == Schedulable::state_blocked)
if (threads[i_t]->get_state () == Schedulable::state_blocked)
_resource_waitings_time++;
}
}
@ -105,91 +103,91 @@ ConcreteThreadStatistics::ConcreteThreadStatistics(const Thread* core, const int
//for each resource check requests at this istant:
//if the request of this thread is allocated then increase _resource_usage_time
Environment::Resources::const_iterator res_iter = res.begin();
while(res_iter != res.end())
Environment::Resources::const_iterator res_iter = res.begin ();
while (res_iter != res.end ())
{
Environment::resource_key_t key = (*res_iter).first;
vector<SubRequest*> req = env.get_request_queue(key);
for (unsigned int i_r=0; i_r < req.size(); i_r++)
if( (*req[i_r]).get_request().get_thread() == (*core) && (*req[i_r]).get_state() == Request::state_allocated)
vector<SubRequest *> req = env.get_request_queue (key);
for (unsigned int i_r = 0; i_r < req.size (); i_r++)
if ((*req[i_r]).get_request ().get_thread () == (*core) && (*req[i_r]).get_state () == Request::state_allocated)
_resource_usage_time++;
res_iter++;
}
}//istants
} //istants
//set other variables
if (core->get_total_cpu_time() != 0)
_execution_progress = (100*_execution_time)/core->get_total_cpu_time();
if (core->get_total_cpu_time () != 0)
_execution_progress = (100 * _execution_time) / core->get_total_cpu_time ();
if (_turn_around == 0)
_efficiency = -1;
else
_efficiency = (_execution_time*100)/_turn_around;
_efficiency = (_execution_time * 100) / _turn_around;
}
ConcreteThreadStatistics::~ConcreteThreadStatistics()
ConcreteThreadStatistics::~ConcreteThreadStatistics ()
{
}
int
ConcreteThreadStatistics::get_execution_time() const
ConcreteThreadStatistics::get_execution_time () const
{
return _execution_time;
}
int
ConcreteThreadStatistics::get_execution_progress() const
ConcreteThreadStatistics::get_execution_progress () const
{
return _execution_progress;
}
int
ConcreteThreadStatistics::get_total_inactivity() const
ConcreteThreadStatistics::get_total_inactivity () const
{
return _total_inactivity;
}
int
ConcreteThreadStatistics::get_response_time() const
ConcreteThreadStatistics::get_response_time () const
{
return _response_time;
}
int
ConcreteThreadStatistics::get_turn_around() const
ConcreteThreadStatistics::get_turn_around () const
{
return _turn_around;
}
int
ConcreteThreadStatistics::get_efficiency() const
ConcreteThreadStatistics::get_efficiency () const
{
return _efficiency;
}
int
ConcreteThreadStatistics::get_resource_usage_time() const
ConcreteThreadStatistics::get_resource_usage_time () const
{
return _resource_usage_time;
}
int
ConcreteThreadStatistics::get_resource_waitings_time() const
ConcreteThreadStatistics::get_resource_waitings_time () const
{
return _resource_waitings_time;
}
int
ConcreteThreadStatistics::get_real_arrival_time() const
ConcreteThreadStatistics::get_real_arrival_time () const
{
return _real_arrival_time;
}
const Thread*
ConcreteThreadStatistics::get_core() const
const Thread *
ConcreteThreadStatistics::get_core () const
{
return _core;
}

View File

@ -22,7 +22,6 @@
#define CONCRETE_THREAD_STATISTICS_HH 1
#include <sgpemv2/thread_statistics.hh>
#include <glibmm/ustring.h>
@ -30,38 +29,38 @@
namespace sgpem
{
class ConcreteProcessStatistics;
class ConcreteProcessStatistics;
/** \brief Represents the statistics of a Thread
/** \brief Represents the statistics of a Thread
This class is a direct subclass of the abstract class ThreadStatistics.
For the documentation af all methods refere to it.
*/
class SG_DLLLOCAL ConcreteThreadStatistics : public ThreadStatistics
{
class SG_DLLLOCAL ConcreteThreadStatistics : public ThreadStatistics
{
public:
friend class ConcreteProcessStatistics;
~ConcreteThreadStatistics();
~ConcreteThreadStatistics ();
int get_execution_time() const;
int get_execution_progress() const;
int get_total_inactivity() const;
int get_response_time() const;
int get_turn_around() const;
int get_efficiency() const;
int get_resource_usage_time() const;
int get_resource_waitings_time() const;
int get_execution_time () const;
int get_execution_progress () const;
int get_total_inactivity () const;
int get_response_time () const;
int get_turn_around () const;
int get_efficiency () const;
int get_resource_usage_time () const;
int get_resource_waitings_time () const;
const Thread* get_core() const;
const Thread *get_core () const;
int get_real_arrival_time() const; //useful for ProcessStatistics
int get_real_arrival_time () const; //useful for ProcessStatistics
private:
ConcreteThreadStatistics(const Thread* core, const int& instant);
const Thread* _core;
ConcreteThreadStatistics (const Thread *core, const int &instant);
const Thread *_core;
int _real_arrival_time;
};
}
};
} // namespace sgpem
#endif

View File

@ -18,10 +18,9 @@
// along with SGPEMv2. If not, see http://www.gnu.org/licenses/.
#include "cpp_resource_policy_manager.hh"
#include "resource_policy_lifo.hh"
#include "resource_policy_fifo.hh"
#include "resource_policy_lifo.hh"
#include "resource_policy_priority.hh"
#include "resource_policy_priority_inheritance.hh"
@ -33,24 +32,24 @@ using namespace sgpem;
CppResourcePolicyManager CppResourcePolicyManager::_default_instance;
CppResourcePolicyManager::CppResourcePolicyManager()
CppResourcePolicyManager::CppResourcePolicyManager ()
{
ResourcePoliciesGatekeeper::get_instance().register_manager(this);
ResourcePoliciesGatekeeper::get_instance ().register_manager (this);
// Includes default policies.
_policies.push_back(new ResourcePolicyLiFo());
_policies.push_back(new ResourcePolicyFiFo());
_policies.push_back(new ResourcePolicyPriority());
_policies.push_back(new ResourcePolicyPriorityInheritance());
_policies.push_back (new ResourcePolicyLiFo ());
_policies.push_back (new ResourcePolicyFiFo ());
_policies.push_back (new ResourcePolicyPriority ());
_policies.push_back (new ResourcePolicyPriorityInheritance ());
}
CppResourcePolicyManager::~CppResourcePolicyManager()
CppResourcePolicyManager::~CppResourcePolicyManager ()
{
ResourcePoliciesGatekeeper::get_instance().unregister_manager(this);
ResourcePoliciesGatekeeper::get_instance ().unregister_manager (this);
}
const std::vector<ResourcePolicy*>&
CppResourcePolicyManager::get_avail_policies() const
const std::vector<ResourcePolicy *> &
CppResourcePolicyManager::get_avail_policies () const
{
return _policies;
}

View File

@ -23,7 +23,7 @@
namespace sgpem
{
class ResourcePolicy;
class ResourcePolicy;
}
#include <sgpemv2/resource_policy_manager.hh>
@ -32,33 +32,32 @@ namespace sgpem
namespace sgpem
{
class CppResourcePolicyManager;
class CppResourcePolicyManager;
/**
/**
ResourcePolicyManager is the Abstract Factory for \ref ResourcePolicy objects.
*/
class SG_DLLLOCAL CppResourcePolicyManager : public ResourcePolicyManager
{
class SG_DLLLOCAL CppResourcePolicyManager : public ResourcePolicyManager
{
public:
/** \brief CppResourcePolicyManager constructor
*
* Registers itself to the ResourcePoliciesGatekeeper singleton.
*/
CppResourcePolicyManager();
CppResourcePolicyManager ();
virtual ~CppResourcePolicyManager();
virtual ~CppResourcePolicyManager ();
virtual const std::vector<ResourcePolicy*>& get_avail_policies() const;
virtual const std::vector<ResourcePolicy *> &get_avail_policies () const;
private:
std::vector<ResourcePolicy*> _policies;
std::vector<ResourcePolicy *> _policies;
// an Instance of this class is created by default and it is registered to
// the ResourcePolicyGateKeeper
static CppResourcePolicyManager _default_instance;
};
};
} //~ namespace sgpem
} // namespace sgpem
#endif

View File

@ -18,12 +18,10 @@
// along with SGPEMv2. If not, see http://www.gnu.org/licenses/.
#include <sgpemv2/cpu_policies_gatekeeper.hh>
#include <sgpemv2/cpu_policy_manager.hh>
#include <sgpemv2/cpu_policy.hh>
#include "concrete_history.hh"
#include <sgpemv2/cpu_policies_gatekeeper.hh>
#include <sgpemv2/cpu_policy.hh>
#include <sgpemv2/cpu_policy_manager.hh>
// Include full template definition only in implementation files:
#include <sgpemv2/templates/singleton.tcc>
@ -34,136 +32,136 @@
#include <cassert>
#include <iostream>
using std::vector;
using std::map;
using std::find;
using std::map;
using std::runtime_error;
using std::vector;
using namespace sgpem;
// Explicit template instantiation to allow to export symbols from the DSO.
template class sgpem::Singleton<CPUPoliciesGatekeeper>;
typedef vector<CPUPolicyManager*>::iterator ManagerIterator;
typedef map<History*, CPUPolicy*>::iterator ActiveIterator;
typedef vector<CPUPolicyManager *>::iterator ManagerIterator;
typedef map<History *, CPUPolicy *>::iterator ActiveIterator;
vector<CPUPolicyManager*>
CPUPoliciesGatekeeper::get_registered() const
vector<CPUPolicyManager *>
CPUPoliciesGatekeeper::get_registered () const
{
return _registered;
}
void
CPUPoliciesGatekeeper::register_manager(CPUPolicyManager* manager)
CPUPoliciesGatekeeper::register_manager (CPUPolicyManager *manager)
{
assert(manager != nullptr);
assert (manager != nullptr);
ManagerIterator end = _registered.end();
ManagerIterator end = _registered.end ();
if (find(_registered.begin(), end, manager) == end)
_registered.push_back(manager);
if (find (_registered.begin (), end, manager) == end)
_registered.push_back (manager);
}
void
CPUPoliciesGatekeeper::unregister_manager(CPUPolicyManager* manager)
CPUPoliciesGatekeeper::unregister_manager (CPUPolicyManager *manager)
{
assert(manager != nullptr);
assert (manager != nullptr);
ManagerIterator end = _registered.end();
ManagerIterator pos = find(_registered.begin(), end, manager);
ManagerIterator end = _registered.end ();
ManagerIterator pos = find (_registered.begin (), end, manager);
if (pos != end)
{
deactivate_policies(*pos);
_registered.erase(pos);
deactivate_policies (*pos);
_registered.erase (pos);
}
}
CPUPolicy*
CPUPoliciesGatekeeper::get_current_policy(History* history)
CPUPolicy *
CPUPoliciesGatekeeper::get_current_policy (History *history)
{
assert(history != nullptr);
assert (history != nullptr);
ActiveIterator policy = _active_policies.find(history);
ActiveIterator policy = _active_policies.find (history);
if (policy == _active_policies.end())
throw runtime_error("No active policy associated with this "
if (policy == _active_policies.end ())
throw runtime_error (
"No active policy associated with this "
"history is available.");
return policy->second;
}
void
CPUPoliciesGatekeeper::activate_policy(History *history, CPUPolicy* policy)
CPUPoliciesGatekeeper::activate_policy (History *history, CPUPolicy *policy)
{
assert(history != nullptr);
assert (history != nullptr);
ActiveIterator end = _active_policies.end();
ActiveIterator pos = _active_policies.find(history);
ActiveIterator end = _active_policies.end ();
ActiveIterator pos = _active_policies.find (history);
// deactivate the policy, if necessary
if (pos != end)
{
// nothing to do in this case
if(pos->second == policy)
if (pos->second == policy)
return;
pos->second->deactivate();
pos->second->deactivate ();
}
// if policy is nullptr, simply erase the entry and return, since we are sure the policy is
// not active due to the previous lines
if(policy == nullptr)
if (policy == nullptr)
{
// this is a no-op if history is not a key used in the map
_active_policies.erase(history);
_active_policies.erase (history);
return;
}
try
{
policy->activate();
policy->activate ();
_active_policies[history] = policy;
// the content of history (if any) is not vaild any more.
down_cast<ConcreteHistory*>(history)->reset();
down_cast<ConcreteHistory *> (history)->reset ();
}
catch(const CPUPolicyException& e)
catch (const CPUPolicyException &e)
{
// the caller need to know if it failed
throw;
}
}
CPUPoliciesGatekeeper::CPUPoliciesGatekeeper()
{}
CPUPoliciesGatekeeper::CPUPoliciesGatekeeper ()
{
}
void
CPUPoliciesGatekeeper::deactivate_policies(CPUPolicyManager* manager)
CPUPoliciesGatekeeper::deactivate_policies (CPUPolicyManager *manager)
{
typedef vector<CPUPolicy*>::iterator CPUPolicyIterator;
typedef vector<CPUPolicy *>::iterator CPUPolicyIterator;
vector<CPUPolicy*> avail_policies = manager->get_avail_policies();
vector<CPUPolicy *> avail_policies = manager->get_avail_policies ();
CPUPolicyIterator avail_it = avail_policies.begin();
CPUPolicyIterator avail_end = avail_policies.end();
CPUPolicyIterator avail_it = avail_policies.begin ();
CPUPolicyIterator avail_end = avail_policies.end ();
for (; avail_it != avail_end; ++avail_it)
{
ActiveIterator act_it = _active_policies.begin();
ActiveIterator act_it = _active_policies.begin ();
while (act_it != _active_policies.end())
while (act_it != _active_policies.end ())
{
if (act_it->second == *avail_it)
{
act_it->second->deactivate();
act_it->second->deactivate ();
// Please note the postfix increment
// (operating on the old, now invalidated by
// erase, iterator object):
_active_policies.erase(act_it++);
_active_policies.erase (act_it++);
}
else
++act_it;
}
} //~ for(avail_it)
}

View File

@ -24,32 +24,33 @@ using namespace sgpem;
// Static member data
CPUPolicy* CPUPolicy::_callback_policy = nullptr;
CPUPolicy *CPUPolicy::_callback_policy = nullptr;
CPUPolicy::~CPUPolicy()
{}
CPUPolicy::~CPUPolicy ()
{
}
PolicyParameters&
CPUPolicy::get_parameters()
PolicyParameters &
CPUPolicy::get_parameters ()
{
return _parameters;
}
CPUPolicy*
CPUPolicy::callback_get_policy()
CPUPolicy *
CPUPolicy::callback_get_policy ()
{
if(_callback_policy == nullptr)
throw std::runtime_error("CPUPolicy::callback_get_policy() not used as a callback method. nullptr ptr returned.");
if (_callback_policy == nullptr)
throw std::runtime_error (
"CPUPolicy::callback_get_policy() not used as a callback method. nullptr ptr returned.");
return _callback_policy;
}
void
CPUPolicy::set_callback_policy(CPUPolicy* ptr)
CPUPolicy::set_callback_policy (CPUPolicy *ptr)
{
_callback_policy = ptr;
}

View File

@ -25,7 +25,6 @@
#include <sgpemv2/malformed_policy_exception.hh>
using namespace sgpem;
CPUPolicyException::CPUPolicyException(const std::string& msg)
: std::runtime_error(msg)
{}
CPUPolicyException::CPUPolicyException (const std::string &msg) : std::runtime_error (msg)
{
}

View File

@ -18,20 +18,18 @@
// along with SGPEMv2. If not, see http://www.gnu.org/licenses/.
#include <sgpemv2/cpu_policy_manager.hh>
#include <sgpemv2/cpu_policies_gatekeeper.hh>
#include <sgpemv2/cpu_policy_manager.hh>
using namespace sgpem;
CPUPolicyManager::CPUPolicyManager()
CPUPolicyManager::CPUPolicyManager ()
{
CPUPoliciesGatekeeper::get_instance().register_manager(this);
CPUPoliciesGatekeeper::get_instance ().register_manager (this);
}
CPUPolicyManager::~CPUPolicyManager()
CPUPolicyManager::~CPUPolicyManager ()
{
CPUPoliciesGatekeeper::get_instance().unregister_manager(this);
CPUPoliciesGatekeeper::get_instance ().unregister_manager (this);
}

View File

@ -19,59 +19,55 @@
#include "dynamic_process.hh"
#include "static_process.hh"
#include "dynamic_thread.hh"
#include "static_process.hh"
#include <sgpemv2/serialize_visitor.hh>
#include <sgpemv2/templates/sequences.tcc>
#include <algorithm>
#include <cassert>
#include <functional>
#include <iostream>
#include <cassert>
using namespace sgpem;
using namespace std;
typedef std::vector<DynamicThread*>::const_iterator ConstThreadIt;
typedef std::vector<DynamicThread*>::iterator ThreadIt;
typedef std::vector<DynamicThread *>::const_iterator ConstThreadIt;
typedef std::vector<DynamicThread *>::iterator ThreadIt;
DynamicProcess::DynamicProcess(StaticProcess* core) :
DynamicSchedulable(), _core(core)
DynamicProcess::DynamicProcess (StaticProcess *core) : DynamicSchedulable (), _core (core)
{
assert(core != nullptr);
assert (core != nullptr);
}
DynamicProcess::DynamicProcess(const DynamicProcess &other) :
Schedulable(), DynamicSchedulable(other), Process(),
_core(other._core)
DynamicProcess::DynamicProcess (const DynamicProcess &other)
: Schedulable (), DynamicSchedulable (other), Process (), _core (other._core)
{
for (Iseq<ConstThreadIt> seq = iseq(other._dynamic_threads); seq; ++seq)
new DynamicThread(*(*seq), this);
for (Iseq<ConstThreadIt> seq = iseq (other._dynamic_threads); seq; ++seq)
new DynamicThread (*(*seq), this);
}
DynamicProcess::~DynamicProcess()
DynamicProcess::~DynamicProcess ()
{
for_each(_dynamic_threads.begin(),
_dynamic_threads.end(),
[] (auto *p) { delete p; });
for_each (_dynamic_threads.begin (), _dynamic_threads.end (), [](auto *p) { delete p; });
}
std::vector<Thread*>
DynamicProcess::get_threads()
std::vector<Thread *>
DynamicProcess::get_threads ()
{
return vector<Thread*>(_dynamic_threads.begin(), _dynamic_threads.end());
return vector<Thread *> (_dynamic_threads.begin (), _dynamic_threads.end ());
}
std::vector<const Thread*>
DynamicProcess::get_threads() const
std::vector<const Thread *>
DynamicProcess::get_threads () const
{
return vector<const Thread*>(_dynamic_threads.begin(), _dynamic_threads.end());
return vector<const Thread *> (_dynamic_threads.begin (), _dynamic_threads.end ());
}
Schedulable::state
DynamicProcess::get_state() const
DynamicProcess::get_state () const
{
const int uninitialized = -1;
@ -97,11 +93,11 @@ DynamicProcess::get_state() const
// state_terminated.
for(Iseq<ConstThreadIt> seq = iseq(_dynamic_threads); seq; ++seq)
for (Iseq<ConstThreadIt> seq = iseq (_dynamic_threads); seq; ++seq)
{
const state thread_state = (*seq)->get_state();
const state thread_state = (*seq)->get_state ();
switch(thread_state)
switch (thread_state)
{
case state_running: // (a)
return state_running;
@ -109,18 +105,18 @@ DynamicProcess::get_state() const
result = state_ready;
continue;
case state_blocked: // (c)
if((result & state_ready) == 0)
if ((result & state_ready) == 0)
result = state_blocked;
continue;
case state_future: // (d)
if((result & (state_ready|state_blocked)) == 0)
if ((result & (state_ready | state_blocked)) == 0)
{
result = state_future;
int thread_starts_at = (*seq)->get_arrival_time();
if(next_thread_starts_at == uninitialized) // (d1)
int thread_starts_at = (*seq)->get_arrival_time ();
if (next_thread_starts_at == uninitialized) // (d1)
next_thread_starts_at = thread_starts_at;
else
next_thread_starts_at = std::min(thread_starts_at, next_thread_starts_at);
next_thread_starts_at = std::min (thread_starts_at, next_thread_starts_at);
}
continue;
case state_terminated: // (e)
@ -133,8 +129,7 @@ DynamicProcess::get_state() const
// the next thread to start, e.g. the one with the least arrival_time,
// has start time greater than the current process elapsed time, then
// pass from state_future to state_terminated:
if (result == state_future &&
next_thread_starts_at > static_cast<int>(get_elapsed_time()))
if (result == state_future && next_thread_starts_at > static_cast<int> (get_elapsed_time ()))
return state_terminated;
return result;
@ -142,49 +137,49 @@ DynamicProcess::get_state() const
void
DynamicProcess::serialize(SerializeVisitor& translator) const
DynamicProcess::serialize (SerializeVisitor &translator) const
{
translator.from_process(*this);
translator.from_process (*this);
}
StaticProcess&
DynamicProcess::get_core()
StaticProcess &
DynamicProcess::get_core ()
{
return *_core;
}
const StaticProcess&
DynamicProcess::get_core() const
const StaticProcess &
DynamicProcess::get_core () const
{
return *_core;
}
std::vector<DynamicThread*>&
DynamicProcess::get_dynamic_threads()
std::vector<DynamicThread *> &
DynamicProcess::get_dynamic_threads ()
{
return _dynamic_threads;
}
unsigned int
DynamicProcess::get_elapsed_time() const
DynamicProcess::get_elapsed_time () const
{
unsigned int result = 0;
for (Iseq<ConstThreadIt> seq = iseq(_dynamic_threads); seq; ++seq)
for (Iseq<ConstThreadIt> seq = iseq (_dynamic_threads); seq; ++seq)
{
result += (*seq)->get_elapsed_time();
result += (*seq)->get_elapsed_time ();
}
return result;
}
int
DynamicProcess::get_last_acquisition() const
DynamicProcess::get_last_acquisition () const
{
int result = -1;
for (Iseq<ConstThreadIt> seq = iseq(_dynamic_threads); seq; ++seq)
for (Iseq<ConstThreadIt> seq = iseq (_dynamic_threads); seq; ++seq)
{
int acq = (*seq)->get_last_acquisition();
int acq = (*seq)->get_last_acquisition ();
if (result < acq)
result = acq;
}
@ -192,15 +187,14 @@ DynamicProcess::get_last_acquisition() const
}
int
DynamicProcess::get_last_release() const
DynamicProcess::get_last_release () const
{
int result = -1;
for (Iseq<ConstThreadIt> seq = iseq(_dynamic_threads); seq; ++seq)
for (Iseq<ConstThreadIt> seq = iseq (_dynamic_threads); seq; ++seq)
{
int acq = (*seq)->get_last_release();
int acq = (*seq)->get_last_release ();
if (result < acq)
result = acq;
}
return result;
}

View File

@ -24,9 +24,9 @@
#include "gettext.h"
#include <sgpemv2/process.hh>
#include "dynamic_schedulable.hh"
#include "static_process.hh"
#include <sgpemv2/process.hh>
#include <glibmm/ustring.h>
@ -35,40 +35,40 @@
namespace sgpem
{
class DynamicProcess;
class StaticProcess;
class DynamicThread;
class Thread;
class DynamicProcess;
class StaticProcess;
class DynamicThread;
class Thread;
class SG_DLLLOCAL DynamicProcess : public DynamicSchedulable, public Process
{
class SG_DLLLOCAL DynamicProcess : public DynamicSchedulable, public Process
{
public:
DynamicProcess(StaticProcess* core);
DynamicProcess(const DynamicProcess &other);
virtual ~DynamicProcess();
DynamicProcess (StaticProcess *core);
DynamicProcess (const DynamicProcess &other);
virtual ~DynamicProcess ();
std::vector<Thread*> get_threads();
std::vector<const Thread*> get_threads() const;
std::vector<Thread *> get_threads ();
std::vector<const Thread *> get_threads () const;
state get_state() const;
state get_state () const;
void serialize(SerializeVisitor& translator) const;
void serialize (SerializeVisitor &translator) const;
int get_last_acquisition() const;
int get_last_release() const;
unsigned int get_elapsed_time() const;
int get_last_acquisition () const;
int get_last_release () const;
unsigned int get_elapsed_time () const;
virtual StaticProcess& get_core();
virtual const StaticProcess& get_core() const;
virtual StaticProcess &get_core ();
virtual const StaticProcess &get_core () const;
// Does also the job of "add_thread" and "remove_thread"
std::vector<DynamicThread*>& get_dynamic_threads();
std::vector<DynamicThread *> &get_dynamic_threads ();
private:
std::shared_ptr<StaticProcess> _core;
std::vector<DynamicThread*> _dynamic_threads;
};
std::vector<DynamicThread *> _dynamic_threads;
};
}
} // namespace sgpem
#endif

View File

@ -19,98 +19,96 @@
#include "dynamic_request.hh"
#include "static_request.hh"
#include "dynamic_sub_request.hh"
#include "dynamic_thread.hh"
#include "static_request.hh"
#include <sgpemv2/serialize_visitor.hh>
#include <sgpemv2/templates/down_cast.tcc>
#include <algorithm>
#include <functional>
#include <cassert>
#include <functional>
using namespace sgpem;
using namespace std;
DynamicRequest::DynamicRequest(StaticRequest *core,
DynamicThread* owner) :
_static_request(core), _dynamic_thread(owner)
DynamicRequest::DynamicRequest (StaticRequest *core, DynamicThread *owner)
: _static_request (core), _dynamic_thread (owner)
{
assert(core != nullptr);
assert(owner != nullptr);
assert (core != nullptr);
assert (owner != nullptr);
// Leave this line: it helps us with a compiler warning if
// the get_dynamic* method signature changes:
std::vector<DynamicRequest*>& siblings = owner->get_dynamic_requests();
siblings.push_back(this);
std::vector<DynamicRequest *> &siblings = owner->get_dynamic_requests ();
siblings.push_back (this);
}
DynamicRequest::DynamicRequest(const DynamicRequest& other, DynamicThread* owner) :
_static_request(other._static_request), _dynamic_thread(owner)
DynamicRequest::DynamicRequest (const DynamicRequest &other, DynamicThread *owner)
: _static_request (other._static_request), _dynamic_thread (owner)
{
typedef vector<DynamicSubRequest*> SubReqVec;
typedef vector<DynamicSubRequest *> SubReqVec;
assert(owner != nullptr);
assert (owner != nullptr);
const SubReqVec& other_subs = other._dynamic_subrequests;
const SubReqVec &other_subs = other._dynamic_subrequests;
// Not sure of this, but the constructor of DynamicSubRequest should take care
// of adding itself to the vector of sub requests. This is only my opinion,
// but I think this is a complicated way of doing things...
for (SubReqVec::const_iterator it = other_subs.begin(); it != other_subs.end(); ++it)
new DynamicSubRequest(*(*it), this);
for (SubReqVec::const_iterator it = other_subs.begin (); it != other_subs.end (); ++it)
new DynamicSubRequest (*(*it), this);
// Leave this line: it helps us with a compiler warning if
// the get_dynamic* method signature changes:
std::vector<DynamicRequest*>& siblings = owner->get_dynamic_requests();
siblings.push_back(this);
std::vector<DynamicRequest *> &siblings = owner->get_dynamic_requests ();
siblings.push_back (this);
}
DynamicRequest::~DynamicRequest()
DynamicRequest::~DynamicRequest ()
{
for_each(_dynamic_subrequests.begin(), _dynamic_subrequests.end(),
[] (auto *p) { delete p; });
for_each (_dynamic_subrequests.begin (), _dynamic_subrequests.end (), [](auto *p) { delete p; });
}
bool
DynamicRequest::operator==(const Request& op2) const
DynamicRequest::operator== (const Request &op2) const
{
return _static_request == down_cast<const DynamicRequest&>(op2)._static_request;
return _static_request == down_cast<const DynamicRequest &> (op2)._static_request;
}
vector<SubRequest*>
DynamicRequest::get_subrequests()
vector<SubRequest *>
DynamicRequest::get_subrequests ()
{
return std::vector<SubRequest*>(_dynamic_subrequests.begin(), _dynamic_subrequests.end());
return std::vector<SubRequest *> (_dynamic_subrequests.begin (), _dynamic_subrequests.end ());
}
vector<DynamicSubRequest*>&
DynamicRequest::get_dynamic_subrequests()
vector<DynamicSubRequest *> &
DynamicRequest::get_dynamic_subrequests ()
{
return _dynamic_subrequests;
}
DynamicThread&
DynamicRequest::get_thread()
DynamicThread &
DynamicRequest::get_thread ()
{
return *_dynamic_thread;
}
unsigned int
DynamicRequest::get_instant() const
DynamicRequest::get_instant () const
{
return _static_request->get_instant();
return _static_request->get_instant ();
}
Request::state
DynamicRequest::get_state() const
DynamicRequest::get_state () const
{
typedef std::vector<DynamicSubRequest*> SubReqs;
typedef std::vector<DynamicSubRequest *> SubReqs;
state result = state_future;
@ -119,12 +117,12 @@ DynamicRequest::get_state() const
bool at_least_once = false;
#endif // ~NDEBUG
const SubReqs& sreqs = _dynamic_subrequests;
for (SubReqs::const_iterator it = sreqs.begin(); it != sreqs.end(); it++)
const SubReqs &sreqs = _dynamic_subrequests;
for (SubReqs::const_iterator it = sreqs.begin (); it != sreqs.end (); it++)
{
SubRequest& cur = **it;
SubRequest &cur = **it;
switch (cur.get_state())
switch (cur.get_state ())
{
case state_allocated:
return state_allocated;
@ -138,11 +136,11 @@ DynamicRequest::get_state() const
// state_terminated and state_future are mutually
// exclusive
if (at_least_once)
assert(result == cur.get_state());
assert (result == cur.get_state ());
at_least_once = true;
#endif //~ NDEBUG
result = cur.get_state();
result = cur.get_state ();
}
}
return result;
@ -150,21 +148,21 @@ DynamicRequest::get_state() const
void
DynamicRequest::serialize(SerializeVisitor& translator) const
DynamicRequest::serialize (SerializeVisitor &translator) const
{
translator.from_request(*this);
translator.from_request (*this);
}
StaticRequest&
DynamicRequest::get_core()
StaticRequest &
DynamicRequest::get_core ()
{
return *_static_request;
}
const StaticRequest&
DynamicRequest::get_core() const
const StaticRequest &
DynamicRequest::get_core () const
{
return *_static_request;
}

View File

@ -23,14 +23,14 @@
namespace sgpem
{
class DynamicRequest;
class SerializeVisitor;
class SubRequest;
class DynamicSubRequest;
}
class DynamicRequest;
class SerializeVisitor;
class SubRequest;
class DynamicSubRequest;
} // namespace sgpem
#include "static_request.hh"
#include "dynamic_thread.hh"
#include "static_request.hh"
#include <sgpemv2/request.hh>
@ -39,46 +39,45 @@ namespace sgpem
namespace sgpem
{
/** \brief A "dynamic" request, which represents the state
/** \brief A "dynamic" request, which represents the state
* of a request at a particular temporal instant
*/
class SG_DLLLOCAL DynamicRequest : public Request
{
class SG_DLLLOCAL DynamicRequest : public Request
{
public:
DynamicRequest(StaticRequest *core, DynamicThread* owner);
DynamicRequest(const DynamicRequest& other, DynamicThread* owner);
~DynamicRequest();
DynamicRequest (StaticRequest *core, DynamicThread *owner);
DynamicRequest (const DynamicRequest &other, DynamicThread *owner);
~DynamicRequest ();
virtual bool operator==(const Request& op2) const;
virtual bool operator== (const Request &op2) const;
virtual std::vector<SubRequest*> get_subrequests();
virtual std::vector<SubRequest *> get_subrequests ();
DynamicThread& get_thread();
DynamicThread &get_thread ();
unsigned int get_instant() const;
unsigned int get_instant () const;
state get_state() const;
state get_state () const;
void serialize(SerializeVisitor& translator) const;
void serialize (SerializeVisitor &translator) const;
StaticRequest& get_core();
const StaticRequest& get_core() const;
StaticRequest &get_core ();
const StaticRequest &get_core () const;
/// \internal Since this method is visible only by the backend,
/// return directly a reference that lets us to
/// add and remove subrequests at will.
std::vector<DynamicSubRequest*>& get_dynamic_subrequests();
std::vector<DynamicSubRequest *> &get_dynamic_subrequests ();
private:
// Undefined
DynamicRequest(const DynamicRequest& other);
DynamicRequest (const DynamicRequest &other);
std::shared_ptr<StaticRequest> _static_request;
DynamicThread* _dynamic_thread;
std::vector<DynamicSubRequest*> _dynamic_subrequests;
};
DynamicThread *_dynamic_thread;
std::vector<DynamicSubRequest *> _dynamic_subrequests;
};
}
} // namespace sgpem
#endif

View File

@ -29,44 +29,44 @@
using namespace sgpem;
DynamicResource::DynamicResource(StaticResource *core) :
_static_resource(core)
{}
DynamicResource::DynamicResource (StaticResource *core) : _static_resource (core)
{
}
bool
DynamicResource::operator==(const Resource& op2) const
DynamicResource::operator== (const Resource &op2) const
{
return _static_resource == down_cast<const DynamicResource&>(op2)._static_resource;
return _static_resource == down_cast<const DynamicResource &> (op2)._static_resource;
}
Glib::ustring
DynamicResource::get_name() const
DynamicResource::get_name () const
{
return _static_resource->get_name();
return _static_resource->get_name ();
}
unsigned int
DynamicResource::get_places() const
DynamicResource::get_places () const
{
return _static_resource->get_places();
return _static_resource->get_places ();
}
void
DynamicResource::serialize(SerializeVisitor& translator) const
DynamicResource::serialize (SerializeVisitor &translator) const
{
translator.from_resource(*this);
translator.from_resource (*this);
}
StaticResource&
DynamicResource::get_core()
StaticResource &
DynamicResource::get_core ()
{
return *_static_resource;
}
const StaticResource&
DynamicResource::get_core() const
const StaticResource &
DynamicResource::get_core () const
{
return *_static_resource;
}

View File

@ -23,76 +23,73 @@
#include "glibmm/ustring.h"
#include <sgpemv2/resource.hh>
#include "static_resource.hh"
#include <sgpemv2/resource.hh>
#include <memory>
namespace sgpem
{
/// \brief Desribes the state of a resource entity in a particular moment
/// of the simulation.
///
/// Contains part of the information used by the scheduling policies to
/// perform scheduling.
/// DynamicResource objects may be created by the system
/// via the Scheduler.step_forward() method (which then inserts them into a
/// ::ConcreteEnvironment), or by the user on a resetted ::History by creating
/// one of them anew.
///
/// Actually this class does not provide any information to the system, nor it
/// does play any particular role. It is here for the puropose of extensibility
/// and beauty in general.
///
/// These objects may be destroyed only by resetting an ::History, or via one
/// of its methods.
class DynamicResource;
class SerializeVisitor;
/// \brief Desribes the state of a resource entity in a particular moment
/// of the simulation.
///
/// Contains part of the information used by the scheduling policies to
/// perform scheduling.
/// DynamicResource objects may be created by the system
/// via the Scheduler.step_forward() method (which then inserts them into a
/// ::ConcreteEnvironment), or by the user on a resetted ::History by creating
/// one of them anew.
///
/// Actually this class does not provide any information to the system, nor it
/// does play any particular role. It is here for the puropose of extensibility
/// and beauty in general.
///
/// These objects may be destroyed only by resetting an ::History, or via one
/// of its methods.
class DynamicResource;
class SerializeVisitor;
class SG_DLLLOCAL DynamicResource : public Resource
{
class SG_DLLLOCAL DynamicResource : public Resource
{
public:
DynamicResource(StaticResource *core);
DynamicResource (StaticResource *core);
virtual bool operator==(const Resource& op2) const;
virtual bool operator== (const Resource &op2) const;
/// \brief Returns the name of the Resource.
///
/// Returns the name of the Resource.
/// \return the name of the Resource.
Glib::ustring get_name() const;
Glib::ustring get_name () const;
/// \brief Returns the number of places of the Resource.
///
/// Returns the number of places of the Resource.
/// \return the number of places of the Resource.
unsigned int get_places() const;
unsigned int get_places () const;
/// \brief Serializes this object via the provided translator.
///
/// Calls translator->from_resource(this).
void serialize(SerializeVisitor& translator) const;
void serialize (SerializeVisitor &translator) const;
/// \brief Returns a reference to the static resource object.
///
/// This function returns a reference to the actual schedable object
/// represented, along with its status, by this instance.
StaticResource& get_core();
StaticResource &get_core ();
/// \brief Returns a constant reference to the static schedulable object.
///
/// This function returns a constant reference to the actual schedable object
/// represented, along with its status, by this instance.
const StaticResource& get_core() const;
const StaticResource &get_core () const;
private:
std::shared_ptr<StaticResource> _static_resource;
};
};
}
} // namespace sgpem
#endif

View File

@ -27,42 +27,42 @@
using namespace sgpem;
using namespace std;
DynamicSchedulable::DynamicSchedulable()
: _priority_push(0)
{}
DynamicSchedulable::DynamicSchedulable () : _priority_push (0)
{
}
bool
DynamicSchedulable::operator==(const Schedulable& op2) const
DynamicSchedulable::operator== (const Schedulable &op2) const
{
return &get_core() == &(down_cast<const DynamicSchedulable&>(op2).get_core());
return &get_core () == &(down_cast<const DynamicSchedulable &> (op2).get_core ());
}
Glib::ustring
DynamicSchedulable::get_name() const
DynamicSchedulable::get_name () const
{
return get_core().get_name();
return get_core ().get_name ();
}
unsigned int
DynamicSchedulable::get_arrival_time() const
DynamicSchedulable::get_arrival_time () const
{
return get_core().get_arrival_time();
return get_core ().get_arrival_time ();
}
int
DynamicSchedulable::get_base_priority() const
DynamicSchedulable::get_base_priority () const
{
return get_core().get_priority();
return get_core ().get_priority ();
}
unsigned int
DynamicSchedulable::get_total_cpu_time() const
DynamicSchedulable::get_total_cpu_time () const
{
return get_core().get_total_cpu_time();
return get_core ().get_total_cpu_time ();
}
int
DynamicSchedulable::set_priority_push(int new_value)
DynamicSchedulable::set_priority_push (int new_value)
{
int old_priority_push = _priority_push;
_priority_push = new_value;
@ -70,13 +70,13 @@ DynamicSchedulable::set_priority_push(int new_value)
}
int
DynamicSchedulable::get_priority_push() const
DynamicSchedulable::get_priority_push () const
{
return _priority_push;
}
int
DynamicSchedulable::get_current_priority() const
DynamicSchedulable::get_current_priority () const
{
return get_base_priority() + get_priority_push();
return get_base_priority () + get_priority_push ();
}

View File

@ -22,31 +22,30 @@
#define DYNAMIC_SCHEDULABLE_HH 1
#include <sgpemv2/schedulable.hh>
#include "static_schedulable.hh"
#include <sgpemv2/schedulable.hh>
namespace sgpem
{
/// \brief Desribes the state of a schedulable entity in a particular moment
/// of the simulation.
///
/// Contains part of the information used by the scheduling policies to
/// perform scheduling.
/// Objects of subclasses of ::DynamicSchedulable may be created by the system
/// via the Scheduler.step_forward() method (which then inserts them into a
/// ::ConcreteEnvironment), or by the user on a resetted ::History by creating
/// one of them anew.
///
/// These objects may be destroyed only by resetting an ::History, or via one
/// of its methods.
class DynamicSchedulable;
/// \brief Desribes the state of a schedulable entity in a particular moment
/// of the simulation.
///
/// Contains part of the information used by the scheduling policies to
/// perform scheduling.
/// Objects of subclasses of ::DynamicSchedulable may be created by the system
/// via the Scheduler.step_forward() method (which then inserts them into a
/// ::ConcreteEnvironment), or by the user on a resetted ::History by creating
/// one of them anew.
///
/// These objects may be destroyed only by resetting an ::History, or via one
/// of its methods.
class DynamicSchedulable;
class SG_DLLLOCAL DynamicSchedulable : public virtual Schedulable
{
class SG_DLLLOCAL DynamicSchedulable : public virtual Schedulable
{
public:
/** \brief Object constructor */
DynamicSchedulable();
DynamicSchedulable ();
//DynamicSchedulable(const DynamicSchedulable& obj); //copy constructor
@ -56,14 +55,14 @@ namespace sgpem
* actual represented process is the same, and if the status is also the
* same.
*/
virtual bool operator==(const Schedulable&) const;
virtual bool operator== (const Schedulable &) const;
/// \brief Returns the name of the Schedulable.
///
/// Returns the name of the Schedulable.
/// It is fetched from the associated ::StaticSchedulable object.
/// \return the name of the Schedulable.
virtual Glib::ustring get_name() const;
virtual Glib::ustring get_name () const;
/// \brief Returns the arrival time of the Schedulable.
///
@ -75,7 +74,7 @@ namespace sgpem
/// The arrival time is a static (respect to the simulation) property.
/// It is fetched from the associated ::StaticSchedulable object.
/// \return the arrival time of the Schedulable.
virtual unsigned int get_arrival_time() const;
virtual unsigned int get_arrival_time () const;
/// \brief Returns the base priority of the Schedulable.
///
@ -90,7 +89,7 @@ namespace sgpem
/// The base priority is a static (respect to the simulation) property.
/// It is fetched from the associated ::StaticSchedulable object.
/// \return the base priority of the Schedulable.
virtual int get_base_priority() const;
virtual int get_base_priority () const;
/// \brief Returns the total required CPU time of the Schedulable.
///
@ -104,7 +103,7 @@ namespace sgpem
/// The total required CPU time is a static (respect to the simulation) property.
/// It is fetched from the associated ::StaticSchedulable object.
/// \return the total required CPU time of the Schedulable.
virtual unsigned int get_total_cpu_time() const;
virtual unsigned int get_total_cpu_time () const;
/// \brief Returns the current priority push of the Schedulable.
///
@ -118,7 +117,7 @@ namespace sgpem
///
/// The priority push is a dynamic (respect to the simulation) property.
/// \return the current priority push of the Schedulable.
virtual int get_priority_push() const;
virtual int get_priority_push () const;
/// \brief Sets the priority push of the Schedulable, returning the old one.
///
@ -133,7 +132,7 @@ namespace sgpem
/// The priority push is a dynamic (respect to the simulation) property.
/// \param new_value the new push to be set.
/// \return the old priority push of the Schedulable.
virtual int set_priority_push(int new_value = 0);
virtual int set_priority_push (int new_value = 0);
/// \brief Returns the current priority of the Schedulable.
///
@ -147,7 +146,7 @@ namespace sgpem
///
/// The current priority is a dynamic (respect to the simulation) property.
/// \return the dynamic priority of the Schedulable.
virtual int get_current_priority() const;
virtual int get_current_priority () const;
/// \brief Returns the elapsed time of the Schedulable.
///
@ -157,23 +156,23 @@ namespace sgpem
///
/// The elapsed time is a dynamic (respect to the simulation) property.
/// \return the elapsed time of the Schedulable.
virtual unsigned int get_elapsed_time() const = 0;
virtual unsigned int get_elapsed_time () const = 0;
/// \brief Returns a reference to the static schedulable object.
///
/// This function returns a reference to the actual schedable object.
/// represented, along with its status, by this instance.
virtual StaticSchedulable& get_core() = 0;
virtual StaticSchedulable &get_core () = 0;
/// \brief Returns a constant reference to the static schedulable object.
///
/// This function returns a constant reference to the actual schedable object.
/// represented, along with its status, by this instance.
virtual const StaticSchedulable& get_core() const = 0;
virtual const StaticSchedulable &get_core () const = 0;
private:
int _priority_push;
};
}
};
} // namespace sgpem
#endif

View File

@ -30,86 +30,85 @@
using namespace sgpem;
DynamicSubRequest::DynamicSubRequest(StaticSubRequest* core,
DynamicRequest* owner) :
_static_subrequest(core), _owner(owner),
_queue_position(-1), _ran_for(0), _state(Request::state_future)
DynamicSubRequest::DynamicSubRequest (StaticSubRequest *core, DynamicRequest *owner)
: _static_subrequest (core), _owner (owner), _queue_position (-1), _ran_for (0), _state (Request::state_future)
{
assert(core != nullptr);
assert(owner != nullptr);
assert (core != nullptr);
assert (owner != nullptr);
// Leave this line: it helps us with a compiler warning if
// the get_dynamic* method signature changes:
std::vector<DynamicSubRequest*>& siblings = owner->get_dynamic_subrequests();
siblings.push_back(this);
std::vector<DynamicSubRequest *> &siblings = owner->get_dynamic_subrequests ();
siblings.push_back (this);
}
DynamicSubRequest::DynamicSubRequest(const DynamicSubRequest& other,
DynamicRequest* owner) :
_static_subrequest(other._static_subrequest), _owner(owner),
_queue_position(other._queue_position), _ran_for(other._ran_for),
_state(other._state)
DynamicSubRequest::DynamicSubRequest (const DynamicSubRequest &other, DynamicRequest *owner)
: _static_subrequest (other._static_subrequest),
_owner (owner),
_queue_position (other._queue_position),
_ran_for (other._ran_for),
_state (other._state)
{
assert(owner != nullptr);
assert (owner != nullptr);
// Leave this line: it helps us with a compiler warning if
// the get_dynamic* method signature changes:
std::vector<DynamicSubRequest*>& siblings = owner->get_dynamic_subrequests();
siblings.push_back(this);
std::vector<DynamicSubRequest *> &siblings = owner->get_dynamic_subrequests ();
siblings.push_back (this);
}
DynamicSubRequest::~DynamicSubRequest()
{}
DynamicSubRequest::~DynamicSubRequest ()
{
}
bool
DynamicSubRequest::operator==(const SubRequest& op2) const
DynamicSubRequest::operator== (const SubRequest &op2) const
{
return _static_subrequest ==
down_cast<const DynamicSubRequest&>(op2)._static_subrequest;
return _static_subrequest == down_cast<const DynamicSubRequest &> (op2)._static_subrequest;
}
SubRequest::resource_key_t
DynamicSubRequest::get_resource_key() const
DynamicSubRequest::get_resource_key () const
{
return _static_subrequest->get_resource_key();
return _static_subrequest->get_resource_key ();
}
unsigned int
DynamicSubRequest::get_length() const
DynamicSubRequest::get_length () const
{
return _static_subrequest->get_length();
return _static_subrequest->get_length ();
}
int
DynamicSubRequest::get_queue_position() const
DynamicSubRequest::get_queue_position () const
{
return _queue_position;
}
void
DynamicSubRequest::set_queue_position(int position)
DynamicSubRequest::set_queue_position (int position)
{
_queue_position = position;
}
DynamicRequest&
DynamicSubRequest::get_request()
DynamicRequest &
DynamicSubRequest::get_request ()
{
return *_owner;
}
DynamicSubRequest::state
DynamicSubRequest::get_state() const
DynamicSubRequest::get_state () const
{
return _state;
}
DynamicSubRequest::state
DynamicSubRequest::set_state(state new_state)
DynamicSubRequest::set_state (state new_state)
{
state temp = _state;
_state = new_state;
@ -118,18 +117,18 @@ DynamicSubRequest::set_state(state new_state)
unsigned int
DynamicSubRequest::get_remaining_time() const
DynamicSubRequest::get_remaining_time () const
{
return _static_subrequest->get_length() - _ran_for;
return _static_subrequest->get_length () - _ran_for;
}
unsigned int
DynamicSubRequest::decrease_remaining_time()
DynamicSubRequest::decrease_remaining_time ()
{
assert(_state == Request::state_allocated);
assert (_state == Request::state_allocated);
unsigned int temp = get_remaining_time();
unsigned int temp = get_remaining_time ();
if (temp > 0)
_ran_for++;
@ -138,21 +137,21 @@ DynamicSubRequest::decrease_remaining_time()
void
DynamicSubRequest::serialize(SerializeVisitor& translator) const
DynamicSubRequest::serialize (SerializeVisitor &translator) const
{
translator.from_subrequest(*this);
translator.from_subrequest (*this);
}
StaticSubRequest&
DynamicSubRequest::get_core()
StaticSubRequest &
DynamicSubRequest::get_core ()
{
return *_static_subrequest;
}
const StaticSubRequest&
DynamicSubRequest::get_core() const
const StaticSubRequest &
DynamicSubRequest::get_core () const
{
return *_static_subrequest;
}

View File

@ -23,11 +23,11 @@
namespace sgpem
{
class DynamicSubRequest;
class SerializeVisitor;
class Resource;
class StaticSubRequest;
}
class DynamicSubRequest;
class SerializeVisitor;
class Resource;
class StaticSubRequest;
} // namespace sgpem
#include "dynamic_request.hh"
#include "dynamic_resource.hh"
@ -40,74 +40,74 @@ namespace sgpem
namespace sgpem
{
/** \brief Represents the dynamic status of a subrequest
/** \brief Represents the dynamic status of a subrequest
*/
class SG_DLLLOCAL DynamicSubRequest : public SubRequest
{
class SG_DLLLOCAL DynamicSubRequest : public SubRequest
{
public:
/** \brief Constructor
*
* Only ::History knows how to use this :-).
*/
DynamicSubRequest(StaticSubRequest* core, DynamicRequest* owner);
DynamicSubRequest (StaticSubRequest *core, DynamicRequest *owner);
/** \brief "Special" copy constructor, which copies everything except owner
* \param owner The owner of the new DynamicSubRequest
*/
DynamicSubRequest(const DynamicSubRequest& other, DynamicRequest* owner);
DynamicSubRequest (const DynamicSubRequest &other, DynamicRequest *owner);
virtual ~DynamicSubRequest();
virtual ~DynamicSubRequest ();
/** \brief Tells if this object equals another of the same type
*
* \return true If they own a reference to the same Static object
* \return false Otherwise
*/
virtual bool operator==(const SubRequest& op2) const;
virtual bool operator== (const SubRequest &op2) const;
/** \brief Returns the key to the DynamicResource that was requested
*
* The correct ::Resource object can be obtained via
* Environment.get_resources(), using the returned value as a key
*/
resource_key_t get_resource_key() const;
resource_key_t get_resource_key () const;
/** \brief Returns the time the resource is needed
*
* This time is meant relative to a process executed time.
*/
unsigned int get_length() const;
unsigned int get_length () const;
int get_queue_position() const;
void set_queue_position(int position);
int get_queue_position () const;
void set_queue_position (int position);
virtual DynamicRequest& get_request();
virtual DynamicRequest &get_request ();
state get_state() const;
state set_state(state new_state);
state get_state () const;
state set_state (state new_state);
unsigned int get_remaining_time() const;
unsigned int get_remaining_time () const;
/** \brief Decreases remaining time by 1
*/
unsigned int decrease_remaining_time();
unsigned int decrease_remaining_time ();
void serialize(SerializeVisitor& translator) const;
void serialize (SerializeVisitor &translator) const;
StaticSubRequest& get_core();
const StaticSubRequest& get_core() const;
StaticSubRequest &get_core ();
const StaticSubRequest &get_core () const;
private:
// Undefined
DynamicSubRequest(const DynamicSubRequest&);
DynamicSubRequest (const DynamicSubRequest &);
std::shared_ptr<StaticSubRequest> _static_subrequest;
DynamicRequest* _owner;
DynamicRequest *_owner;
int _queue_position;
unsigned int _ran_for;
state _state;
};
};
}
} // namespace sgpem
#endif

View File

@ -19,71 +19,74 @@
#include "dynamic_thread.hh"
#include "static_thread.hh"
#include "dynamic_request.hh"
#include "static_thread.hh"
#include <sgpemv2/serialize_visitor.hh>
#include <algorithm>
#include <functional>
#include <cassert>
#include <functional>
using namespace sgpem;
DynamicThread::DynamicThread(StaticThread* core, DynamicProcess* parent)
: DynamicSchedulable(), _core(core), _state(state_future), _parent(parent),
_ran_for(0), _last_acquisition(-1), _last_release(-1)
DynamicThread::DynamicThread (StaticThread *core, DynamicProcess *parent)
: DynamicSchedulable (), _core (core), _state (state_future), _parent (parent), _ran_for (0), _last_acquisition (-1), _last_release (-1)
{
assert(core != nullptr);
assert(parent != nullptr);
assert (core != nullptr);
assert (parent != nullptr);
// Leave this line: it helps us with a compiler warning if
// the get_dynamic* method signature changes:
std::vector<DynamicThread*>& siblings = parent->get_dynamic_threads();
siblings.push_back(this);
std::vector<DynamicThread *> &siblings = parent->get_dynamic_threads ();
siblings.push_back (this);
}
DynamicThread::DynamicThread(const DynamicThread &other, DynamicProcess* parent) :
Schedulable(), DynamicSchedulable(other), Thread(),
_core(other._core), _state(other._state), _parent(parent),
_ran_for(other._ran_for), _last_acquisition(other._last_acquisition),
_last_release(other._last_release)
DynamicThread::DynamicThread (const DynamicThread &other, DynamicProcess *parent)
: Schedulable (),
DynamicSchedulable (other),
Thread (),
_core (other._core),
_state (other._state),
_parent (parent),
_ran_for (other._ran_for),
_last_acquisition (other._last_acquisition),
_last_release (other._last_release)
{
typedef std::vector<DynamicRequest*>::const_iterator ReqIt;
typedef std::vector<DynamicRequest *>::const_iterator ReqIt;
assert(parent != nullptr);
assert (parent != nullptr);
const std::vector<DynamicRequest*>& other_req = other._dynamic_requests;
const std::vector<DynamicRequest *> &other_req = other._dynamic_requests;
for (ReqIt it = other_req.begin(); it != other_req.end(); ++it)
new DynamicRequest(*(*it), this);
for (ReqIt it = other_req.begin (); it != other_req.end (); ++it)
new DynamicRequest (*(*it), this);
// Leave this line: it helps us with a compiler warning if
// the get_dynamic* method signature changes:
std::vector<DynamicThread*>& siblings = parent->get_dynamic_threads();
siblings.push_back(this);
std::vector<DynamicThread *> &siblings = parent->get_dynamic_threads ();
siblings.push_back (this);
}
DynamicThread::~DynamicThread()
DynamicThread::~DynamicThread ()
{
for_each(_dynamic_requests.begin(), _dynamic_requests.end(),
[] (auto *p) { delete p; });
for_each (_dynamic_requests.begin (), _dynamic_requests.end (), [](auto *p) { delete p; });
}
DynamicProcess&
DynamicThread::get_process()
DynamicProcess &
DynamicThread::get_process ()
{
return *_parent;
}
Schedulable::state
DynamicThread::get_state() const
DynamicThread::get_state () const
{
return _state;
}
Schedulable::state
DynamicThread::set_state(state new_state)
DynamicThread::set_state (state new_state)
{
state old_state = _state;
_state = new_state;
@ -91,74 +94,73 @@ DynamicThread::set_state(state new_state)
return old_state;
}
std::vector<Request*>
DynamicThread::get_requests()
std::vector<Request *>
DynamicThread::get_requests ()
{
return std::vector<Request*>(_dynamic_requests.begin(), _dynamic_requests.end());
return std::vector<Request *> (_dynamic_requests.begin (), _dynamic_requests.end ());
}
void
DynamicThread::serialize(SerializeVisitor& translator) const
DynamicThread::serialize (SerializeVisitor &translator) const
{
translator.from_thread(*this);
translator.from_thread (*this);
}
StaticThread&
DynamicThread::get_core()
StaticThread &
DynamicThread::get_core ()
{
return *_core;
}
const StaticThread&
DynamicThread::get_core() const
const StaticThread &
DynamicThread::get_core () const
{
return *_core;
}
std::vector<DynamicRequest*>&
DynamicThread::get_dynamic_requests()
std::vector<DynamicRequest *> &
DynamicThread::get_dynamic_requests ()
{
return _dynamic_requests;
}
unsigned int
DynamicThread::get_elapsed_time() const
DynamicThread::get_elapsed_time () const
{
return _ran_for;
}
void
DynamicThread::decrease_remaining_time()
DynamicThread::decrease_remaining_time ()
{
// strict check for us to better debug scheduler
assert(_ran_for < get_total_cpu_time());
if (_ran_for < get_total_cpu_time())
assert (_ran_for < get_total_cpu_time ());
if (_ran_for < get_total_cpu_time ())
_ran_for++;
}
int
DynamicThread::get_last_acquisition() const
DynamicThread::get_last_acquisition () const
{
return _last_acquisition;
}
void
DynamicThread::set_last_acquisition(int instant)
DynamicThread::set_last_acquisition (int instant)
{
_last_acquisition = instant;
}
int
DynamicThread::get_last_release() const
DynamicThread::get_last_release () const
{
return _last_release;
}
void
DynamicThread::set_last_release(int instant)
DynamicThread::set_last_release (int instant)
{
_last_release = instant;
}

View File

@ -26,60 +26,60 @@
#include "glibmm/ustring.h"
#include <vector>
#include <sgpemv2/thread.hh>
#include "dynamic_process.hh"
#include "dynamic_schedulable.hh"
#include <sgpemv2/thread.hh>
#include <memory>
namespace sgpem
{
class DynamicThread;
class DynamicProcess;
class StaticThread;
class Request;
class DynamicRequest;
class DynamicThread;
class DynamicProcess;
class StaticThread;
class Request;
class DynamicRequest;
class SG_DLLLOCAL DynamicThread : public DynamicSchedulable, public Thread
{
class SG_DLLLOCAL DynamicThread : public DynamicSchedulable, public Thread
{
public:
/**
\brief Constructor.
\param core The static counterpart to this object.
\param parent The parent process that spawned this thread.
*/
DynamicThread(StaticThread* core, DynamicProcess* parent);
DynamicThread (StaticThread *core, DynamicProcess *parent);
/**
\brief Copy constructor.
\param other The dynamic thread to clone.
\param parent The parent process that spawned this thread.
*/
DynamicThread(const DynamicThread &other, DynamicProcess* parent);
DynamicThread (const DynamicThread &other, DynamicProcess *parent);
/**
\brief Destructor.
*/
virtual ~DynamicThread();
virtual ~DynamicThread ();
/**
\brief Gets the owning process.
\return A reference to the DynamicProcess that owns this thread.
*/
DynamicProcess& get_process();
DynamicProcess &get_process ();
/**
\brief Gets this thread's state.
\return The current Schedulable::state of this object.
*/
state get_state() const;
state get_state () const;
/**
\brief Sets/gets this thread's state.
\param new_state The desired Schedulable::state of this object.
\return The previous state.
*/
state set_state(state new_state);
state set_state (state new_state);
/**
\brief Gets the last istant this schedulable has
@ -87,7 +87,7 @@ namespace sgpem
\return Current value of last_acquisition.
*/
int get_last_acquisition() const;
int get_last_acquisition () const;
/**
\brief Sets/gets the last istant this schedulable
@ -96,7 +96,7 @@ namespace sgpem
\param instant New value for last_acquisition.
\return Previous value of last_acquisition.
*/
void set_last_acquisition(int instant);
void set_last_acquisition (int instant);
/**
\brief Gets the last instant this schedulable has changed its state
@ -104,7 +104,7 @@ namespace sgpem
\return Current value of last_release.
*/
int get_last_release() const;
int get_last_release () const;
/**
\brief Sets/gets the last instant this schedulable has changed
@ -113,38 +113,37 @@ namespace sgpem
\param instant New value for last_release.
\return Previous value of last_release.
*/
void set_last_release(int instant);
void set_last_release (int instant);
/**
\brief Gets total running time of this thread.
\return Current value of _run_for.
*/
unsigned int get_elapsed_time() const;
unsigned int get_elapsed_time () const;
/**
\brief Decreases the schedulable remaining time by one unit.
*/
void decrease_remaining_time();
void decrease_remaining_time ();
/**
\brief Serializes this object via the provided visitor.
Calls translator->from_thread(this).
*/
void serialize(SerializeVisitor& translator) const;
void serialize (SerializeVisitor &translator) const;
/**
\brief Gets a reference to static counterpart of this object.
\return A reference to static counterpart of this object.
*/
virtual StaticThread& get_core();
virtual StaticThread &get_core ();
/**
\brief Gets a const reference to static counterpart of this object.
\return A const reference to static counterpart of this object.
*/
virtual const StaticThread& get_core() const;
virtual const StaticThread &get_core () const;
/**
@ -155,7 +154,7 @@ namespace sgpem
Does also the job of "add_request" and "remove_request"
\return A reference to the DynamicRequests pointers vector.
*/
std::vector<Request*> get_requests();
std::vector<Request *> get_requests ();
/**
\brief Returns ::DynamicRequest pointers this ::Thread did to some ::Resource.
@ -165,14 +164,14 @@ namespace sgpem
Does also the job of "add_request" and "remove_request"
\return A reference to the DynamicRequests pointers vector.
*/
std::vector<DynamicRequest*>& get_dynamic_requests();
std::vector<DynamicRequest *> &get_dynamic_requests ();
private:
/**
\brief Private copy constructor; avoids public construction of
DynamicThread without owning process.
*/
DynamicThread(const DynamicThread &other);
DynamicThread (const DynamicThread &other);
/**
\brief Pointer to static counterpart of this object.
@ -189,12 +188,12 @@ namespace sgpem
/**
\brief Container with this thread's requests.
*/
std::vector<DynamicRequest*> _dynamic_requests;
std::vector<DynamicRequest *> _dynamic_requests;
/**
\brief Pointer to this thread parent.
*/
DynamicProcess* _parent;
DynamicProcess *_parent;
/**
\brief Total running time of this thread
@ -211,9 +210,8 @@ namespace sgpem
from running to something else.
*/
int _last_release;
};
};
}
} // namespace sgpem
#endif

View File

@ -23,6 +23,6 @@
using namespace sgpem;
Environment::~Environment()
{}
Environment::~Environment ()
{
}

View File

@ -23,7 +23,7 @@
#if ENABLE_NLS
/* Get declarations of GNU message catalog functions. */
# include <libintl.h>
#include <libintl.h>
#else
@ -34,17 +34,17 @@
and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
is OK. */
#if defined(__sun)
# include <locale.h>
#include <locale.h>
#endif
/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
<libintl.h>, which chokes if dcgettext is defined as a macro. So include
it now, to make later inclusions of <libintl.h> a NOP. */
#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
# include <cstdlib>
# if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H
# include <libintl.h>
# endif
#include <cstdlib>
#if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H
#include <libintl.h>
#endif
#endif
/* Disabled NLS.
@ -52,18 +52,16 @@
for invalid uses of the value returned from these functions.
On pre-ANSI systems without 'const', the config.h file is supposed to
contain "#define const". */
# define gettext(Msgid) ((const char *) (Msgid))
# define dgettext(Domainname, Msgid) ((const char *) (Msgid))
# define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid))
# define ngettext(Msgid1, Msgid2, N) \
#define gettext(Msgid) ((const char *) (Msgid))
#define dgettext(Domainname, Msgid) ((const char *) (Msgid))
#define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid))
#define ngettext(Msgid1, Msgid2, N) ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
#define dngettext(Domainname, Msgid1, Msgid2, N) ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
#define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
# define dngettext(Domainname, Msgid1, Msgid2, N) \
((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
# define textdomain(Domainname) ((const char *) (Domainname))
# define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname))
# define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset))
#define textdomain(Domainname) ((const char *) (Domainname))
#define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname))
#define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset))
#endif
@ -77,7 +75,7 @@
#define gettext_noop(String) String
/* Commodity macros -- added by Matteo Settenvini 2006-01-13 */
#define _(x) (gettext(x))
#define N_(x) (gettext_noop(x))
#define _(x) (gettext (x))
#define N_(x) (gettext_noop (x))
#endif /* _LIBGETTEXT_H */

View File

@ -34,7 +34,7 @@
#include <sstream>
#ifdef _MSC_VER
#include <shlobj.h>
#include <shlobj.h>
#endif
using namespace sgpem;
@ -42,13 +42,13 @@ using namespace sgpem;
// Explicit template instantiation to allow to export symbols from the DSO.
template class sgpem::Singleton<GlobalPreferences>;
GlobalPreferences::GlobalPreferences()
: _mod_dirs(1, PLUGDIR), _pol_dirs(1, POLDIR), _speed(1000)
{}
GlobalPreferences::GlobalPreferences () : _mod_dirs (1, PLUGDIR), _pol_dirs (1, POLDIR), _speed (1000)
{
}
Glib::ustring
GlobalPreferences::get_preferences_dir() const
GlobalPreferences::get_preferences_dir () const
{
using namespace Glib;
// windows-specific part, i don't use ifdef WIN32 since I'm not sure how
@ -56,49 +56,45 @@ GlobalPreferences::get_preferences_dir() const
#ifdef _MSC_VER
TCHAR raw_path[MAX_PATH];
if(SUCCEEDED(SHGetFolderPath(NULL,
CSIDL_APPDATA,
nullptr,
SHGFP_TYPE_CURRENT,
raw_path)))
if (SUCCEEDED (SHGetFolderPath (NULL, CSIDL_APPDATA, nullptr, SHGFP_TYPE_CURRENT, raw_path)))
{
// if UNICODE, characters are 16bit, otherwise plain bytes
# ifdef UNICODE
std::wstring path(raw_path);
# else
std::string path(raw_path);
# endif
#ifdef UNICODE
std::wstring path (raw_path);
#else
std::string path (raw_path);
#endif
path += TEXT("\\sgpemv2");
path += TEXT ("\\sgpemv2");
// Create "Application Data\sgpemv2". if not present,
// otherwise it is a no-op
CreateDirectory(path.c_str(), nullptr);
CreateDirectory (path.c_str (), nullptr);
// if UNICODE, we need to convert to utf-8
// I'm not sure if this part is OK, anyway...
# ifdef UNICODE
#ifdef UNICODE
char raw_path_utf[MAX_PATH];
WideCharToMultiByte(CP_UTF8, 0, path.c_str(), -1, raw_path_utf, MAX_PATH, nullptr, nullptr);
WideCharToMultiByte (CP_UTF8, 0, path.c_str (), -1, raw_path_utf, MAX_PATH, nullptr, nullptr);
return Glib::ustring(raw_path_utf);
# else
return Glib::ustring (raw_path_utf);
#else
// no UNICODE, simply return plain string
return path;
# endif //~UNICODE
#endif //~UNICODE
}
else
throw FileError(FileError::FAILED, _("Unable to obtain Application Data directory"));
throw FileError (FileError::FAILED, _ ("Unable to obtain Application Data directory"));
#else
const ustring dir = get_home_dir() + G_DIR_SEPARATOR_S + ".sgpemv2";
if(!file_test(dir, FILE_TEST_IS_DIR))
const ustring dir = get_home_dir () + G_DIR_SEPARATOR_S + ".sgpemv2";
if (!file_test (dir, FILE_TEST_IS_DIR))
{
const int err = g_mkdir(dir.c_str(), 0755);
if(err != 0)
throw FileError(FileError::FAILED, g_strerror(err));
const int err = g_mkdir (dir.c_str (), 0755);
if (err != 0)
throw FileError (FileError::FAILED, g_strerror (err));
}
return dir;
@ -107,32 +103,32 @@ GlobalPreferences::get_preferences_dir() const
Glib::ustring
GlobalPreferences::get_config_filename() const
GlobalPreferences::get_config_filename () const
{
const Glib::ustring filename = get_preferences_dir() + G_DIR_SEPARATOR_S + Glib::ustring("sgpemrc");
const Glib::ustring filename = get_preferences_dir () + G_DIR_SEPARATOR_S + Glib::ustring ("sgpemrc");
return filename;
}
GlobalPreferences::DirVector&
GlobalPreferences::get_policy_dirs()
GlobalPreferences::DirVector &
GlobalPreferences::get_policy_dirs ()
{
return _pol_dirs;
}
GlobalPreferences::DirVector&
GlobalPreferences::get_plugin_dirs()
GlobalPreferences::DirVector &
GlobalPreferences::get_plugin_dirs ()
{
return _mod_dirs;
}
int
GlobalPreferences::get_speed()
GlobalPreferences::get_speed ()
{
return _speed;
}
int
GlobalPreferences::set_speed(int new_speed)
GlobalPreferences::set_speed (int new_speed)
{
int old_speed = _speed;
_speed = new_speed;
@ -140,9 +136,9 @@ GlobalPreferences::set_speed(int new_speed)
}
const Glib::ustring
GlobalPreferences::get_schedulable_color(Schedulable::state st) const
GlobalPreferences::get_schedulable_color (Schedulable::state st) const
{
switch(st)
switch (st)
{
case Schedulable::state_running:
return "ForestGreen";
@ -160,9 +156,9 @@ GlobalPreferences::get_schedulable_color(Schedulable::state st) const
}
const Glib::ustring
GlobalPreferences::get_request_color(Request::state st) const
GlobalPreferences::get_request_color (Request::state st) const
{
switch(st)
switch (st)
{
case Request::state_allocated:
return "ForestGreen";
@ -180,32 +176,31 @@ GlobalPreferences::get_request_color(Request::state st) const
}
void
GlobalPreferences::write_configrc()
GlobalPreferences::write_configrc ()
{
KeyFile kf;
key_file_write(kf);
kf.file_write(get_config_filename());
key_file_write (kf);
kf.file_write (get_config_filename ());
}
void
GlobalPreferences::load_configrc()
GlobalPreferences::load_configrc ()
{
KeyFile kf;
kf.file_read(get_config_filename());
key_file_read(kf);
kf.file_read (get_config_filename ());
key_file_read (kf);
}
void
GlobalPreferences::key_file_read(KeyFile& kf)
GlobalPreferences::key_file_read (KeyFile &kf)
{
_mod_dirs.clear();
_pol_dirs.clear();
std::vector<Glib::ustring> old_mod_dirs(1, PLUGDIR);
std::vector<Glib::ustring> old_pol_dirs(1, POLDIR);
_mod_dirs.clear ();
_pol_dirs.clear ();
std::vector<Glib::ustring> old_mod_dirs (1, PLUGDIR);
std::vector<Glib::ustring> old_pol_dirs (1, POLDIR);
_mod_dirs = old_mod_dirs;
_pol_dirs = old_pol_dirs;
@ -213,31 +208,31 @@ GlobalPreferences::key_file_read(KeyFile& kf)
// read speed
{
int new_speed = 1000; // use a default value
const Glib::ustring* val = kf.search_value(Glib::ustring("speed"));
const Glib::ustring *val = kf.search_value (Glib::ustring ("speed"));
if (val)
{
new_speed = string_to<int>(*val);
set_speed(new_speed);
new_speed = string_to<int> (*val);
set_speed (new_speed);
}
}
// read modules directories
{
const Glib::ustring* val = kf.search_value(Glib::ustring("modules-dir-number"));
const Glib::ustring *val = kf.search_value (Glib::ustring ("modules-dir-number"));
if (val)
{
std::istringstream istr(*val);
std::istringstream istr (*val);
int n;
istr >> n;
for (int i = 1; i <= n; i++)
{
std::ostringstream ostr;
ostr << "modules-dir-" << i;
Glib::ustring key(ostr.str());
val = kf.search_value(key);
Glib::ustring key (ostr.str ());
val = kf.search_value (key);
if (val && *val != _mod_dirs[0])
{
// add_modules_dir(*val);
_mod_dirs.push_back(*val);
_mod_dirs.push_back (*val);
}
}
}
@ -245,39 +240,37 @@ GlobalPreferences::key_file_read(KeyFile& kf)
// read policies directories
{
const Glib::ustring* val = kf.search_value(Glib::ustring("policies-dir-number"));
const Glib::ustring *val = kf.search_value (Glib::ustring ("policies-dir-number"));
if (val)
{
std::istringstream istr(*val);
std::istringstream istr (*val);
int n;
istr >> n;
for (int i = 1; i <= n; i++)
{
std::ostringstream ostr;
ostr << "policies-dir-" << i;
Glib::ustring key(ostr.str().c_str());
val = kf.search_value(key);
Glib::ustring key (ostr.str ().c_str ());
val = kf.search_value (key);
if (val && *val != _pol_dirs[0])
{
// add_policies_dir(*val);
_pol_dirs.push_back(*val);
_pol_dirs.push_back (*val);
}
}
}
}
}
void
GlobalPreferences::key_file_write(KeyFile& kf)
GlobalPreferences::key_file_write (KeyFile &kf)
{
// write speed
{
Glib::ustring key("speed");
Glib::ustring key ("speed");
Glib::ustring value;
to_string<int>(_speed, value);
kf.insert_key_value(key, value);
to_string<int> (_speed, value);
kf.insert_key_value (key, value);
}
// add modules directories
@ -285,47 +278,45 @@ GlobalPreferences::key_file_write(KeyFile& kf)
/*
GlobalPreferences::dir_iterator iter=_globalPreferences.modules_dir_begin();
*/
DirVectorConstIt iter = _mod_dirs.begin();
DirVectorConstIt end = _mod_dirs.end();
DirVectorConstIt iter = _mod_dirs.begin ();
DirVectorConstIt end = _mod_dirs.end ();
int n = 0;
while (iter != end)
{
std::ostringstream ostr;
n++;
ostr << "modules-dir-" << n; // << std::ends;
Glib::ustring key(ostr.str().c_str());
kf.insert_key_value(key, (*iter));
Glib::ustring key (ostr.str ().c_str ());
kf.insert_key_value (key, (*iter));
++iter;
}
Glib::ustring key("modules-dir-number");
Glib::ustring key ("modules-dir-number");
std::ostringstream ostr;
ostr << n << std::ends;
Glib::ustring value(ostr.str().c_str());
kf.insert_key_value(key, value);
Glib::ustring value (ostr.str ().c_str ());
kf.insert_key_value (key, value);
}
// add policies directories
{
/*
GlobalPreferences::dir_iterator iter=_globalPreferences.policies_dir_begin();
*/
DirVectorConstIt iter = _pol_dirs.begin();
DirVectorConstIt end = _pol_dirs.end();
DirVectorConstIt iter = _pol_dirs.begin ();
DirVectorConstIt end = _pol_dirs.end ();
int n = 0;
while (iter != end)
{
std::ostringstream ostr;
n++;
ostr << "policies-dir-" << n; // << std::ends;
Glib::ustring key(ostr.str().c_str());
kf.insert_key_value(key, (*iter));
Glib::ustring key (ostr.str ().c_str ());
kf.insert_key_value (key, (*iter));
++iter;
}
Glib::ustring key("policies-dir-number");
Glib::ustring key ("policies-dir-number");
std::ostringstream ostr;
ostr << n << std::ends;
Glib::ustring value(ostr.str().c_str());
kf.insert_key_value(key, value);
Glib::ustring value (ostr.str ().c_str ());
kf.insert_key_value (key, value);
}
}

View File

@ -26,37 +26,36 @@
namespace sgpem
{
class GlobalPreferencesSerializer;
class GlobalPreferencesSerializer;
/** \brief Save and retrieve global preferences formatted as key=value rows.
/** \brief Save and retrieve global preferences formatted as key=value rows.
*
* This class handles files to store and retrieve global preferences
* in the form of: key=value rows.
*
*/
class SG_DLLLOCAL GlobalPreferencesSerializer : public KeyFile
{
class SG_DLLLOCAL GlobalPreferencesSerializer : public KeyFile
{
public:
/** \brief Object constructor */
GlobalPreferencesSerializer(GlobalPreferences &gp);
GlobalPreferencesSerializer (GlobalPreferences &gp);
/** \brief Read a file into this object.
*
* \param filename The file to read from.
*/
void file_read(const Glib::ustring& filename);
void file_read (const Glib::ustring &filename);
/** \brief Write a file from this object.
*
* \param filename The file to write to.
*/
void file_write(const Glib::ustring& filename);
void file_write (const Glib::ustring &filename);
private:
GlobalPreferences& _globalPreferences;
};
}
GlobalPreferences &_globalPreferences;
};
} // namespace sgpem
#endif

View File

@ -18,8 +18,6 @@
// along with SGPEMv2. If not, see http://www.gnu.org/licenses/.
#include <sgpemv2/history.hh>
#include <sgpemv2/history_observer.hh>
@ -29,58 +27,56 @@
using namespace sgpem;
History::History()
: _front(0), _notify(true)
History::History () : _front (0), _notify (true)
{
}
History::~History()
History::~History ()
{
}
void
History::attach(HistoryObserver& observer)
History::attach (HistoryObserver &observer)
{
_observers.push_back(&observer);
_observers.push_back (&observer);
}
void
History::detach(const HistoryObserver& observer)
History::detach (const HistoryObserver &observer)
{
_observers.erase(std::find(_observers.begin(),
_observers.end(),
&observer));
_observers.erase (std::find (_observers.begin (), _observers.end (), &observer));
}
void
History::notify_change()
History::notify_change ()
{
if (!_notify) return;
if (!_notify)
return;
for (RegisteredObservers::iterator it = _observers.begin();
it != _observers.end(); it++)
(*it)->update(*this);
for (RegisteredObservers::iterator it = _observers.begin (); it != _observers.end (); it++)
(*it)->update (*this);
}
unsigned int History::get_front() const
unsigned int
History::get_front () const
{
return _front;
}
bool
History::set_notify_enabled(bool enabled)
History::set_notify_enabled (bool enabled)
{
bool old_value = _notify;
_notify = enabled;
// Force notify if we re-enable it
if (old_value == false && _notify == true)
notify_change();
notify_change ();
return old_value;
}
@ -88,12 +84,11 @@ History::set_notify_enabled(bool enabled)
// --------- History::LockNotify ---------------
History::LockNotify::LockNotify(History& history)
: _h(history), _was_enabled(_h.set_notify_enabled(false))
History::LockNotify::LockNotify (History &history) : _h (history), _was_enabled (_h.set_notify_enabled (false))
{
}
History::LockNotify::~LockNotify()
History::LockNotify::~LockNotify ()
{
_h.set_notify_enabled(_was_enabled);
_h.set_notify_enabled (_was_enabled);
}

View File

@ -20,6 +20,8 @@
#include <sgpemv2/history_observer.hh>
sgpem::HistoryObserver::~HistoryObserver() {}
sgpem::HistoryObserver::~HistoryObserver ()
{
}
// Pure abstract class. Nothing else to put here.

View File

@ -18,12 +18,10 @@
// along with SGPEMv2. If not, see http://www.gnu.org/licenses/.
#include <sgpemv2/invalid_plugin_exception.hh>
using namespace sgpem;
InvalidPluginException::InvalidPluginException(const std::string& what) :
std::runtime_error(what)
{}
InvalidPluginException::InvalidPluginException (const std::string &what) : std::runtime_error (what)
{
}

View File

@ -18,9 +18,8 @@
// along with SGPEMv2. If not, see http://www.gnu.org/licenses/.
#include <sgpemv2/key_file.hh>
#include <fstream>
#include <sgpemv2/key_file.hh>
#include <string.h>
#include <iostream>
@ -29,106 +28,106 @@ using namespace std;
namespace sgpem
{
KeyFile::KeyFile()
{}
KeyFile::KeyFile ()
{
}
KeyFile::elements_iterator
KeyFile::elements_begin() const
{
return _elements.begin();
}
KeyFile::elements_iterator
KeyFile::elements_begin () const
{
return _elements.begin ();
}
KeyFile::elements_iterator
KeyFile::elements_end() const
{
return _elements.end();
}
KeyFile::elements_iterator
KeyFile::elements_end () const
{
return _elements.end ();
}
void
KeyFile::insert_key_value(const Glib::ustring& key, const Glib::ustring& value)
{
std::map<Glib::ustring, Glib::ustring>::value_type val_pair(key, value);
_elements.insert(val_pair);
}
void
KeyFile::insert_key_value (const Glib::ustring &key, const Glib::ustring &value)
{
std::map<Glib::ustring, Glib::ustring>::value_type val_pair (key, value);
_elements.insert (val_pair);
}
const Glib::ustring*
KeyFile::search_value(const Glib::ustring& key)
{
const Glib::ustring* ret = 0;
elements_iterator cur = _elements.find(key);
if (cur != elements_end())
const Glib::ustring *
KeyFile::search_value (const Glib::ustring &key)
{
const Glib::ustring *ret = 0;
elements_iterator cur = _elements.find (key);
if (cur != elements_end ())
{
ret = &((*cur).second);
}
return ret;
}
}
void
KeyFile::file_read(const Glib::ustring& filename)
{
std::ifstream ifs(filename.c_str());
void
KeyFile::file_read (const Glib::ustring &filename)
{
std::ifstream ifs (filename.c_str ());
if (ifs)
{
file_read(ifs);
file_read (ifs);
} // end - if(ifs)
}
}
void
KeyFile::file_read(std::istream& is)
{
void
KeyFile::file_read (std::istream &is)
{
const unsigned int KEY_FILE_BUF_LEN = 1000;
if (is)
{
_elements.clear(); // erase all elements
_elements.clear (); // erase all elements
char buff[KEY_FILE_BUF_LEN]; //
while (is)
{
is.getline(buff, (KEY_FILE_BUF_LEN), '\n');
is.getline (buff, (KEY_FILE_BUF_LEN), '\n');
// if not a comment line...
if (*buff != '\0' && *buff != '#')
{
char* pos = strchr(buff, '=');
char *pos = strchr (buff, '=');
if (pos != 0)
{
*pos = '\0';
const Glib::ustring key(buff);
const Glib::ustring value(pos + 1);
insert_key_value(key, value);
const Glib::ustring key (buff);
const Glib::ustring value (pos + 1);
insert_key_value (key, value);
}
} // end - if not a comment line...
} // end - while(ifs))
} // end - if(ifs)
}
}
void
KeyFile::file_write(const Glib::ustring& filename)
{
std::ofstream ofs(filename.c_str());
void
KeyFile::file_write (const Glib::ustring &filename)
{
std::ofstream ofs (filename.c_str ());
if (ofs)
{
file_write(ofs);
file_write (ofs);
} // end - if(ofs)
}
}
void
KeyFile::file_write(std::ostream& os)
{
void
KeyFile::file_write (std::ostream &os)
{
if (os)
{
elements_iterator iter;
for (iter = elements_begin(); iter != elements_end(); iter++)
for (iter = elements_begin (); iter != elements_end (); iter++)
{
os << (*iter).first << "=" << (*iter).second << std::endl;
}
} // end - if(ofs)
}
}
} // namespace sgpem

View File

@ -25,7 +25,6 @@
#include <sgpemv2/malformed_policy_exception.hh>
using namespace sgpem;
MalformedPolicyException::MalformedPolicyException(const std::string& msg)
: CPUPolicyException(msg)
{}
MalformedPolicyException::MalformedPolicyException (const std::string &msg) : CPUPolicyException (msg)
{
}

View File

@ -21,72 +21,72 @@
using namespace sgpem;
Module::Module(const Glib::ustring& identifier) :
Glib::Module(identifier),
_enabled(false),
_id(identifier),
on_init_ptr(NULL),
on_exit_ptr(NULL),
describe_ptr(NULL),
get_name_ptr(NULL),
get_author_ptr(NULL),
get_version_ptr(NULL)
Module::Module (const Glib::ustring &identifier)
: Glib::Module (identifier),
_enabled (false),
_id (identifier),
on_init_ptr (NULL),
on_exit_ptr (NULL),
describe_ptr (NULL),
get_name_ptr (NULL),
get_author_ptr (NULL),
get_version_ptr (NULL)
{
if (!*this) throw InvalidPluginException(Module::get_last_error());
if (!*this)
throw InvalidPluginException (Module::get_last_error ());
// Type-safeness here is an optional, as always. :-)
std::string prefix = "sgpem__Plugin__";
if (!(get_symbol(prefix + "on_init", reinterpret_cast<void*&>(on_init_ptr)) &&
get_symbol(prefix + "on_exit", reinterpret_cast<void*&>(on_exit_ptr)) &&
get_symbol(prefix + "describe", reinterpret_cast<void*&>(describe_ptr)) &&
get_symbol(prefix + "get_name", reinterpret_cast<void*&>(get_name_ptr)) &&
get_symbol(prefix + "get_author", reinterpret_cast<void*&>(get_author_ptr)) &&
get_symbol(prefix + "get_version", reinterpret_cast<void*&>(get_version_ptr))))
throw InvalidPluginException("incomplete/wrong exported interface");
if (!(get_symbol (prefix + "on_init", reinterpret_cast<void *&> (on_init_ptr)) &&
get_symbol (prefix + "on_exit", reinterpret_cast<void *&> (on_exit_ptr)) &&
get_symbol (prefix + "describe", reinterpret_cast<void *&> (describe_ptr)) &&
get_symbol (prefix + "get_name", reinterpret_cast<void *&> (get_name_ptr)) &&
get_symbol (prefix + "get_author", reinterpret_cast<void *&> (get_author_ptr)) &&
get_symbol (prefix + "get_version", reinterpret_cast<void *&> (get_version_ptr))))
throw InvalidPluginException ("incomplete/wrong exported interface");
}
void
Module::set_enabled(bool enabled)
Module::set_enabled (bool enabled)
{
if (_enabled == enabled)
return;
if (enabled)
on_init_ptr();
on_init_ptr ();
else
on_exit_ptr();
on_exit_ptr ();
_enabled = enabled;
}
Glib::ustring
Module::get_name() const
Module::get_name () const
{
return get_name_ptr();
return get_name_ptr ();
}
Glib::ustring
Module::get_author() const
Module::get_author () const
{
return get_author_ptr();
return get_author_ptr ();
}
Glib::ustring
Module::describe() const
Module::describe () const
{
return describe_ptr();
return describe_ptr ();
}
float
Module::get_version() const
Module::get_version () const
{
return get_version_ptr();
return get_version_ptr ();
}
bool
Module::get_enabled() const
Module::get_enabled () const
{
return _enabled;
}

View File

@ -26,8 +26,6 @@
using namespace sgpem;
NullPolicyException::NullPolicyException(const char* msg)
: std::runtime_error(msg)
NullPolicyException::NullPolicyException (const char *msg) : std::runtime_error (msg)
{
}

View File

@ -18,69 +18,66 @@
// along with SGPEMv2. If not, see http://www.gnu.org/licenses/.
#include <sgpemv2/plugin_manager.hh>
#include <sgpemv2/module.hh>
#include <sgpemv2/global_preferences.hh>
#include <sgpemv2/module.hh>
#include <sgpemv2/plugin_manager.hh>
#include <sgpemv2/templates/singleton.tcc>
#include <glibmm/fileutils.h>
#include <glibmm/pattern.h>
#include <iostream>
#include <algorithm>
#include <iostream>
using namespace sgpem;
template class sgpem::Singleton<PluginManager>;
std::vector<Module*>
PluginManager::get_module_list() const
std::vector<Module *>
PluginManager::get_module_list () const
{
return _modules;
}
void
PluginManager::rescan_dirs()
PluginManager::rescan_dirs ()
{
Module* module = nullptr;
Module *module = nullptr;
for_each(_modules.begin(), _modules.end(),
[] (auto *p) { delete p; });
_modules.clear();
for_each (_modules.begin (), _modules.end (), [](auto *p) { delete p; });
_modules.clear ();
GlobalPreferences& prefs = GlobalPreferences::get_instance();
GlobalPreferences::DirVector& plugin_dirs = prefs.get_plugin_dirs();
GlobalPreferences::DirVectorIt it = plugin_dirs.begin();
GlobalPreferences &prefs = GlobalPreferences::get_instance ();
GlobalPreferences::DirVector &plugin_dirs = prefs.get_plugin_dirs ();
GlobalPreferences::DirVectorIt it = plugin_dirs.begin ();
Glib::PatternSpec shared_obj(Glib::ustring("*.") + G_MODULE_SUFFIX);
Glib::PatternSpec shared_obj (Glib::ustring ("*.") + G_MODULE_SUFFIX);
while (it != plugin_dirs.end())
while (it != plugin_dirs.end ())
{
Glib::Dir dir(*it);
Glib::Dir dir (*it);
for (Glib::DirIterator dir_it = dir.begin(); dir_it != dir.end(); ++dir_it)
for (Glib::DirIterator dir_it = dir.begin (); dir_it != dir.end (); ++dir_it)
{
// only attempt to load .so files
if (shared_obj.match(*dir_it))
if (shared_obj.match (*dir_it))
{
std::string module_path = Module::build_path(*it, *dir_it);
std::string module_path = Module::build_path (*it, *dir_it);
std::cerr << "Attempting to load module at path " << module_path << std::endl;
try
{
module = new Module(module_path);
_modules.push_back(module);
module = new Module (module_path);
_modules.push_back (module);
std::cerr << "\tSuccess" << std::endl;
}
catch (InvalidPluginException& e)
catch (InvalidPluginException &e)
{
std::cerr << "\tFailed, invalid plugin: " << e.what() << std::endl;
std::cerr << "\tFailed, invalid plugin: " << e.what () << std::endl;
}
}
}
@ -89,8 +86,7 @@ PluginManager::rescan_dirs()
}
}
PluginManager::PluginManager()
PluginManager::PluginManager ()
{
rescan_dirs();
rescan_dirs ();
}

View File

@ -29,10 +29,10 @@ using Glib::ustring;
// instantiate Parameter template for use outside this DSO
namespace sgpem
{
template class SG_DLLEXPORT PolicyParameters::Parameter<int>;
template class SG_DLLEXPORT PolicyParameters::Parameter<float>;
template class SG_DLLEXPORT PolicyParameters::Parameter<Glib::ustring>;
}
template class SG_DLLEXPORT PolicyParameters::Parameter<int>;
template class SG_DLLEXPORT PolicyParameters::Parameter<float>;
template class SG_DLLEXPORT PolicyParameters::Parameter<Glib::ustring>;
} // namespace sgpem
/**
@ -40,25 +40,17 @@ namespace sgpem
If there is a parameter with the same name and type it will be overwritten.
*/
void
PolicyParameters::register_int(Glib::ustring name,
const int& lower_bound,
const int& upper_bound,
const bool& required,
const int& default_value)
PolicyParameters::register_int (Glib::ustring name, const int &lower_bound, const int &upper_bound,
const bool &required, const int &default_value)
{
//there is a parameter with the same name!!
map<ustring, Parameter<int> >::iterator i = int_map.find(name);
if (i != int_map.end())
int_map.erase(i);
map<ustring, Parameter<int> >::value_type v(name, Parameter<int>(name,
default_value,
lower_bound,
upper_bound,
required,
default_value));
int_map.insert(v);
map<ustring, Parameter<int>>::iterator i = int_map.find (name);
if (i != int_map.end ())
int_map.erase (i);
map<ustring, Parameter<int>>::value_type v (
name, Parameter<int> (name, default_value, lower_bound, upper_bound, required, default_value));
int_map.insert (v);
}
/**
@ -66,25 +58,18 @@ PolicyParameters::register_int(Glib::ustring name,
If there is a parameter with the same name and type it will be overwritten.
*/
void
PolicyParameters::register_float(Glib::ustring name,
const float& lower_bound,
const float& upper_bound,
const bool& required,
const float& default_value)
PolicyParameters::register_float (Glib::ustring name, const float &lower_bound, const float &upper_bound,
const bool &required, const float &default_value)
{
//there is a parameter with the same name!!
map<ustring, Parameter<float> >::iterator i = float_map.find(name);
if (i != float_map.end())
float_map.erase(i);
map<ustring, Parameter<float>>::iterator i = float_map.find (name);
if (i != float_map.end ())
float_map.erase (i);
map<ustring, Parameter<float> >::value_type v(name, Parameter<float>(name,
default_value,
lower_bound,
upper_bound,
required,
default_value));
map<ustring, Parameter<float>>::value_type v (
name, Parameter<float> (name, default_value, lower_bound, upper_bound, required, default_value));
float_map.insert(v);
float_map.insert (v);
}
/**
@ -92,20 +77,16 @@ PolicyParameters::register_float(Glib::ustring name,
If there is a parameter with the same name and type it will be overwritten.
*/
void
PolicyParameters::register_string(Glib::ustring name, const bool& required, const Glib::ustring& default_value)
PolicyParameters::register_string (Glib::ustring name, const bool &required, const Glib::ustring &default_value)
{
//there is a parameter with the same name!!
map<ustring, Parameter<Glib::ustring> >::iterator i = string_map.find(name);
if (i != string_map.end())
string_map.erase(i);
map<ustring, Parameter<Glib::ustring>>::iterator i = string_map.find (name);
if (i != string_map.end ())
string_map.erase (i);
map<ustring, Parameter<Glib::ustring> >::value_type v(name, Parameter<Glib::ustring>(name,
default_value,
"",
"",
required,
default_value));
string_map.insert(v);
map<ustring, Parameter<Glib::ustring>>::value_type v (
name, Parameter<Glib::ustring> (name, default_value, "", "", required, default_value));
string_map.insert (v);
}
/**
@ -113,18 +94,18 @@ PolicyParameters::register_string(Glib::ustring name, const bool& required, cons
*/
void
PolicyParameters::clear()
PolicyParameters::clear ()
{
int_map.clear();
float_map.clear();
string_map.clear();
int_map.clear ();
float_map.clear ();
string_map.clear ();
}
/**
Retruns a copy of the map containing all registered integer parameters.
*/
map<ustring, PolicyParameters::Parameter<int> >
PolicyParameters::get_registered_int_parameters() const
map<ustring, PolicyParameters::Parameter<int>>
PolicyParameters::get_registered_int_parameters () const
{
return int_map;
}
@ -132,8 +113,8 @@ PolicyParameters::get_registered_int_parameters() const
/**
Retruns a copy of the map containing all registered float parameters.
*/
map<ustring, PolicyParameters::Parameter<float> >
PolicyParameters::get_registered_float_parameters() const
map<ustring, PolicyParameters::Parameter<float>>
PolicyParameters::get_registered_float_parameters () const
{
return float_map;
}
@ -141,8 +122,8 @@ PolicyParameters::get_registered_float_parameters() const
/**
Retruns a copy of the map containing all registered string parameters.
*/
map<ustring, PolicyParameters::Parameter<ustring> >
PolicyParameters::get_registered_string_parameters() const
map<ustring, PolicyParameters::Parameter<ustring>>
PolicyParameters::get_registered_string_parameters () const
{
return string_map;
}
@ -154,17 +135,17 @@ PolicyParameters::get_registered_string_parameters() const
\returns FALSE in the other cases.
*/
bool
PolicyParameters::set_int(ustring name, const int& value)
PolicyParameters::set_int (ustring name, const int &value)
{
map<ustring, Parameter<int> >::iterator i = int_map.find(name);
if (i == int_map.end())
map<ustring, Parameter<int>>::iterator i = int_map.find (name);
if (i == int_map.end ())
//the parameter doesn't exist!!
return false;
if (value < i->second.get_lower_bound() || value > i->second.get_upper_bound())
if (value < i->second.get_lower_bound () || value > i->second.get_upper_bound ())
return false;
i->second.set_value(value);
i->second.set_value (value);
return true;
}
@ -176,17 +157,17 @@ PolicyParameters::set_int(ustring name, const int& value)
\returns FALSE in the other cases.
*/
bool
PolicyParameters::set_float(ustring name, const float& value)
PolicyParameters::set_float (ustring name, const float &value)
{
map<ustring, Parameter<float> >::iterator i = float_map.find(name);
if (i == float_map.end())
map<ustring, Parameter<float>>::iterator i = float_map.find (name);
if (i == float_map.end ())
//the parameter doesn't exist!!
return false;
if (value < i->second.get_lower_bound() || value > i->second.get_upper_bound())
if (value < i->second.get_lower_bound () || value > i->second.get_upper_bound ())
return false;
i->second.set_value(value);
i->second.set_value (value);
return true;
}
@ -197,14 +178,14 @@ PolicyParameters::set_float(ustring name, const float& value)
\returns FALSE in the other case.
*/
bool
PolicyParameters::set_string(ustring name, const ustring& value)
PolicyParameters::set_string (ustring name, const ustring &value)
{
map<ustring, Parameter<ustring> >::iterator i = string_map.find(name);
if (i == string_map.end())
map<ustring, Parameter<ustring>>::iterator i = string_map.find (name);
if (i == string_map.end ())
//the parameter doesn't exist!!
return false;
i->second.set_value(value);
i->second.set_value (value);
return true;
}
@ -214,13 +195,13 @@ PolicyParameters::set_string(ustring name, const ustring& value)
\throws A PolicyParametersException if the parameter has not been found.
*/
int
PolicyParameters::get_int(ustring name) const
PolicyParameters::get_int (ustring name) const
{
map<ustring, Parameter<int> >::const_iterator i = int_map.find(name);
if (i == int_map.end())
throw PolicyParametersException("Unregistred parameter");
map<ustring, Parameter<int>>::const_iterator i = int_map.find (name);
if (i == int_map.end ())
throw PolicyParametersException ("Unregistred parameter");
else
return i->second.get_value();
return i->second.get_value ();
}
@ -230,13 +211,13 @@ PolicyParameters::get_int(ustring name) const
\throws A PolicyParametersException if the parameter has not been found.
*/
float
PolicyParameters::get_float(ustring name) const
PolicyParameters::get_float (ustring name) const
{
map<ustring, Parameter<float> >::const_iterator i = float_map.find(name);
if (i == float_map.end())
throw PolicyParametersException("Unregistred parameter");
map<ustring, Parameter<float>>::const_iterator i = float_map.find (name);
if (i == float_map.end ())
throw PolicyParametersException ("Unregistred parameter");
else
return i->second.get_value();
return i->second.get_value ();
}
@ -246,12 +227,11 @@ PolicyParameters::get_float(ustring name) const
\throws A PolicyParametersException if the parameter has not been found.
*/
ustring
PolicyParameters::get_string(ustring name) const
PolicyParameters::get_string (ustring name) const
{
map<ustring, Parameter<ustring> >::const_iterator i = string_map.find(name);
if (i == string_map.end())
throw PolicyParametersException("Unregistred parameter");
map<ustring, Parameter<ustring>>::const_iterator i = string_map.find (name);
if (i == string_map.end ())
throw PolicyParametersException ("Unregistred parameter");
else
return i->second.get_value();
return i->second.get_value ();
}

View File

@ -22,6 +22,6 @@
using namespace sgpem;
Process::~Process()
{}
Process::~Process ()
{
}

View File

@ -22,12 +22,10 @@
using namespace sgpem;
ProcessStatistics::~ProcessStatistics()
ProcessStatistics::~ProcessStatistics ()
{
}
ProcessStatistics::ProcessStatistics()
ProcessStatistics::ProcessStatistics ()
{
}

View File

@ -24,66 +24,66 @@ using sgpem::ReadyQueue;
using sgpem::Thread;
void
ReadyQueue::swap(position a, position b)
ReadyQueue::swap (position a, position b)
{
if (a == b) return;
if (a == b)
return;
// Usage of "at()" isn't casual:
// at() checks indexes, "[]" doesn't.
// Once we've done the check once, we
// can assume it's safe to use "[]";
// this for performance reasons.
Thread* temp = _scheds.at(a);
_scheds[a] = _scheds.at(b);
Thread *temp = _scheds.at (a);
_scheds[a] = _scheds.at (b);
_scheds[b] = temp;
}
ReadyQueue::size_t
ReadyQueue::size() const
ReadyQueue::size () const
{
return _scheds.size();
return _scheds.size ();
}
sgpem::Thread&
ReadyQueue::get_item_at(position index)
sgpem::Thread &
ReadyQueue::get_item_at (position index)
{
// Checks index access
return *_scheds.at(index);
return *_scheds.at (index);
}
const sgpem::Thread&
ReadyQueue::get_item_at(position index) const
const sgpem::Thread &
ReadyQueue::get_item_at (position index) const
{
// Checks index access
return *_scheds.at(index);
return *_scheds.at (index);
}
void
ReadyQueue::append(Thread& thread)
ReadyQueue::append (Thread &thread)
{
_scheds.push_back(&thread);
_scheds.push_back (&thread);
}
void
ReadyQueue::bubble_to_front(position x)
ReadyQueue::bubble_to_front (position x)
{
while(x > 0)
while (x > 0)
{
swap(x - 1, x);
swap (x - 1, x);
--x;
}
}
void
ReadyQueue::erase_first()
ReadyQueue::erase_first ()
{
_scheds.erase(_scheds.begin());
_scheds.erase (_scheds.begin ());
}

View File

@ -22,6 +22,6 @@
using namespace sgpem;
Request::~Request()
{}
Request::~Request ()
{
}

View File

@ -22,7 +22,6 @@
using namespace sgpem;
Resource::~Resource()
Resource::~Resource ()
{
}

View File

@ -18,12 +18,10 @@
// along with SGPEMv2. If not, see http://www.gnu.org/licenses/.
#include <sgpemv2/resource_policies_gatekeeper.hh>
#include <sgpemv2/resource_policy_manager.hh>
#include <sgpemv2/resource_policy.hh>
#include "concrete_history.hh"
#include <sgpemv2/resource_policies_gatekeeper.hh>
#include <sgpemv2/resource_policy.hh>
#include <sgpemv2/resource_policy_manager.hh>
// Include full template definition only in implementation files:
#include <sgpemv2/templates/singleton.tcc>
@ -33,93 +31,94 @@
#include <algorithm>
#include <cassert>
using std::vector;
using std::map;
using std::find;
using std::map;
using std::runtime_error;
using std::vector;
using namespace sgpem;
// Explicit template instantiation to allow to export symbols from the DSO.
template class sgpem::Singleton<ResourcePoliciesGatekeeper>;
typedef vector<ResourcePolicyManager*>::iterator ManagerIterator;
typedef map<History*, ResourcePolicy*>::iterator PolicyIterator;
typedef vector<ResourcePolicyManager *>::iterator ManagerIterator;
typedef map<History *, ResourcePolicy *>::iterator PolicyIterator;
const vector<ResourcePolicyManager*>&
ResourcePoliciesGatekeeper::get_registered() const
const vector<ResourcePolicyManager *> &
ResourcePoliciesGatekeeper::get_registered () const
{
return _registered;
}
void
ResourcePoliciesGatekeeper::register_manager(ResourcePolicyManager* manager)
ResourcePoliciesGatekeeper::register_manager (ResourcePolicyManager *manager)
{
assert(manager != nullptr);
assert (manager != nullptr);
ManagerIterator end = _registered.end();
ManagerIterator end = _registered.end ();
if (find(_registered.begin(), end, manager) == end)
_registered.push_back(manager);
if (find (_registered.begin (), end, manager) == end)
_registered.push_back (manager);
}
void
ResourcePoliciesGatekeeper::unregister_manager(ResourcePolicyManager* manager)
ResourcePoliciesGatekeeper::unregister_manager (ResourcePolicyManager *manager)
{
assert(manager != nullptr);
assert (manager != nullptr);
ManagerIterator end = _registered.end();
ManagerIterator pos = find(_registered.begin(), end, manager);
ManagerIterator end = _registered.end ();
ManagerIterator pos = find (_registered.begin (), end, manager);
if (pos != end)
{
deactivate_policies(**pos);
_registered.erase(pos);
deactivate_policies (**pos);
_registered.erase (pos);
}
}
ResourcePolicy&
ResourcePoliciesGatekeeper::get_current_policy(History* history)
ResourcePolicy &
ResourcePoliciesGatekeeper::get_current_policy (History *history)
{
assert(history != nullptr);
assert (history != nullptr);
PolicyIterator policy = _active_policies.find(history);
PolicyIterator policy = _active_policies.find (history);
if (policy == _active_policies.end())
throw runtime_error(_("No active policy associated with this "
if (policy == _active_policies.end ())
throw runtime_error (
_ ("No active policy associated with this "
"history is available."));
return *policy->second;
}
void
ResourcePoliciesGatekeeper::activate_policy(History *history, ResourcePolicy* policy)
ResourcePoliciesGatekeeper::activate_policy (History *history, ResourcePolicy *policy)
{
assert(history != nullptr && policy != nullptr);
assert (history != nullptr && policy != nullptr);
_active_policies[history] = policy;
// the content of history (if any) is not vaild any more.
down_cast<ConcreteHistory*>(history)->reset();
down_cast<ConcreteHistory *> (history)->reset ();
}
ResourcePoliciesGatekeeper::ResourcePoliciesGatekeeper()
{}
ResourcePoliciesGatekeeper::ResourcePoliciesGatekeeper ()
{
}
void
ResourcePoliciesGatekeeper::deactivate_policies(const ResourcePolicyManager& manager)
ResourcePoliciesGatekeeper::deactivate_policies (const ResourcePolicyManager &manager)
{
typedef vector<ResourcePolicy*>::const_iterator AvailableIt;
typedef vector<ResourcePolicy *>::const_iterator AvailableIt;
const vector<ResourcePolicy*>& policies = manager.get_avail_policies();
const vector<ResourcePolicy *> &policies = manager.get_avail_policies ();
for (AvailableIt avail_it = policies.begin(); avail_it != policies.end(); ++avail_it)
for (AvailableIt avail_it = policies.begin (); avail_it != policies.end (); ++avail_it)
{
for (PolicyIterator it = _active_policies.begin(); it != _active_policies.end();)
for (PolicyIterator it = _active_policies.begin (); it != _active_policies.end ();)
if (it->second == *avail_it)
// Please note the postfix increment (operating
// on the old iterator, now invalidated by erase)
_active_policies.erase(it++);
_active_policies.erase (it++);
else
++it;
} //~ for(avail_it)
}

View File

@ -22,13 +22,13 @@
using namespace sgpem;
ResourcePolicy::~ResourcePolicy()
{}
ResourcePolicy::~ResourcePolicy ()
{
}
PolicyParameters&
ResourcePolicy::get_parameters()
PolicyParameters &
ResourcePolicy::get_parameters ()
{
return _parameters;
}

View File

@ -24,62 +24,62 @@
using namespace std;
using namespace sgpem;
ResourcePolicyFiFo::~ResourcePolicyFiFo()
{}
ResourcePolicyFiFo::~ResourcePolicyFiFo ()
{
}
void
ResourcePolicyFiFo::configure()
ResourcePolicyFiFo::configure ()
{
}
void
ResourcePolicyFiFo::enforce(Environment& /*environment*/, Environment::SubRequestQueue& queue, SubRequest& sr)
ResourcePolicyFiFo::enforce (Environment & /*environment*/, Environment::SubRequestQueue &queue, SubRequest &sr)
{
typedef Environment::SubRequestQueue SubRequestQueue;
// the last inserted request goes on the last free place.
SubRequestQueue old_queue(queue);
queue.clear();
SubRequestQueue old_queue (queue);
queue.clear ();
typedef SubRequestQueue::iterator It;
for (It i = old_queue.begin(); i != old_queue.end(); i++)
for (It i = old_queue.begin (); i != old_queue.end (); i++)
{
// allocated ones remain allocated
if((**i).get_state() == Request::state_allocated)
queue.push_back(*i);
if ((**i).get_state () == Request::state_allocated)
queue.push_back (*i);
}
typedef SubRequestQueue::iterator It;
for (It i = old_queue.begin(); i != old_queue.end(); i++)
if((**i).get_state() != Request::state_allocated && *i != &sr)
queue.push_back(*i);
queue.push_back(&sr);
for (It i = old_queue.begin (); i != old_queue.end (); i++)
if ((**i).get_state () != Request::state_allocated && *i != &sr)
queue.push_back (*i);
queue.push_back (&sr);
}
Glib::ustring
ResourcePolicyFiFo::get_description() const
ResourcePolicyFiFo::get_description () const
{
return _("A resource policy which satisfies earlier requests before older ones.");
return _ ("A resource policy which satisfies earlier requests before older ones.");
}
Glib::ustring
ResourcePolicyFiFo::get_name() const
ResourcePolicyFiFo::get_name () const
{
return _("First In, First Out");
return _ ("First In, First Out");
}
void
ResourcePolicyFiFo::activate()
ResourcePolicyFiFo::activate ()
{
}
void
ResourcePolicyFiFo::deactivate()
ResourcePolicyFiFo::deactivate ()
{
}

View File

@ -30,16 +30,16 @@
namespace sgpem
{
class ResourcePolicyFiFo;
class ResourcePolicyFiFo;
/** \brief
/** \brief
It's a Strategy wich stay for a resource allocating algorithm.
It implements the related resource allocation policy.
*/
class SG_DLLLOCAL ResourcePolicyFiFo : public ResourcePolicy
{
class SG_DLLLOCAL ResourcePolicyFiFo : public ResourcePolicy
{
public:
virtual ~ResourcePolicyFiFo();
virtual ~ResourcePolicyFiFo ();
/**
Initialize the inner components of the policy.
@ -47,7 +47,7 @@ namespace sgpem
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
*/
virtual void configure();
virtual void configure ();
/**
Mixes the queues.
@ -55,7 +55,7 @@ namespace sgpem
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
*/
virtual void enforce(Environment& environment, Environment::SubRequestQueue& queue, SubRequest& sr);
virtual void enforce (Environment &environment, Environment::SubRequestQueue &queue, SubRequest &sr);
/**
Gets a string description of the policy.
@ -64,16 +64,16 @@ namespace sgpem
in concrete derived classes.
\return String description of the policy.
*/
virtual Glib::ustring get_description() const;
virtual Glib::ustring get_description () const;
virtual Glib::ustring get_name() const;
virtual Glib::ustring get_name () const;
virtual void activate();
virtual void activate ();
virtual void deactivate();
};
virtual void deactivate ();
};
}//~ namespace sgpem
} // namespace sgpem
#endif //~ RESOURCE_POLICY_FIFO_HH

View File

@ -23,74 +23,74 @@
using namespace std;
using namespace sgpem;
ResourcePolicyLiFo::~ResourcePolicyLiFo()
{}
ResourcePolicyLiFo::~ResourcePolicyLiFo ()
{
}
void
ResourcePolicyLiFo::configure()
ResourcePolicyLiFo::configure ()
{
}
void
ResourcePolicyLiFo::enforce(Environment& /*environment*/, Environment::SubRequestQueue& queue, SubRequest& sr)
ResourcePolicyLiFo::enforce (Environment & /*environment*/, Environment::SubRequestQueue &queue, SubRequest &sr)
{
typedef Environment::SubRequestQueue SubRequestQueue;
// the last inserted request goes on the first free place.
SubRequestQueue old_queue(queue);
queue.clear();
SubRequestQueue old_queue (queue);
queue.clear ();
typedef SubRequestQueue::iterator It;
for (It i = old_queue.begin(); i != old_queue.end(); i++)
for (It i = old_queue.begin (); i != old_queue.end (); i++)
{
// allocated ones remain allocated
if((**i).get_state() == Request::state_allocated)
queue.push_back(*i);
if ((**i).get_state () == Request::state_allocated)
queue.push_back (*i);
}
bool inserted = false;
typedef SubRequestQueue::iterator It;
for (It i = old_queue.begin(); i != old_queue.end(); i++)
for (It i = old_queue.begin (); i != old_queue.end (); i++)
{
// allocated ones remain allocated
if((**i).get_state() != Request::state_allocated)
if ((**i).get_state () != Request::state_allocated)
{
// non-allocated ones go after the newly arrived
if(!inserted)
if (!inserted)
{
queue.push_back(&sr);
queue.push_back (&sr);
inserted = true;
}
if (*i != &sr)
queue.push_back(*i);
queue.push_back (*i);
}
}
}
Glib::ustring
ResourcePolicyLiFo::get_description() const
ResourcePolicyLiFo::get_description () const
{
return _("A resource policy which allows a request to be immediately allocated if there is enough space.");
return _ ("A resource policy which allows a request to be immediately allocated if there is enough space.");
}
Glib::ustring
ResourcePolicyLiFo::get_name() const
ResourcePolicyLiFo::get_name () const
{
return _("Last In, First Out");
return _ ("Last In, First Out");
}
void
ResourcePolicyLiFo::activate()
ResourcePolicyLiFo::activate ()
{
}
void
ResourcePolicyLiFo::deactivate()
ResourcePolicyLiFo::deactivate ()
{
}

View File

@ -31,30 +31,30 @@
namespace sgpem
{
class ResourcePolicyLiFo;
class ResourcePolicyLiFo;
/** \brief
/** \brief
It's a Strategy wich stay for a resource allocating algorithm.
It implements the related resource allocation policy.
*/
class SG_DLLLOCAL ResourcePolicyLiFo : public ResourcePolicy
{
class SG_DLLLOCAL ResourcePolicyLiFo : public ResourcePolicy
{
public:
virtual ~ResourcePolicyLiFo();
virtual ~ResourcePolicyLiFo ();
/** \brief Initialize the inner components of the policy.
*
* Because it's a pure virtual method, must be re-implemented
* in concrete derived classes.
*/
virtual void configure();
virtual void configure ();
/** \brief Mixes the queues.
*
* Because it's a pure virtual method, must be re-implemented
* in concrete derived classes.
*/
virtual void enforce(Environment& environment, Environment::SubRequestQueue& queue, SubRequest& sr);
virtual void enforce (Environment &environment, Environment::SubRequestQueue &queue, SubRequest &sr);
/** \brief Gets a string description of the policy.
*
@ -62,26 +62,26 @@ namespace sgpem
* in concrete derived classes.
* \return String description of the policy.
*/
virtual Glib::ustring get_description() const;
virtual Glib::ustring get_description () const;
/** \brief Returns the policy name
*/
virtual Glib::ustring get_name() const;
virtual Glib::ustring get_name () const;
/** \brief No-op method.
*
* \see ResourcePolicy::activate()
*/
virtual void activate();
virtual void activate ();
/** \brief No-op method.
*
* \see ResourcePolicy::deactivate()
*/
virtual void deactivate();
};
virtual void deactivate ();
};
}//~ namespace sgpem
} // namespace sgpem
#endif

View File

@ -18,20 +18,18 @@
// along with SGPEMv2. If not, see http://www.gnu.org/licenses/.
#include <sgpemv2/resource_policy_manager.hh>
#include <sgpemv2/resource_policies_gatekeeper.hh>
#include <sgpemv2/resource_policy_manager.hh>
using namespace sgpem;
ResourcePolicyManager::ResourcePolicyManager()
ResourcePolicyManager::ResourcePolicyManager ()
{
ResourcePoliciesGatekeeper::get_instance().register_manager(this);
ResourcePoliciesGatekeeper::get_instance ().register_manager (this);
}
ResourcePolicyManager::~ResourcePolicyManager()
ResourcePolicyManager::~ResourcePolicyManager ()
{
ResourcePoliciesGatekeeper::get_instance().unregister_manager(this);
ResourcePoliciesGatekeeper::get_instance ().unregister_manager (this);
}

View File

@ -24,77 +24,76 @@
using namespace sgpem;
ResourcePolicyPriority::~ResourcePolicyPriority()
ResourcePolicyPriority::~ResourcePolicyPriority ()
{
}
void
ResourcePolicyPriority::configure()
ResourcePolicyPriority::configure ()
{
}
void
ResourcePolicyPriority::enforce(Environment& /*environment*/, Environment::SubRequestQueue& queue, SubRequest& sr)
ResourcePolicyPriority::enforce (Environment & /*environment*/, Environment::SubRequestQueue &queue, SubRequest &sr)
{
typedef Environment::SubRequestQueue SubRequestQueue;
SubRequestQueue old_queue(queue);
queue.clear();
SubRequestQueue old_queue (queue);
queue.clear ();
typedef SubRequestQueue::iterator It;
for (It i = old_queue.begin(); i != old_queue.end(); i++)
for (It i = old_queue.begin (); i != old_queue.end (); i++)
{
// allocated ones remain allocated
if((**i).get_state() == Request::state_allocated)
queue.push_back(*i);
if ((**i).get_state () == Request::state_allocated)
queue.push_back (*i);
}
int pthis = sr.get_request().get_thread().get_current_priority();
int pthis = sr.get_request ().get_thread ().get_current_priority ();
// assume they are ordered by priority.
bool inserted = false;
typedef SubRequestQueue::iterator It;
for (It i = old_queue.begin(); i != old_queue.end(); i++)
for (It i = old_queue.begin (); i != old_queue.end (); i++)
{
// allocated ones remain allocated
if((**i).get_state() != Request::state_allocated)
if ((**i).get_state () != Request::state_allocated)
{
// non-allocated ones with lower priority go after the newly arrived
int pthat = (**i).get_request().get_thread().get_current_priority();
if(!inserted && pthis <= pthat)
int pthat = (**i).get_request ().get_thread ().get_current_priority ();
if (!inserted && pthis <= pthat)
{
queue.push_back(&sr);
queue.push_back (&sr);
inserted = true;
}
if (*i != &sr)
queue.push_back(*i);
queue.push_back (*i);
}
}
}
Glib::ustring
ResourcePolicyPriority::get_description() const
ResourcePolicyPriority::get_description () const
{
return _("A resource policy which satisfies higher priority requests before lower priority ones.");
return _ ("A resource policy which satisfies higher priority requests before lower priority ones.");
}
Glib::ustring
ResourcePolicyPriority::get_name() const
ResourcePolicyPriority::get_name () const
{
return _("Higher Priority First");
return _ ("Higher Priority First");
}
void
ResourcePolicyPriority::activate()
ResourcePolicyPriority::activate ()
{
}
void
ResourcePolicyPriority::deactivate()
ResourcePolicyPriority::deactivate ()
{
}

View File

@ -23,36 +23,34 @@
#include "gettext.h"
#include <sgpemv2/resource_policy.hh>
#include <sgpemv2/policy_parameters.hh>
#include <sgpemv2/resource_policy.hh>
#include <sgpemv2/user_interrupt_exception.hh>
#include <glibmm/ustring.h>
namespace sgpem
{
/// \brief A resource allocation policy which provides a better service
/// to higer priority threads.
///
/// A resource allocation policy which provides a better service
/// to higer priority threads. This policy sorts the request queues
/// following the priority of the owners of the requests.
class ResourcePolicyPriority;
/// \brief A resource allocation policy which provides a better service
/// to higer priority threads.
///
/// A resource allocation policy which provides a better service
/// to higer priority threads. This policy sorts the request queues
/// following the priority of the owners of the requests.
class ResourcePolicyPriority;
class SG_DLLLOCAL ResourcePolicyPriority : public ResourcePolicy
{
class SG_DLLLOCAL ResourcePolicyPriority : public ResourcePolicy
{
public:
/// \brief Standard virtual destructor.
///
/// Standard virtual destructor.
virtual ~ResourcePolicyPriority();
virtual ~ResourcePolicyPriority ();
/// \brief Initializes the inner components of the policy.
///
/// Does nothing.
virtual void configure();
virtual void configure ();
/// \brief Sorts the subrequest queue letting higher priority threads to be the first ones
/// to get the resources.
@ -63,33 +61,33 @@ namespace sgpem
/// \param environment the environment on which the policy applies.
/// \param queue the queue where a subrequest has just been added.
/// \param sr the subrequest which has just been added.
virtual void enforce(Environment& environment, Environment::SubRequestQueue& queue, SubRequest& sr);
virtual void enforce (Environment &environment, Environment::SubRequestQueue &queue, SubRequest &sr);
/// \brief Returns a description of the policy.
///
/// Returns a description of the policy.
/// \return a description of the policy.
virtual Glib::ustring get_description() const;
virtual Glib::ustring get_description () const;
/// \brief Returns the name of the policy.
///
/// Returns the name of the policy.
/// \return the name of the policy.
virtual Glib::ustring get_name() const;
virtual Glib::ustring get_name () const;
/// \brief Activates the policy.
///
/// Does nothing.
virtual void activate();
virtual void activate ();
/// \brief Deactivates the policy.
///
/// Does nothing.
virtual void deactivate();
};
virtual void deactivate ();
};
}//~ namespace sgpem
} // namespace sgpem
#endif

View File

@ -25,88 +25,91 @@
using namespace std;
using namespace sgpem;
ResourcePolicyPriorityInheritance::~ResourcePolicyPriorityInheritance()
{}
ResourcePolicyPriorityInheritance::~ResourcePolicyPriorityInheritance ()
{
}
void
ResourcePolicyPriorityInheritance::configure()
ResourcePolicyPriorityInheritance::configure ()
{
}
void
ResourcePolicyPriorityInheritance::enforce(Environment& /*environment*/, Environment::SubRequestQueue& queue, SubRequest& sr)
ResourcePolicyPriorityInheritance::enforce (Environment & /*environment*/, Environment::SubRequestQueue &queue, SubRequest &sr)
{
typedef Environment::SubRequestQueue SubRequestQueue;
SubRequestQueue old_queue(queue);
queue.clear();
SubRequestQueue old_queue (queue);
queue.clear ();
// the priority may only rise!
int pmax = sr.get_request().get_thread().get_current_priority();
int pmax = sr.get_request ().get_thread ().get_current_priority ();
typedef SubRequestQueue::iterator It;
for (It i = old_queue.begin(); i != old_queue.end(); i++)
for (It i = old_queue.begin (); i != old_queue.end (); i++)
{
// determine the max priority
int pthat = (**i).get_request().get_thread().get_current_priority();
int pthat = (**i).get_request ().get_thread ().get_current_priority ();
if (pthat < pmax)
pmax = pthat;
// allocated ones remain allocated
if((**i).get_state() == Request::state_allocated)
queue.push_back(*i);
if ((**i).get_state () == Request::state_allocated)
queue.push_back (*i);
}
int pthis = sr.get_request().get_thread().get_current_priority();
int pthis = sr.get_request ().get_thread ().get_current_priority ();
// assume they are ordered by priority.
bool inserted = false;
typedef SubRequestQueue::iterator It;
for (It i = old_queue.begin(); i != old_queue.end(); i++)
for (It i = old_queue.begin (); i != old_queue.end (); i++)
{
// allocated ones remain allocated
if((**i).get_state() != Request::state_allocated)
if ((**i).get_state () != Request::state_allocated)
{
// non-allocated ones with lower priority go after the newly arrived
int pthat = (**i).get_request().get_thread().get_current_priority();
if(!inserted && pthis <= pthat)
int pthat = (**i).get_request ().get_thread ().get_current_priority ();
if (!inserted && pthis <= pthat)
{
queue.push_back(&sr);
queue.push_back (&sr);
inserted = true;
}
if (*i != &sr)
queue.push_back(*i);
queue.push_back (*i);
}
else
{
// increase the priority of a the thread to the maximum priority of any process waiting
int push = pmax - (**i).get_request().get_thread().get_current_priority();
(**i).get_request().get_thread().set_priority_push(push);
int push = pmax - (**i).get_request ().get_thread ().get_current_priority ();
(**i).get_request ().get_thread ().set_priority_push (push);
}
}
}
Glib::ustring
ResourcePolicyPriorityInheritance::get_description() const
ResourcePolicyPriorityInheritance::get_description () const
{
return _("A resource policy which solves the priority inversion problem by raising the priority of a thread to the maximum relative to the queue.");
return _ (
"A resource policy which solves the priority inversion problem by raising the priority of a thread to the "
"maximum relative to the queue.");
}
Glib::ustring
ResourcePolicyPriorityInheritance::get_name() const
ResourcePolicyPriorityInheritance::get_name () const
{
return _("Basic Priority Inheritance Protocol");
return _ ("Basic Priority Inheritance Protocol");
}
void
ResourcePolicyPriorityInheritance::activate()
ResourcePolicyPriorityInheritance::activate ()
{
}
void
ResourcePolicyPriorityInheritance::deactivate()
ResourcePolicyPriorityInheritance::deactivate ()
{
}

View File

@ -23,25 +23,24 @@
namespace sgpem
{
class ResourcePolicyPriorityInheritance;
class ResourcePolicyPriorityInheritance;
}
#include <sgpemv2/resource_policy.hh>
namespace sgpem
{
/**
/**
* \brief It's a Strategy wich stay for a resource allocating algorithm.
* It implements the related resource allocation policy.
*/
class SG_DLLLOCAL ResourcePolicyPriorityInheritance : public ResourcePolicy
{
class SG_DLLLOCAL ResourcePolicyPriorityInheritance : public ResourcePolicy
{
public:
/// \brief Standard virtual destructor.
///
/// Standard virtual destructor.
virtual ~ResourcePolicyPriorityInheritance();
virtual ~ResourcePolicyPriorityInheritance ();
/**
\brief Initialize the inner components of the policy.
@ -49,7 +48,7 @@ namespace sgpem
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
*/
virtual void configure();
virtual void configure ();
/**
\brief Mixes the queues.
@ -57,9 +56,7 @@ namespace sgpem
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
*/
virtual void enforce(Environment& environment,
Environment::SubRequestQueue& queue,
SubRequest& sr);
virtual void enforce (Environment &environment, Environment::SubRequestQueue &queue, SubRequest &sr);
/**
\brief Gets a string description of the policy.
@ -68,16 +65,16 @@ namespace sgpem
in concrete derived classes.
\return String description of the policy.
*/
virtual Glib::ustring get_description() const;
virtual Glib::ustring get_description () const;
virtual Glib::ustring get_name() const;
virtual Glib::ustring get_name () const;
virtual void activate();
virtual void activate ();
virtual void deactivate();
};
virtual void deactivate ();
};
}//~ namespace sgpem
} // namespace sgpem
#endif

View File

@ -24,16 +24,19 @@
using namespace sgpem;
Schedulable::~Schedulable()
{}
unsigned int Schedulable::get_remaining_time() const
Schedulable::~Schedulable ()
{
assert(get_total_cpu_time() >= get_elapsed_time());
return get_total_cpu_time() - get_elapsed_time();
}
int Schedulable::get_priority_push() const
unsigned int
Schedulable::get_remaining_time () const
{
return get_current_priority() - get_base_priority();
assert (get_total_cpu_time () >= get_elapsed_time ());
return get_total_cpu_time () - get_elapsed_time ();
}
int
Schedulable::get_priority_push () const
{
return get_current_priority () - get_base_priority ();
}

View File

@ -22,11 +22,10 @@
using namespace sgpem;
SchedulableStatistics::SchedulableStatistics()
SchedulableStatistics::SchedulableStatistics ()
{
}
SchedulableStatistics::~SchedulableStatistics()
SchedulableStatistics::~SchedulableStatistics ()
{
}

View File

@ -18,7 +18,6 @@
// along with SGPEMv2. If not, see http://www.gnu.org/licenses/.
/*
// DISCLAIMER FOR THE RAMPANT CODER: \\
// ----------------------------------------------------\\
@ -36,8 +35,8 @@
#include <sgpemv2/scheduler.hh>
// Do not include full template definition in the header file
#include <sgpemv2/templates/singleton.tcc>
#include <sgpemv2/templates/sequences.tcc>
#include <sgpemv2/templates/singleton.tcc>
#include <glibmm/thread.h>
@ -52,81 +51,78 @@ using namespace sgpem;
template class sgpem::Singleton<Scheduler>;
typedef std::vector<DynamicProcess*> Processes;
typedef std::vector<DynamicRequest*> Requests;
typedef std::vector<DynamicSubRequest*> SubRequests;
typedef std::vector<DynamicThread*> Threads;
typedef std::vector<DynamicProcess *> Processes;
typedef std::vector<DynamicRequest *> Requests;
typedef std::vector<DynamicSubRequest *> SubRequests;
typedef std::vector<DynamicThread *> Threads;
typedef Environment::Resources Resources;
typedef Environment::SubRequestQueue SubRequestQueue;
// ------------------ Static helper functions --------------
inline bool is_running(const Thread* running_thread);
static void collect_threads(const std::vector<Process*>& procs, Threads& collected_threads);
static void prepare_ready_queue(ConcreteEnvironment& snapshot, const Threads& all_threads);
static void terminate_all_requests_of(DynamicThread& thread, ConcreteEnvironment& environment);
static void update_allocated_requests(DynamicThread& running_thread, ConcreteEnvironment& environment);
static void raise_new_requests(DynamicThread& running_thread, ConcreteEnvironment& environment, ResourcePolicy& resource_policy);
static void look_for_mutant_request_states(ConcreteEnvironment& environment, unsigned int& alive_threads);
static void determine_subr_allocable_status(const Resource& res, const SubRequestQueue& queue);
inline bool is_running (const Thread *running_thread);
static void collect_threads (const std::vector<Process *> &procs, Threads &collected_threads);
static void prepare_ready_queue (ConcreteEnvironment &snapshot, const Threads &all_threads);
static void terminate_all_requests_of (DynamicThread &thread, ConcreteEnvironment &environment);
static void update_allocated_requests (DynamicThread &running_thread, ConcreteEnvironment &environment);
static void raise_new_requests (DynamicThread &running_thread, ConcreteEnvironment &environment, ResourcePolicy &resource_policy);
static void look_for_mutant_request_states (ConcreteEnvironment &environment, unsigned int &alive_threads);
static void determine_subr_allocable_status (const Resource &res, const SubRequestQueue &queue);
// ---------------------------------------------------------
bool
is_running(const Thread* running_thread)
is_running (const Thread *running_thread)
{
return running_thread != nullptr && running_thread->get_state() == Schedulable::state_running;
return running_thread != nullptr && running_thread->get_state () == Schedulable::state_running;
}
// Collects all threads of an environment into a single vector
void
collect_threads(const std::vector<Process*>& procs,
Threads& collected_threads)
collect_threads (const std::vector<Process *> &procs, Threads &collected_threads)
{
collected_threads.clear();
for (Iseq<vector<Process*>::const_iterator> seq = iseq(procs); seq; ++seq)
collected_threads.clear ();
for (Iseq<vector<Process *>::const_iterator> seq = iseq (procs); seq; ++seq)
{
const Threads& ts = ((DynamicProcess&) **seq).get_dynamic_threads();
collected_threads.insert(collected_threads.end(), ts.begin(), ts.end());
const Threads &ts = ((DynamicProcess &) **seq).get_dynamic_threads ();
collected_threads.insert (collected_threads.end (), ts.begin (), ts.end ());
}
}
void
prepare_ready_queue(ConcreteEnvironment& snapshot,
const Threads& all_threads)
prepare_ready_queue (ConcreteEnvironment &snapshot, const Threads &all_threads)
{
ReadyQueue& queue = snapshot.get_sorted_queue();
assert(queue.size() == 0);
for (Iseq<Threads::const_iterator> seq = iseq(all_threads); seq; ++seq)
ReadyQueue &queue = snapshot.get_sorted_queue ();
assert (queue.size () == 0);
for (Iseq<Threads::const_iterator> seq = iseq (all_threads); seq; ++seq)
{
if ((*seq)->get_state() == Schedulable::state_ready)
queue.append(**seq);
if ((*seq)->get_state () == Schedulable::state_ready)
queue.append (**seq);
}
}
// When a thread terminates, unconditionally kill all its requests
void
terminate_all_requests_of(DynamicThread& thread,
ConcreteEnvironment& environment)
terminate_all_requests_of (DynamicThread &thread, ConcreteEnvironment &environment)
{
Requests& reqs = thread.get_dynamic_requests();
for (Iseq<Requests::iterator> r_it = iseq(reqs); r_it; ++r_it)
Requests &reqs = thread.get_dynamic_requests ();
for (Iseq<Requests::iterator> r_it = iseq (reqs); r_it; ++r_it)
{
SubRequests& subreqs = (*r_it)->get_dynamic_subrequests();
for (Iseq<SubRequests::iterator> s_it = iseq(subreqs); s_it; ++s_it)
SubRequests &subreqs = (*r_it)->get_dynamic_subrequests ();
for (Iseq<SubRequests::iterator> s_it = iseq (subreqs); s_it; ++s_it)
{
(*s_it)->set_state(Request::state_exhausted);
Environment::resource_key_t rkey = (*s_it)->get_resource_key();
SubRequestQueue& queue = environment.get_request_queue(rkey);
SubRequestQueue::iterator removable = find(queue.begin(), queue.end(), *s_it);
if(removable != queue.end()) queue.erase(removable);
(*s_it)->set_state (Request::state_exhausted);
Environment::resource_key_t rkey = (*s_it)->get_resource_key ();
SubRequestQueue &queue = environment.get_request_queue (rkey);
SubRequestQueue::iterator removable = find (queue.begin (), queue.end (), *s_it);
if (removable != queue.end ())
queue.erase (removable);
}
}
}
@ -134,27 +130,27 @@ terminate_all_requests_of(DynamicThread& thread,
// For the current thread, see if there are requests that are exhausted
void
update_allocated_requests(DynamicThread& running_thread,
ConcreteEnvironment& environment)
update_allocated_requests (DynamicThread &running_thread, ConcreteEnvironment &environment)
{
// Go for all dynamic requests of this thread
Requests& reqs = running_thread.get_dynamic_requests();
for (Iseq<Requests::iterator> req_it = iseq(reqs); req_it; ++req_it)
Requests &reqs = running_thread.get_dynamic_requests ();
for (Iseq<Requests::iterator> req_it = iseq (reqs); req_it; ++req_it)
{
SubRequests& cur_request = (*req_it)->get_dynamic_subrequests();
for (Iseq<SubRequests::iterator> subr_it = iseq(cur_request); subr_it; ++subr_it)
SubRequests &cur_request = (*req_it)->get_dynamic_subrequests ();
for (Iseq<SubRequests::iterator> subr_it = iseq (cur_request); subr_it; ++subr_it)
{
DynamicSubRequest& cur_subr = **subr_it;
if(cur_subr.get_state() == Request::state_allocated)
DynamicSubRequest &cur_subr = **subr_it;
if (cur_subr.get_state () == Request::state_allocated)
{
cur_subr.decrease_remaining_time();
if(cur_subr.get_remaining_time() == 0)
cur_subr.decrease_remaining_time ();
if (cur_subr.get_remaining_time () == 0)
{
cur_subr.set_state(Request::state_exhausted);
Environment::resource_key_t rkey = cur_subr.get_resource_key();
SubRequestQueue& queue = environment.get_request_queue(rkey);
SubRequestQueue::iterator removable = find(queue.begin(), queue.end(), &cur_subr);
if(removable != queue.end()) queue.erase(removable);
cur_subr.set_state (Request::state_exhausted);
Environment::resource_key_t rkey = cur_subr.get_resource_key ();
SubRequestQueue &queue = environment.get_request_queue (rkey);
SubRequestQueue::iterator removable = find (queue.begin (), queue.end (), &cur_subr);
if (removable != queue.end ())
queue.erase (removable);
}
}
} //~ for(over subrequests)
@ -169,44 +165,43 @@ update_allocated_requests(DynamicThread& running_thread,
// Remember that a thread may run only if all of its requests are either FUTURE,
// ALLOCATED or EXHAUSTED.
void
raise_new_requests(DynamicThread& running_thread, ConcreteEnvironment& environment, ResourcePolicy& resource_policy)
raise_new_requests (DynamicThread &running_thread, ConcreteEnvironment &environment, ResourcePolicy &resource_policy)
{
// Go for all dynamic requests of this thread
Requests& reqs = running_thread.get_dynamic_requests();
for (Iseq<Requests::iterator> req_it = iseq(reqs); req_it; ++req_it)
Requests &reqs = running_thread.get_dynamic_requests ();
for (Iseq<Requests::iterator> req_it = iseq (reqs); req_it; ++req_it)
{
DynamicRequest& cur_req = **req_it;
SubRequests& subreqs = (*req_it)->get_dynamic_subrequests();
DynamicRequest &cur_req = **req_it;
SubRequests &subreqs = (*req_it)->get_dynamic_subrequests ();
// Add to the queue only requests passing from future to another state:
if(cur_req.get_state() == Request::state_future &&
cur_req.get_instant() == running_thread.get_elapsed_time())
if (cur_req.get_state () == Request::state_future && cur_req.get_instant () == running_thread.get_elapsed_time ())
{
for (Iseq<SubRequests::iterator> subr_it = iseq(subreqs); subr_it; ++subr_it)
for (Iseq<SubRequests::iterator> subr_it = iseq (subreqs); subr_it; ++subr_it)
{
// Do the proper adding:
DynamicSubRequest& cur_subr = **subr_it;
Environment::resource_key_t rkey = cur_subr.get_resource_key();
SubRequestQueue& queue = environment.get_request_queue(rkey);
queue.push_back(&cur_subr);
DynamicSubRequest &cur_subr = **subr_it;
Environment::resource_key_t rkey = cur_subr.get_resource_key ();
SubRequestQueue &queue = environment.get_request_queue (rkey);
queue.push_back (&cur_subr);
/// TODO: right here, right now we should call the resource policy to
/// update the queue. Updates the state of the subrequest depending
/// on the position in the queue, as explained before.
resource_policy.enforce(environment, queue, cur_subr);
resource_policy.enforce (environment, queue, cur_subr);
// Get the number of places for the corresponding resource
Resource& resource = *environment.get_resources().find(rkey)->second;
Resource &resource = *environment.get_resources ().find (rkey)->second;
// WARNING: adding a new request may require updating the status of ALL other
// requests in the queue
determine_subr_allocable_status(resource, queue);
determine_subr_allocable_status (resource, queue);
// after that, check if it is globally allocable.
// See if the subrequest is allocable or unallocable, and set its state.
// It's important that the subrequest has already been added to the queue.
// determine_subr_allocable_status(cur_req, cur_subr, resource, queue);
// determine_subr_allocable_status(cur_req, cur_subr, resource, queue);
} //~ for(over subrequests)
@ -224,16 +219,15 @@ raise_new_requests(DynamicThread& running_thread, ConcreteEnvironment& environme
// resources to threads).
// If it is actually allocable, allocate it
switch(cur_req.get_state())
switch (cur_req.get_state ())
{
case Request::state_allocable:
{
const SubRequests& const_subreqs = subreqs;
for(Iseq<SubRequests::const_iterator> it_dsrs = iseq(const_subreqs); it_dsrs; ++it_dsrs)
const SubRequests &const_subreqs = subreqs;
for (Iseq<SubRequests::const_iterator> it_dsrs = iseq (const_subreqs); it_dsrs; ++it_dsrs)
{
DynamicSubRequest& subreq = **it_dsrs;
assert(subreq.get_state() == Request::state_allocable);
DynamicSubRequest &subreq = **it_dsrs;
assert (subreq.get_state () == Request::state_allocable);
/*
// Move this request up the queue, to the back of the allocated
// subrequests. This is mainly for display. :-)
@ -248,19 +242,19 @@ raise_new_requests(DynamicThread& running_thread, ConcreteEnvironment& environme
assert(this_subreq != queue.end());
swap(*alloc_it, *this_subreq);
*/
subreq.set_state(Request::state_allocated);
subreq.set_state (Request::state_allocated);
}
}
break;
case Request::state_unallocable:
// If it does exist at least one unallocable request, the thread may not run!
running_thread.set_state(Schedulable::state_blocked);
running_thread.set_state (Schedulable::state_blocked);
break;
default:
break;
}//~ switch(request state)
} //~ switch(request state)
} //~ for(over requests)
}
@ -269,24 +263,23 @@ raise_new_requests(DynamicThread& running_thread, ConcreteEnvironment& environme
// The following loop updates the states of the subrequests depending
// on their position in the queue
void
determine_subr_allocable_status(const Resource& res, const SubRequestQueue& queue)
determine_subr_allocable_status (const Resource &res, const SubRequestQueue &queue)
{
unsigned int total_places = res.get_places();
unsigned int total_places = res.get_places ();
unsigned int position_in_queue = 0;
for(Iseq<SubRequestQueue::const_iterator> queue_it = iseq(queue);
queue_it; queue_it++, position_in_queue++)
for (Iseq<SubRequestQueue::const_iterator> queue_it = iseq (queue); queue_it; queue_it++, position_in_queue++)
{
DynamicSubRequest& sr = (DynamicSubRequest&) **queue_it;
if (sr.get_state() == Request::state_allocated)
DynamicSubRequest &sr = (DynamicSubRequest &) **queue_it;
if (sr.get_state () == Request::state_allocated)
continue;
if(position_in_queue + 1 > total_places)
if (position_in_queue + 1 > total_places)
{
sr.set_state(Request::state_unallocable);
sr.set_state (Request::state_unallocable);
// Kludge:
sr.get_request().get_thread().set_state(Schedulable::state_blocked);
sr.get_request ().get_thread ().set_state (Schedulable::state_blocked);
}
else
sr.set_state(Request::state_allocable);
sr.set_state (Request::state_allocable);
} //~ for(over subrequest queue)
}
@ -295,8 +288,7 @@ determine_subr_allocable_status(const Resource& res, const SubRequestQueue& queu
// step of the simulation. It also put previously blocked threads
// back into ready state if need arises.
void
look_for_mutant_request_states(ConcreteEnvironment& environment,
unsigned int& alive_threads)
look_for_mutant_request_states (ConcreteEnvironment &environment, unsigned int &alive_threads)
{
// Now listening to: Testament's ``First Strike Is Still Deadly''
// The name of this function evokes mighty monsters from the abyss. In
@ -304,82 +296,77 @@ look_for_mutant_request_states(ConcreteEnvironment& environment,
// it's got brass bells on).
// We start assuming that SubRequestsQueues are up-to-date
Resources& resources = environment.get_resources();
for(Iseq<Resources::iterator> res_it = iseq(resources); res_it; ++res_it)
Resources &resources = environment.get_resources ();
for (Iseq<Resources::iterator> res_it = iseq (resources); res_it; ++res_it)
{
Environment::resource_key_t rkey = res_it->first;
SubRequestQueue& queue = environment.get_request_queue(rkey);
SubRequestQueue &queue = environment.get_request_queue (rkey);
unsigned int queue_pos = 0;
for(Iseq<SubRequestQueue::iterator> subr_it = iseq(queue); subr_it; ++subr_it, ++queue_pos)
for (Iseq<SubRequestQueue::iterator> subr_it = iseq (queue); subr_it; ++subr_it, ++queue_pos)
{
DynamicSubRequest& subr = (DynamicSubRequest&) **subr_it;
DynamicRequest& req = subr.get_request();
Request::state prev_req_state = req.get_state();
DynamicSubRequest &subr = (DynamicSubRequest &) **subr_it;
DynamicRequest &req = subr.get_request ();
Request::state prev_req_state = req.get_state ();
// If a request is already allocated, we don't have to touch it!
if(prev_req_state == Request::state_allocated)
if (prev_req_state == Request::state_allocated)
continue;
// Update the state of the subrequest, either from allocable to
// unallocable or vice-versa
// determine_subr_allocable_status(req, subr, *res_it->second, queue);
determine_subr_allocable_status(*res_it->second, queue);
// determine_subr_allocable_status(req, subr, *res_it->second, queue);
determine_subr_allocable_status (*res_it->second, queue);
// TODO: The following is a moderately expensive operation
// to do here. See if we can move it somewhere else.
// If a request changes state from allocable to unallocable,
// the corresponding thread should be blocked, and vice-versa
DynamicThread& thread = req.get_thread();
if(prev_req_state == Request::state_allocable &&
req.get_state() == Request::state_unallocable)
DynamicThread &thread = req.get_thread ();
if (prev_req_state == Request::state_allocable && req.get_state () == Request::state_unallocable)
{
if(thread.get_state() != Schedulable::state_blocked)
if (thread.get_state () != Schedulable::state_blocked)
alive_threads--;
thread.set_state(Schedulable::state_blocked);
thread.set_state (Schedulable::state_blocked);
}
else if(prev_req_state == Request::state_unallocable &&
req.get_state() == Request::state_allocable)
else if (prev_req_state == Request::state_unallocable && req.get_state () == Request::state_allocable)
{
if(thread.get_state() == Schedulable::state_blocked)
if (thread.get_state () == Schedulable::state_blocked)
alive_threads++;
thread.set_state(Schedulable::state_ready);
thread.set_state (Schedulable::state_ready);
}
} //~ for(over subrequests in the queue)
} //~ for(over resources)
}
// ---------------------------------------------------------
//private constructor.
Scheduler::Scheduler()
: _ready_queue(NULL), _policy(NULL), _step_mutex()
{}
Scheduler::Scheduler () : _ready_queue (NULL), _policy (NULL), _step_mutex ()
{
}
ReadyQueue*
Scheduler::get_ready_queue()
ReadyQueue *
Scheduler::get_ready_queue ()
{
return _ready_queue;
}
CPUPolicy*
Scheduler::get_policy()
CPUPolicy *
Scheduler::get_policy ()
{
return _policy;
}
bool
Scheduler::step_forward(History& history, CPUPolicy& cpu_policy, ResourcePolicy& resource_policy)
Scheduler::step_forward (History &history, CPUPolicy &cpu_policy, ResourcePolicy &resource_policy)
{
// This very method should be exclusive: no concurrent behaviour, from when we
@ -390,47 +377,47 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy, ResourcePolicy&
// NOTE: Be sure to read the *ORIGINAL* documentation in the design document for this method!
unsigned int alive_threads = 0; // Assume we've finished. Then prove me wrong.
int current_instant = history.get_size() - 1; /* They should be equivalent */
int current_instant = history.get_size () - 1; /* They should be equivalent */
// Safe cast:
ConcreteHistory& concrete_history = static_cast<ConcreteHistory&>(history);
ConcreteHistory &concrete_history = static_cast<ConcreteHistory &> (history);
// Use an auto_ptr since we've some exceptions in the coming...
unique_ptr<ConcreteEnvironment> new_snapshot(new ConcreteEnvironment(concrete_history.get_environment_at(current_instant)));
unique_ptr<ConcreteEnvironment> new_snapshot (new ConcreteEnvironment (concrete_history.get_environment_at (current_instant)));
Threads all_threads;
DynamicThread* running_thread = nullptr;
DynamicThread *running_thread = nullptr;
collect_threads(new_snapshot->get_processes(), all_threads);
collect_threads (new_snapshot->get_processes (), all_threads);
// The first thing we've to do is to update the state of the old
// running thread, if there's one.
for (Iseq<Threads::iterator> it = iseq(all_threads); it; ++it)
for (Iseq<Threads::iterator> it = iseq (all_threads); it; ++it)
{
DynamicThread& current = **it;
DynamicThread &current = **it;
// Save the current running thread for future usage, if it hasn't ended
// its allotted time
if (current.get_state() == Schedulable::state_running)
if (current.get_state () == Schedulable::state_running)
{
running_thread = &current; // Even if we can change its state to terminate
// increasing the time elapsed of the running thread + process
// should be done here as the first thing, instead than
// directly after selecting them
if (current.get_total_cpu_time() - current.get_elapsed_time() > 0)
current.decrease_remaining_time();
if (current.get_total_cpu_time () - current.get_elapsed_time () > 0)
current.decrease_remaining_time ();
// 4a. Look for exhausted requests for the running thread
update_allocated_requests(current, *new_snapshot);
update_allocated_requests (current, *new_snapshot);
// 2. mark threads that used all their allotted time as terminated,
// and put their requests as exhausted
if (current.get_total_cpu_time() - current.get_elapsed_time() == 0)
if (current.get_total_cpu_time () - current.get_elapsed_time () == 0)
{
current.set_state(Schedulable::state_terminated);
current.set_last_release(current_instant);
terminate_all_requests_of(current, *new_snapshot);
current.set_state (Schedulable::state_terminated);
current.set_last_release (current_instant);
terminate_all_requests_of (current, *new_snapshot);
running_thread = nullptr;
}
@ -444,24 +431,23 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy, ResourcePolicy&
// When a new instant cames, we could have to update the state of future
// threads to make them ready. We also keep a count of alive threads
for (Iseq<Threads::iterator> it = iseq(all_threads); it; ++it)
for (Iseq<Threads::iterator> it = iseq (all_threads); it; ++it)
{
DynamicThread& current = **it;
DynamicThread &current = **it;
// 1. mark future threads as ready, if appropriate
if (current.get_state() == Schedulable::state_future)
if (current.get_state () == Schedulable::state_future)
{
Process& parent = current.get_process();
if ((long) parent.get_arrival_time() <= current_instant &&
parent.get_elapsed_time() == current.get_arrival_time())
current.set_state(Schedulable::state_ready);
Process &parent = current.get_process ();
if ((long) parent.get_arrival_time () <= current_instant && parent.get_elapsed_time () == current.get_arrival_time ())
current.set_state (Schedulable::state_ready);
}
// 3. check for simulation termination (we can directly use threads
// for this check, since processes' state is based upon threads' one)
Schedulable::state cur_state = current.get_state();
Schedulable::state cur_state = current.get_state ();
if ((cur_state & (Schedulable::state_blocked | Schedulable::state_terminated)) == 0 &&
(current.get_process().get_state() & (Schedulable::state_terminated | Schedulable::state_blocked)) == 0) // check for holes
(current.get_process ().get_state () & (Schedulable::state_terminated | Schedulable::state_blocked)) == 0) // check for holes
{
alive_threads++;
}
@ -471,11 +457,12 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy, ResourcePolicy&
// ?. Time to see if some unallocable request became allocable, so
// the thread can pass from blocked to ready state, or the other way
// round
look_for_mutant_request_states(*new_snapshot, alive_threads);
look_for_mutant_request_states (*new_snapshot, alive_threads);
// Now if the simulation ended we append the newly
// created environment and return false
if (alive_threads == 0) goto final_cleanup;
if (alive_threads == 0)
goto final_cleanup;
// Use the CPU Policy to sort the ready queue, and manage
// requests for the newly selected running thread
@ -485,54 +472,55 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy, ResourcePolicy&
// use from external plugins. In fact, this is how get_ready_queue()
// acts as a callback function.
_policy = &cpu_policy;
_ready_queue = &new_snapshot->get_sorted_queue();
_ready_queue = &new_snapshot->get_sorted_queue ();
// Determine if the policy is pre_emptive, and what time slice it uses
bool preemptive_policy = cpu_policy.is_pre_emptive();
int time_slice = cpu_policy.get_time_slice();
bool preemptive_policy = cpu_policy.is_pre_emptive ();
int time_slice = cpu_policy.get_time_slice ();
// ?. See if old running_thread has to be put to ready state
// This happens when a time slice ends
if (is_running(running_thread) && time_slice > 0 &&
if (is_running (running_thread) && time_slice > 0 &&
// A process can be preempted every n-th time-slice, so we use the modulo operator:
(current_instant - running_thread->get_last_acquisition()) % time_slice == 0)
(current_instant - running_thread->get_last_acquisition ()) % time_slice == 0)
{
running_thread->set_state(Schedulable::state_ready);
running_thread->set_last_release(current_instant);
running_thread->set_state (Schedulable::state_ready);
running_thread->set_last_release (current_instant);
}
prepare_ready_queue(*new_snapshot, all_threads);
prepare_ready_queue (*new_snapshot, all_threads);
// If the policy is preemptible, and we still have a running thread,
// add it to the queue.
if(preemptive_policy && is_running(running_thread))
_ready_queue->append(*running_thread);
if (preemptive_policy && is_running (running_thread))
_ready_queue->append (*running_thread);
// ?. Ask the policy to sort the queue. If we must select
// a new thread and it can't run for some reason (it goes blocked, or
// terminates), then we remove it from the built ReadyQueue and
// check if the next one can run (see while loop further below).
if(_ready_queue->size() > 0) cpu_policy.sort_queue();
if (_ready_queue->size () > 0)
cpu_policy.sort_queue ();
// If we don't have to select a new running thread, because the old one didn't
// have to release the CPU, our work may end here:
// * if the current running thread doesn't block, we can perform the final cleanup,
// since the queue is already sorted
// * else we've to select another running thread, so we continue down in the method
if( // Non-preemptive policy, not ended time-slice:
(!preemptive_policy && is_running(running_thread)) ||
if ( // Non-preemptive policy, not ended time-slice:
(!preemptive_policy && is_running (running_thread)) ||
// Pre-emptive policy, running thread still the first of the queue.
// Note: if is_running(running_thread) == true, then _ready_queue->size() > 0
(preemptive_policy && is_running(running_thread) && &_ready_queue->get_item_at(0) == running_thread) )
(preemptive_policy && is_running (running_thread) && &_ready_queue->get_item_at (0) == running_thread))
{
raise_new_requests(*running_thread, *new_snapshot, resource_policy);
if(running_thread->get_state() != Schedulable::state_blocked)
raise_new_requests (*running_thread, *new_snapshot, resource_policy);
if (running_thread->get_state () != Schedulable::state_blocked)
goto final_cleanup;
else
{
running_thread->set_last_release(current_instant);
_ready_queue->erase_first();
running_thread->set_last_release (current_instant);
_ready_queue->erase_first ();
running_thread = nullptr;
alive_threads--;
// Proceed to select a new running thread, below
@ -540,35 +528,35 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy, ResourcePolicy&
}
bool we_ve_got_a_winner = false;
while(_ready_queue->size() > 0 && !we_ve_got_a_winner) // No sense in trying to schedule something that isn't there
while (_ready_queue->size () > 0 && !we_ve_got_a_winner) // No sense in trying to schedule something that isn't there
{
// Else, it's time to see if the first candidate can run
DynamicThread& candidate = (DynamicThread&) _ready_queue->get_item_at(0);
DynamicThread &candidate = (DynamicThread &) _ready_queue->get_item_at (0);
// If a thread has been created with duration "0" (silly, but possible);
// if you think it's safe, you can change this condition with an assert
// and delete the body of the ``if''.
if(candidate.get_total_cpu_time() - candidate.get_elapsed_time() == 0)
if (candidate.get_total_cpu_time () - candidate.get_elapsed_time () == 0)
{
candidate.set_last_acquisition(current_instant);
candidate.set_last_release(current_instant);
candidate.set_state(Schedulable::state_terminated);
candidate.set_last_acquisition (current_instant);
candidate.set_last_release (current_instant);
candidate.set_state (Schedulable::state_terminated);
// Put every request of this thread to state_exhausted
terminate_all_requests_of(candidate, *new_snapshot);
_ready_queue->erase_first();
terminate_all_requests_of (candidate, *new_snapshot);
_ready_queue->erase_first ();
alive_threads--;
continue;
}
// Now we check if our candidate blocks on a new request
raise_new_requests(candidate, *new_snapshot, resource_policy);
if(candidate.get_state() != Schedulable::state_blocked)
raise_new_requests (candidate, *new_snapshot, resource_policy);
if (candidate.get_state () != Schedulable::state_blocked)
// If we got here, our candidate can run
we_ve_got_a_winner /*!hurrah!*/ = true;
else // if blocked, we've to remove it from the ready queue
{
_ready_queue->erase_first();
_ready_queue->erase_first ();
alive_threads--;
}
}
@ -578,26 +566,25 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy, ResourcePolicy&
if (we_ve_got_a_winner)
{
// Fix fields of running thread
DynamicThread& new_running = (DynamicThread&) _ready_queue->get_item_at(0);
_ready_queue->erase_first();
new_running.set_state(Schedulable::state_running);
DynamicThread &new_running = (DynamicThread &) _ready_queue->get_item_at (0);
_ready_queue->erase_first ();
new_running.set_state (Schedulable::state_running);
// If the new running is different from the old one,
// remember to release our old pal, and to acquire our
// new runner.
if(&new_running != running_thread)
if (&new_running != running_thread)
{
if(running_thread != nullptr)
if (running_thread != nullptr)
{
running_thread->set_state(Schedulable::state_ready);
running_thread->set_last_release(current_instant);
running_thread->set_state (Schedulable::state_ready);
running_thread->set_last_release (current_instant);
}
new_running.set_last_acquisition(current_instant);
new_running.set_last_acquisition (current_instant);
}
}
}
catch (const CPUPolicyException& e)
catch (const CPUPolicyException &e)
{
// Reset values that the policy doesn't need anymore
_policy = nullptr;
@ -615,7 +602,7 @@ final_cleanup:
// append the new snapshot...
// ...and remember to release the auto_ptr!
concrete_history.append_new_environment(new_snapshot.release());
concrete_history.append_new_environment (new_snapshot.release ());
// Reset values that the policy doesn't need anymore
_policy = nullptr;

View File

@ -22,6 +22,6 @@
using namespace sgpem;
SerializeVisitor::~SerializeVisitor()
{}
SerializeVisitor::~SerializeVisitor ()
{
}

View File

@ -24,14 +24,13 @@
using namespace sgpem;
Serializer::Serializer()
Serializer::Serializer ()
{
// automatically register subclasses to the manager
SerializersGatekeeper::get_instance().register_serializer(this);
SerializersGatekeeper::get_instance ().register_serializer (this);
}
Serializer::~Serializer()
Serializer::~Serializer ()
{
// INSPECTOR NOTE: no unregister here?
}

View File

@ -18,12 +18,10 @@
// along with SGPEMv2. If not, see http://www.gnu.org/licenses/.
#include <sgpemv2/serializer_error.hh>
using namespace sgpem;
SerializerError::SerializerError(const std::string& what) :
std::runtime_error(what)
{}
SerializerError::SerializerError (const std::string &what) : std::runtime_error (what)
{
}

View File

@ -18,10 +18,8 @@
// along with SGPEMv2. If not, see http://www.gnu.org/licenses/.
#include <sgpemv2/serializers_gatekeeper.hh>
#include <sgpemv2/serializer.hh>
#include <sgpemv2/serializers_gatekeeper.hh>
// Include full template definition only in implementation files:
#include <sgpemv2/templates/singleton.tcc>
@ -29,50 +27,48 @@
#include <algorithm>
#include <cassert>
using std::vector;
using std::find;
using std::runtime_error;
using std::vector;
using namespace sgpem;
// Explicit template instantiation to allow to export symbols from the DSO.
template class sgpem::Singleton<SerializersGatekeeper>;
typedef vector<Serializer*>::iterator SerializerIterator;
typedef vector<Serializer *>::iterator SerializerIterator;
vector<Serializer*>
SerializersGatekeeper::get_registered() const
vector<Serializer *>
SerializersGatekeeper::get_registered () const
{
return _registered;
}
void
SerializersGatekeeper::register_serializer(Serializer* serializer)
SerializersGatekeeper::register_serializer (Serializer *serializer)
{
assert(serializer != nullptr);
assert (serializer != nullptr);
SerializerIterator end = _registered.end();
SerializerIterator end = _registered.end ();
if (find(_registered.begin(), end, serializer) == end)
_registered.push_back(serializer);
if (find (_registered.begin (), end, serializer) == end)
_registered.push_back (serializer);
}
void
SerializersGatekeeper::unregister_serializer(Serializer* serializer)
SerializersGatekeeper::unregister_serializer (Serializer *serializer)
{
assert(serializer != nullptr);
assert (serializer != nullptr);
SerializerIterator end = _registered.end();
SerializerIterator pos = find(_registered.begin(), end, serializer);
SerializerIterator end = _registered.end ();
SerializerIterator pos = find (_registered.begin (), end, serializer);
if (pos != end)
{
_registered.erase(pos);
_registered.erase (pos);
}
}
SerializersGatekeeper::SerializersGatekeeper()
SerializersGatekeeper::SerializersGatekeeper ()
{
}

View File

@ -5,4 +5,3 @@
#define POLDIR "@policiesdir@"
#define PLUGDIR "@plugindir@"
#define EXAMPLESDIR "@examplesdir@"

View File

@ -23,26 +23,26 @@
namespace sgpem
{
class CPUPolicyManager;
class CPUPolicy;
class History;
}
class CPUPolicyManager;
class CPUPolicy;
class History;
} // namespace sgpem
#include <sgpemv2/sgpemv2-visibility.hh>
#include <vector>
#include <map>
#include <stdexcept>
#include <vector>
#include <sgpemv2/templates/singleton.hh>
#include <sgpemv2/malformed_policy_exception.hh>
#include <sgpemv2/templates/singleton.hh>
#include <sgpemv2/user_interrupt_exception.hh>
namespace sgpem
{
class CPUPoliciesGatekeeper;
class CPUPoliciesGatekeeper;
/** \brief This is the container of all CPU policies found on the system.
/** \brief This is the container of all CPU policies found on the system.
*
* Keeps all registered policy managers in order to access to available policies
* Every CPUPolicyManager should register itself to this class so that
@ -50,22 +50,22 @@ namespace sgpem
*
* This class' constructor should be friend with Singleton (shake hands, make a smile!).
*/
class SG_DLLEXPORT CPUPoliciesGatekeeper : public Singleton<CPUPoliciesGatekeeper>
{
class SG_DLLEXPORT CPUPoliciesGatekeeper : public Singleton<CPUPoliciesGatekeeper>
{
friend class Singleton<CPUPoliciesGatekeeper>;
public:
typedef CPUPolicyManager Manager;
typedef std::vector<Manager*> Managers;
typedef std::vector<Manager *> Managers;
/** \brief Returns registered ::CPUManager */
Managers get_registered() const;
Managers get_registered () const;
/** \brief Register a new manager
*
* A no-op if a manager of the same type already exists
*/
void register_manager(CPUPolicyManager* manager);
void register_manager (CPUPolicyManager *manager);
/** \brief Unregister a given manager
*
@ -73,35 +73,33 @@ namespace sgpem
* to ensure that the currently active policies weren't managed by it. If so, the policies
* should be deactivated before removal.
*/
void unregister_manager(CPUPolicyManager* manager);
void unregister_manager (CPUPolicyManager *manager);
/** \brief Returns the currently active policy
*
* If no policy was previously activated for the attached
* ::History, throw an appropriate exception.
*/
CPUPolicy* get_current_policy(History* history);
CPUPolicy *get_current_policy (History *history);
/** \brief Associates a policy with history.
* If an exception is thrown, the current associated *policy with this history
* (if there are any), is \b no more active, \b nor associated
*/
void activate_policy(History* history, CPUPolicy* policy);
void activate_policy (History *history, CPUPolicy *policy);
private:
CPUPoliciesGatekeeper(); //private constructor.
CPUPoliciesGatekeeper(const CPUPoliciesGatekeeper&);
CPUPoliciesGatekeeper& operator=(const CPUPoliciesGatekeeper&);
CPUPoliciesGatekeeper (); //private constructor.
CPUPoliciesGatekeeper (const CPUPoliciesGatekeeper &);
CPUPoliciesGatekeeper &operator= (const CPUPoliciesGatekeeper &);
/** \brief Deactivates active policies managed by the specified manager. */
void deactivate_policies(CPUPolicyManager* manager);
void deactivate_policies (CPUPolicyManager *manager);
Managers _registered;
std::map<History*, CPUPolicy*> _active_policies;
};
std::map<History *, CPUPolicy *> _active_policies;
};
}//~ namespace sgpem
} // namespace sgpem
#endif //~ CPU_POLICIES_GATEKEEPER_HH

View File

@ -21,31 +21,31 @@
#ifndef CPU_POLICY_HH
#define CPU_POLICY_HH 1
#include <sgpemv2/sgpemv2-visibility.hh>
#include "gettext.h"
#include <sgpemv2/sgpemv2-visibility.hh>
#include "glibmm/ustring.h"
#include <sgpemv2/malformed_policy_exception.hh>
#include <sgpemv2/policy_parameters.hh>
#include <sgpemv2/user_interrupt_exception.hh>
#include <sgpemv2/malformed_policy_exception.hh>
#include <stdexcept>
namespace sgpem
{
class CPUPolicy;
class CPUPolicy;
/** \brief
/** \brief
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 ReadyQueue.
*/
class SG_DLLEXPORT CPUPolicy
{
class SG_DLLEXPORT CPUPolicy
{
public:
virtual ~CPUPolicy();
virtual ~CPUPolicy ();
/**
Initialize the inner components of the policy.
@ -53,7 +53,7 @@ namespace sgpem
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
*/
virtual void configure() = 0;
virtual void configure () = 0;
/**
Sort the \ref ReadyQueue object that contain all the Schedulable objects
@ -62,7 +62,7 @@ namespace sgpem
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
*/
virtual void sort_queue() const = 0;
virtual void sort_queue () const = 0;
/**
Gets a string description of the policy.
@ -71,9 +71,9 @@ namespace sgpem
in concrete derived classes.
\return String description of the policy.
*/
virtual Glib::ustring get_description() const = 0;
virtual Glib::ustring get_description () const = 0;
virtual Glib::ustring get_name() const = 0;
virtual Glib::ustring get_name () const = 0;
/**
Tell if this policy is preemptible.
@ -82,7 +82,7 @@ namespace sgpem
in concrete derived classes.
\return True if this policy is preemptible.
*/
virtual bool is_pre_emptive() const = 0;
virtual bool is_pre_emptive () const = 0;
/**
Gets the time quantum for the policy.
@ -91,33 +91,32 @@ namespace sgpem
in concrete derived classes.
\return Time quantum for the policy.
*/
virtual int get_time_slice() const = 0;
virtual int get_time_slice () const = 0;
virtual void activate() = 0;
virtual void activate () = 0;
virtual void deactivate() = 0;
virtual void deactivate () = 0;
/**
Gets the parameters related with this policy.
\return The policy parameters.
*/
PolicyParameters& get_parameters();
PolicyParameters &get_parameters ();
/** This method is used only as a callback by scripting languages */
static CPUPolicy* callback_get_policy();
static CPUPolicy *callback_get_policy ();
protected:
PolicyParameters _parameters;
static void set_callback_policy(CPUPolicy* ptr = nullptr);
static void set_callback_policy (CPUPolicy *ptr = nullptr);
private:
// Used by callback_get_policy:
static CPUPolicy* _callback_policy;
static CPUPolicy *_callback_policy;
};
};
}//~ namespace sgpem
} // namespace sgpem
#endif //~ CPU_POLICY_HH

View File

@ -31,13 +31,13 @@
namespace sgpem
{
class CPUPolicyException;
class CPUPolicyException;
class SG_DLLEXPORT CPUPolicyException : public std::runtime_error
{
class SG_DLLEXPORT CPUPolicyException : public std::runtime_error
{
public:
explicit CPUPolicyException(const std::string& msg = "");
};
} //~ namespace sgpem
explicit CPUPolicyException (const std::string &msg = "");
};
} // namespace sgpem
#endif

View File

@ -23,7 +23,7 @@
namespace sgpem
{
class CPUPolicyManager;
class CPUPolicyManager;
}
#include <sgpemv2/sgpemv2-visibility.hh>
@ -35,15 +35,15 @@ namespace sgpem
namespace sgpem
{
/**
/**
\brief CPUPolicyManager is the Abstract Factory for
\ref CPUPolicy objects.
*/
class SG_DLLEXPORT CPUPolicyManager
{
class SG_DLLEXPORT CPUPolicyManager
{
public:
typedef CPUPolicy Policy;
typedef std::vector<Policy*> Policies;
typedef std::vector<Policy *> Policies;
/** \brief CPUPolicyManager constructor
*
@ -51,11 +51,11 @@ namespace sgpem
* when needed. This is done so that concrete subclasses can be defined
* even if they are found in external dynamic modules not known at compile time.
*/
CPUPolicyManager();
CPUPolicyManager ();
virtual ~CPUPolicyManager() = 0;
virtual ~CPUPolicyManager () = 0;
virtual const Policies& get_avail_policies() = 0;
virtual const Policies &get_avail_policies () = 0;
protected:
/**
@ -68,12 +68,11 @@ namespace sgpem
* method will be called at some time during the initialization of
* the manager (usually inside the constructor).
*/
virtual void collect_policies() = 0;
virtual void collect_policies () = 0;
std::vector<CPUPolicy*> _policies;
};
std::vector<CPUPolicy *> _policies;
};
} //~ namespace sgpem
} // namespace sgpem
#endif

View File

@ -23,7 +23,7 @@
namespace sgpem
{
class ResourcePolicy;
class ResourcePolicy;
}
#include <sgpemv2/sgpemv2-visibility.hh>
@ -35,33 +35,32 @@ namespace sgpem
namespace sgpem
{
class CppResourcePolicyManager;
class CppResourcePolicyManager;
/**
/**
ResourcePolicyManager is the Abstract Factory for \ref ResourcePolicy objects.
*/
class SG_DLLEXPORT CppResourcePolicyManager : public ResourcePolicyManager
{
class SG_DLLEXPORT CppResourcePolicyManager : public ResourcePolicyManager
{
public:
/** \brief CppResourcePolicyManager constructor
*
* Registers itself to the ResourcePoliciesGatekeeper singleton.
*/
CppResourcePolicyManager();
CppResourcePolicyManager ();
virtual ~CppResourcePolicyManager();
virtual ~CppResourcePolicyManager ();
virtual const std::vector<ResourcePolicy*>& get_avail_policies() const;
virtual const std::vector<ResourcePolicy *> &get_avail_policies () const;
private:
std::vector<ResourcePolicy*> _policies;
std::vector<ResourcePolicy *> _policies;
// an Instance of this class is created by default and it is registered to
// the ResourcePolicyGateKeeper
static CppResourcePolicyManager _default_instance;
};
};
} //~ namespace sgpem
} // namespace sgpem
#endif

View File

@ -31,38 +31,38 @@
namespace sgpem
{
class ReadyQueue;
class Process;
class Request;
class Resource;
class ReadyQueue;
class Process;
class Request;
class Resource;
/// \brief An instant of the simulation.
/// An object of the Environment class represents a snapshot of
/// the simulated environment taken in a fixed instant, composed
/// by processes, threads, resources and more.
/// A snapshot for every single entity is accessible from here.
/// All the provided objects and data is constant.
///
/// Class History provides access to Environments for each instant
/// of the simulation.
///
/// Anyway, as well as the returned collections contain non-const
/// pointers, it will be possible to call non-const member functions
/// on these objects. This has no consequences until someone adds
/// non-const member functions to these classes.
///
/// This class is abstract: it provides the public interface to
/// read the content of an History.
/// \see History
/// \brief An instant of the simulation.
/// An object of the Environment class represents a snapshot of
/// the simulated environment taken in a fixed instant, composed
/// by processes, threads, resources and more.
/// A snapshot for every single entity is accessible from here.
/// All the provided objects and data is constant.
///
/// Class History provides access to Environments for each instant
/// of the simulation.
///
/// Anyway, as well as the returned collections contain non-const
/// pointers, it will be possible to call non-const member functions
/// on these objects. This has no consequences until someone adds
/// non-const member functions to these classes.
///
/// This class is abstract: it provides the public interface to
/// read the content of an History.
/// \see History
class SG_DLLEXPORT Environment
{
class SG_DLLEXPORT Environment
{
public:
typedef SubRequest::resource_key_t resource_key_t;
typedef std::vector<Process*> Processes;
typedef std::map<resource_key_t, Resource*> Resources;
typedef std::vector<SubRequest*> SubRequestQueue;
typedef std::vector<Process *> Processes;
typedef std::map<resource_key_t, Resource *> Resources;
typedef std::vector<SubRequest *> SubRequestQueue;
/// \brief Returns an indexed set of snapshots of the processes
/// Returns a standard vector of Process objects describing
@ -71,8 +71,7 @@ namespace sgpem
///
/// \return a constant set of snapshots of processes
virtual const Processes&
get_processes() const = 0;
virtual const Processes &get_processes () const = 0;
/// \brief Returns an indexed set of snapshots of the resources
@ -89,8 +88,7 @@ namespace sgpem
///
/// \return an indexed constant set of snapshot of resources.
virtual const Resources&
get_resources() const = 0;
virtual const Resources &get_resources () const = 0;
/// \brief Returns a snapshot of the current request queue for a resource.
@ -100,8 +98,7 @@ namespace sgpem
/// \param resource the resource the requests are for
/// \return the current ready requests queue (constant).
virtual const SubRequestQueue&
get_request_queue(resource_key_t resource_key) const = 0;
virtual const SubRequestQueue &get_request_queue (resource_key_t resource_key) const = 0;
/// \brief Returns a snapshot of the current scheduler's ready queue.
@ -111,18 +108,15 @@ namespace sgpem
/// of the CPU.
/// \return the current ready queue (constant).
virtual const ReadyQueue&
get_sorted_queue() const = 0;
virtual const ReadyQueue &get_sorted_queue () const = 0;
/// \brief The standard virtual destructor.
/// The standard virtual destructor.
virtual
~Environment() = 0;
};
virtual ~Environment () = 0;
};
}
} // namespace sgpem
#endif

View File

@ -30,25 +30,26 @@
#include <vector>
// Do not include complete template definition here:
#include <sgpemv2/templates/singleton.hh>
#include <sgpemv2/schedulable.hh>
#include <sgpemv2/request.hh>
#include <sgpemv2/schedulable.hh>
#include <sgpemv2/templates/singleton.hh>
namespace sgpem
{
class GlobalPreferences;
class KeyFile;
}
class GlobalPreferences;
class KeyFile;
} // namespace sgpem
namespace sgpem
{
/**
/**
\brief Contains all global application preferences
*/
class SG_DLLEXPORT GlobalPreferences : public Singleton<GlobalPreferences>
{
class SG_DLLEXPORT GlobalPreferences : public Singleton<GlobalPreferences>
{
friend class Singleton<GlobalPreferences>;
public:
typedef std::vector<Glib::ustring> DirVector;
typedef DirVector::iterator DirVectorIt;
@ -57,47 +58,47 @@ namespace sgpem
/**
\return GlobalPreferences configuration filename
*/
Glib::ustring get_config_filename() const;
Glib::ustring get_config_filename () const;
/**
\brief Returns configured Policy directories
\return ::_policy_dirs
*/
DirVector& get_policy_dirs();
DirVector &get_policy_dirs ();
/**
\brief Returns configured Plugin directories
\return ::_plugin_dirs
*/
DirVector& get_plugin_dirs();
DirVector &get_plugin_dirs ();
/**
\brief Returns the simumulation speed
\return _speed
*/
int get_speed();
int get_speed ();
/**
\brief Returns the simumulation speed and return old speed
\return _speed
*/
int set_speed(int new_speed);
int set_speed (int new_speed);
/**
\return A HTML color name or hexadecimal code
*/
const Glib::ustring get_schedulable_color(Schedulable::state st) const;
const Glib::ustring get_schedulable_color (Schedulable::state st) const;
/**
\brief Also works with SubRequest::state
\return A HTML color name or hexadecimal code
*/
const Glib::ustring get_request_color(Request::state st) const;
const Glib::ustring get_request_color (Request::state st) const;
/**
\brief Writes preferences to disk
@ -110,7 +111,7 @@ namespace sgpem
We advice using a key=value text format.
#- Close the configuration file.
*/
void write_configrc();
void write_configrc ();
/**
\brief Load global preferences from disk
@ -119,7 +120,7 @@ namespace sgpem
\throw std::io_error
*/
void load_configrc();
void load_configrc ();
/** \brief Prepare directory to read/write preferences to disk
*
@ -128,15 +129,15 @@ namespace sgpem
* %ApplicationData%/sgpemv2, on *nix systems $HOME/.sgpemv2.
* If it doesn't exist, attempt to create it.
*/
Glib::ustring get_preferences_dir() const;
Glib::ustring get_preferences_dir () const;
private:
GlobalPreferences();
GlobalPreferences(const GlobalPreferences&);
GlobalPreferences& operator=(const GlobalPreferences&);
GlobalPreferences ();
GlobalPreferences (const GlobalPreferences &);
GlobalPreferences &operator= (const GlobalPreferences &);
void key_file_read(KeyFile& kf);
void key_file_write(KeyFile& kf);
void key_file_read (KeyFile &kf);
void key_file_write (KeyFile &kf);
/**
\brief Returns directories to search for plugins
@ -156,7 +157,7 @@ namespace sgpem
-# By a backend::Plugin::on_init() method called when loading an external DSO. This is perfectly normal and permitted.
*/
int _speed;
};
}
};
} // namespace sgpem
#endif

View File

@ -34,7 +34,7 @@
namespace sgpem
{
/** \brief Manages the history of the simulation
/** \brief Manages the history of the simulation
Manages the history of the simulation from the instant 0 to the current time,
i.e. permits to know the state of each schedulable object inside this time interval.
@ -43,18 +43,18 @@ namespace sgpem
In a future iteration it will be possible to revert the entire simulation to a state
present in the history ("undo operation")
*/
class History;
class History;
// Forward declarations:
class HistoryObserver;
class Resource;
class Process;
class Thread;
class Request;
class SubRequest;
// Forward declarations:
class HistoryObserver;
class Resource;
class Process;
class Thread;
class Request;
class SubRequest;
class SG_DLLEXPORT History
{
class SG_DLLEXPORT History
{
public:
// Forward declaration
class LockNotify;
@ -66,14 +66,14 @@ namespace sgpem
typedef int prio_t;
typedef Environment::resource_key_t resource_key_t;
typedef const std::pair<resource_key_t, Resource*> ResourcePair;
typedef const std::pair<resource_key_t, Resource *> ResourcePair;
History();
virtual ~History() = 0;
History ();
virtual ~History () = 0;
virtual size_t get_size() const = 0;
virtual const Environment& get_last_environment() const = 0;
virtual const Environment& get_environment_at(position index) const = 0;
virtual size_t get_size () const = 0;
virtual const Environment &get_last_environment () const = 0;
virtual const Environment &get_environment_at (position index) const = 0;
/**
\brief Removes a Resource from the whole History.
@ -83,7 +83,7 @@ namespace sgpem
\param resource_key The key of the resource to remove.
*/
virtual void remove(resource_key_t resource_key) = 0;
virtual void remove (resource_key_t resource_key) = 0;
/**
\brief Removes a Process from the whole History.
@ -92,7 +92,7 @@ namespace sgpem
\param process The process to remove.
*/
virtual void remove(Process& process) = 0;
virtual void remove (Process &process) = 0;
/**
\brief Removes a thread from the whole History.
@ -101,7 +101,7 @@ namespace sgpem
\param thread The thread to remove.
*/
virtual void remove(Thread& thread) = 0;
virtual void remove (Thread &thread) = 0;
/**
\brief Removes a request from the whole History.
@ -111,7 +111,7 @@ namespace sgpem
\param request The request to remove.
*/
virtual void remove(Request& request) = 0;
virtual void remove (Request &request) = 0;
/**
\brief Removes a subrequest from the whole History.
@ -121,12 +121,12 @@ namespace sgpem
\param subrequest The subrequest to remove.
*/
virtual void remove(SubRequest& subrequest) = 0;
virtual void remove (SubRequest &subrequest) = 0;
/**
\brief Clears the whole history
*/
virtual void clear() = 0;
virtual void clear () = 0;
/**
\brief Add a Resource to the simulation.
@ -137,10 +137,8 @@ namespace sgpem
\param availability The instant from wich the resource is available.
\return a pair with unique key and pointer to the resource created.
*/
virtual ResourcePair add_resource(const Glib::ustring& name,
bool preemptable = false,
size_t places = 1,
size_t availability = 0) = 0;
virtual ResourcePair
add_resource (const Glib::ustring &name, bool preemptable = false, size_t places = 1, size_t availability = 0) = 0;
/**
\brief Change data of an existing resource.
@ -151,11 +149,8 @@ namespace sgpem
\param places Number of places of the resource.
\param availability The instant from wich the resource is available.
*/
virtual void edit_resource(Resource& resource,
const Glib::ustring& name,
bool preemptable = false,
size_t places = 1,
size_t availability = 0) = 0;
virtual void edit_resource (Resource &resource, const Glib::ustring &name, bool preemptable = false,
size_t places = 1, size_t availability = 0) = 0;
/**
\brief Add a Process to the simulation.
@ -166,9 +161,7 @@ namespace sgpem
(scheduler can change it during execution).
\return The newly created process.
*/
virtual Process& add_process(const Glib::ustring& name,
time_t arrival_time,
prio_t base_priority = 0) = 0;
virtual Process &add_process (const Glib::ustring &name, time_t arrival_time, prio_t base_priority = 0) = 0;
/**
\brief Edit an exixting Process in the simulation.
@ -179,10 +172,7 @@ namespace sgpem
\param base_priority Process priority at start up time
(scheduler can change it during execution).
*/
virtual void edit_process(Process& process,
const Glib::ustring& name,
time_t arrival_time,
prio_t base_priority = 0) = 0;
virtual void edit_process (Process &process, const Glib::ustring &name, time_t arrival_time, prio_t base_priority = 0) = 0;
/**
@ -196,10 +186,7 @@ namespace sgpem
(scheduler can change it during execution).
\return The newly created thread.
*/
virtual Thread& add_thread(const Glib::ustring& name,
Process& parent,
time_t cpu_time,
time_t arrival_time = 0,
virtual Thread &add_thread (const Glib::ustring &name, Process &parent, time_t cpu_time, time_t arrival_time = 0,
prio_t base_priority = 0) = 0;
/**
@ -212,10 +199,7 @@ namespace sgpem
\param base_priority Thread priority at start up time
(scheduler can change it during execution).
*/
virtual void edit_thread(Thread& thread,
const Glib::ustring& name,
time_t cpu_time,
time_t arrival_time = 0,
virtual void edit_thread (Thread &thread, const Glib::ustring &name, time_t cpu_time, time_t arrival_time = 0,
prio_t base_priority = 0) = 0;
/**
@ -225,8 +209,7 @@ namespace sgpem
\param instant When the request arrives.
\return The newly created request.
*/
virtual Request& add_request(Thread& owner,
time_t instant) = 0;
virtual Request &add_request (Thread &owner, time_t instant) = 0;
/**
\brief Edit a Request.
@ -234,8 +217,7 @@ namespace sgpem
\param request Reference to editing request.
\param instant When the request arrives.
*/
virtual void edit_request(Request& request,
time_t instant) = 0;
virtual void edit_request (Request &request, time_t instant) = 0;
/**
@ -246,9 +228,7 @@ namespace sgpem
\param duration Total time of request usage.
\return The newly created subrequest.
*/
virtual SubRequest& add_subrequest(Request& request,
resource_key_t resource_key,
time_t duration) = 0;
virtual SubRequest &add_subrequest (Request &request, resource_key_t resource_key, time_t duration) = 0;
/**
\brief Edit an existing SubRequest.
@ -257,17 +237,15 @@ namespace sgpem
\param resource_key Key of the requested resource.
\param duration Total time of request usage.
*/
virtual void edit_subrequest(SubRequest& subrequest,
resource_key_t resource_key,
time_t duration) = 0;
virtual void edit_subrequest (SubRequest &subrequest, resource_key_t resource_key, time_t duration) = 0;
/**
\return actual instant (current time in simulation)
*/
virtual position get_front() const;
virtual position get_front () const;
/**
*/
virtual bool is_sealed() const = 0;
virtual bool is_sealed () const = 0;
/**
\brief Attach a new observer object for this History.
@ -277,27 +255,27 @@ namespace sgpem
want to be notified, e.g. only when resources change but not when requests
do, etc.
*/
virtual void attach(HistoryObserver& observer);
virtual void attach (HistoryObserver &observer);
/**
\brief Detach an observer object for this History.
*/
virtual void detach(const HistoryObserver& observer);
virtual void detach (const HistoryObserver &observer);
/**
\brief Brings History to initial state.
*/
virtual void reset() = 0;
virtual void reset () = 0;
protected:
typedef std::vector<HistoryObserver*> RegisteredObservers;
typedef std::vector<HistoryObserver *> RegisteredObservers;
RegisteredObservers _observers;
/**
\brief Notify all registered ::HistoryObserver that the History has changed.
Calls HistoryObserver.update(this) for each registered observer.
*/
void notify_change();
void notify_change ();
position _front;
@ -310,16 +288,16 @@ namespace sgpem
*
* \return The old value
*/
bool set_notify_enabled(bool enabled = true);
bool set_notify_enabled (bool enabled = true);
/**
\brief Flag indicating notification to observers enabled/disbled.
*/
bool _notify;
}; //~ class History
}; //~ class History
/** \brief Disables notifications to History during the life of this object
/** \brief Disables notifications to History during the life of this object
*
* This class is useful if you've to do a lot of sequential operations on
* History that would reset it / notify its observers. For example, when loading
@ -328,21 +306,21 @@ namespace sgpem
*
* Locks can be taken recursively without fear.
*/
class SG_DLLEXPORT History::LockNotify
{
class SG_DLLEXPORT History::LockNotify
{
public:
LockNotify(History& history);
~LockNotify();
LockNotify (History &history);
~LockNotify ();
private:
History& _h;
History &_h;
bool _was_enabled;
LockNotify(const LockNotify&);
LockNotify& operator=(const LockNotify&);
}; //~ class History::LockNotify
LockNotify (const LockNotify &);
LockNotify &operator= (const LockNotify &);
}; //~ class History::LockNotify
}//~ namespace sgpem
} // namespace sgpem
#endif //~ HISTORY_HH

View File

@ -23,34 +23,31 @@
namespace sgpem
{
class History;
class HistoryObserver;
}
class History;
class HistoryObserver;
} // namespace sgpem
#include <sgpemv2/sgpemv2-visibility.hh>
namespace sgpem
{
/** \brief Specifies that the object wants to be notified
/** \brief Specifies that the object wants to be notified
* whenever backend::History changes
*
* Observers need to register to an History if they want to be
* notified.
* \see History
*/
class SG_DLLEXPORT HistoryObserver
{
class SG_DLLEXPORT HistoryObserver
{
public:
/** \brief Called on an History update
*/
virtual void update(const History& changed_history) = 0;
virtual ~HistoryObserver();
virtual void update (const History &changed_history) = 0;
virtual ~HistoryObserver ();
}
; // class HistoryObserver
}; // class HistoryObserver
}//~ namespace sgpem
} // namespace sgpem
#endif //HISTORY_OBSERVER_H

View File

@ -27,22 +27,21 @@
namespace sgpem
{
/**
/**
* \brief This exception is thrown when the DSO you're trying to load doesn't
* export a valid SGPEMv2 backend::Plugin interface.
*/
class InvalidPluginException : public std::runtime_error
{
class InvalidPluginException : public std::runtime_error
{
public:
/**
* \brief Exception constructor.
*
* \param what A constant string msg indicating the failure reason.
*/
InvalidPluginException(const std::string& what);
}
; //~ class InvalidPluginException
InvalidPluginException (const std::string &what);
}; //~ class InvalidPluginException
} //~ namespace sgpem
} // namespace sgpem
#endif

View File

@ -23,7 +23,7 @@
namespace sgpem
{
class KeyFile;
class KeyFile;
}
#include <sgpemv2/sgpemv2-visibility.hh>
@ -35,7 +35,7 @@ namespace sgpem
namespace sgpem
{
/** \brief Save and retrieve configuration files formatted as key=value rows.
/** \brief Save and retrieve configuration files formatted as key=value rows.
*
* This class handles files to store and retrieve configuration preferences
* in the form of: key=value rows.
@ -48,65 +48,64 @@ namespace sgpem
* Reading files, empty lines and lines starting with # are ignored.
*
*/
class SG_DLLEXPORT KeyFile
{
class SG_DLLEXPORT KeyFile
{
public:
/** \brief Elements iterator type definition. */
typedef std::map<Glib::ustring, Glib::ustring>::const_iterator elements_iterator;
/** \brief Object constructor */
KeyFile();
KeyFile ();
/** \brief Elements iterator (begin of container) initializer. */
elements_iterator elements_begin() const;
elements_iterator elements_begin () const;
/** \brief Elements iterator (end of container) initializer */
elements_iterator elements_end() const;
elements_iterator elements_end () const;
/** \brief Insert a new key/value pair.
*
* \param key The key value to insert.
* \param value The value associated to the key inserted.
*/
void insert_key_value(const Glib::ustring& key, const Glib::ustring& value);
void insert_key_value (const Glib::ustring &key, const Glib::ustring &value);
/** \brief Insert a new key/value pair.
*
* \param key The key value to insert.
* \return A pointer to the value associated to the searched key or 0 if not found.
*/
const Glib::ustring* search_value(const Glib::ustring& key);
const Glib::ustring *search_value (const Glib::ustring &key);
/** \brief Read a file into this object.
*
* \param filename The file to read from.
*/
void file_read(const Glib::ustring& filename);
void file_read (const Glib::ustring &filename);
/** \brief Read a stream into this object.
*
* \param is the stream to read from.
*/
void file_read(std::istream& is);
void file_read (std::istream &is);
/** \brief Write into a file from this object.
*
* \param filename The file to write to.
*/
void file_write(const Glib::ustring& filename);
void file_write (const Glib::ustring &filename);
/** \brief Write into a stream from this object.
*
* \param os the stream to write to.
*/
void file_write(std::ostream& os);
private:
void file_write (std::ostream &os);
private:
std::map<Glib::ustring, Glib::ustring> _elements;
};
}
};
} // namespace sgpem
#endif

View File

@ -31,21 +31,20 @@
namespace sgpem
{
/// \brief An exception signaling a non well-formed script.
/// Represents an exception which may be raised to signal that a script which
/// was supposed to represent a policy is not well-formed.
class MalformedPolicyException;
/// \brief An exception signaling a non well-formed script.
/// Represents an exception which may be raised to signal that a script which
/// was supposed to represent a policy is not well-formed.
class MalformedPolicyException;
class SG_DLLEXPORT MalformedPolicyException : public CPUPolicyException
{
class SG_DLLEXPORT MalformedPolicyException : public CPUPolicyException
{
public:
/// \brief Constructor taking a message as parameter.
///
/// Creates a MalformedPolicyException with an optional detailed message.
/// \param msg a message carrying detailed information.
explicit MalformedPolicyException(const std::string& msg = "");
};
} //~ namespace sgpem
explicit MalformedPolicyException (const std::string &msg = "");
};
} // namespace sgpem
#endif

View File

@ -30,20 +30,18 @@
namespace sgpem
{
/// \brief A link to a loaded DSO object
///
/// When a plugin is found, PluginManager::rescan_dirs() tries to load it by
/// creating an object of this class.
/// The constructor should throw InvalidPluginException if the plugin isn't
/// a valid SGPEMv2 one. This should be handled directly into
/// PluginManager::rescan_dirs().
class Module;
/// \brief A link to a loaded DSO object
///
/// When a plugin is found, PluginManager::rescan_dirs() tries to load it by
/// creating an object of this class.
/// The constructor should throw InvalidPluginException if the plugin isn't
/// a valid SGPEMv2 one. This should be handled directly into
/// PluginManager::rescan_dirs().
class Module;
class SG_DLLEXPORT Module : public Glib::Module
{
class SG_DLLEXPORT Module : public Glib::Module
{
public:
/// \brief Constructor taking an identifier.
///
/// Constructor taking an identifier.
@ -51,50 +49,50 @@ namespace sgpem
/// doesn't export a valid SGPEMv2 backend::Plugin interface.
/// \param identifier A string with the DSO name without any file-extension
/// suffix. This is retrieved by PluginManager::rescan_dirs().
Module(const Glib::ustring& identifier);
Module (const Glib::ustring &identifier);
/// \brief Enables or disables a plugin
///
/// Enables/disables a plugin, calling its on_init()/on_exit() exported
/// functions where appropriate.
/// \param enabled whether to enable or disable the module.
void set_enabled(bool enabled = true);
void set_enabled (bool enabled = true);
/// \brief Returns the name of the module.
///
/// Calls Plugin::get_name()
/// \return the name of the module.
Glib::ustring get_name() const;
Glib::ustring get_name () const;
/// \brief Returns the author of the module.
///
/// Calls Plugin::get_author()
/// \return the author of the module.
Glib::ustring get_author() const;
Glib::ustring get_author () const;
/// \brief Returns a description of the module.
///
/// Calls Plugin::describe()
/// \return a description of the module.
Glib::ustring describe() const;
Glib::ustring describe () const;
/// \brief Returns the version of the module.
///
/// Calls Plugin::get_version()
/// \return the version of the module.
float get_version() const;
float get_version () const;
/// \brief Returns whether the module is enabled or disabled.
///
/// Enables/disables a plugin, calling its on_init()/on_exit() exported
/// functions where appropriate.
/// \param enabled whether to enable or disable the module.
bool get_enabled() const;
bool get_enabled () const;
private:
typedef void (*f_void)(void);
typedef const char* (*f_ustring)(void);
typedef float (*f_float)(void);
typedef void (*f_void) (void);
typedef const char *(*f_ustring) (void);
typedef float (*f_float) (void);
/// True if the plugin is enabled, false otherwise
///
@ -111,10 +109,8 @@ namespace sgpem
f_ustring get_author_ptr;
f_float get_version_ptr;
}
; //~ class Module
}; //~ class Module
} //~ namespace sgpem
} // namespace sgpem
#endif

View File

@ -31,16 +31,16 @@
namespace sgpem
{
class NullPolicyException;
class NullPolicyException;
/** \brief Exception thrown when no policy has been selected and
/** \brief Exception thrown when no policy has been selected and
* an operation that involves scheduling is requested
*/
class SG_DLLEXPORT NullPolicyException : public std::runtime_error
{
class SG_DLLEXPORT NullPolicyException : public std::runtime_error
{
public:
explicit NullPolicyException(const char* msg = "");
};
} //~ namespace sgpem
explicit NullPolicyException (const char *msg = "");
};
} // namespace sgpem
#endif

View File

@ -43,13 +43,13 @@ extern "C"
* Sets up the plugin's initial state and
* performs needed actions before its usage can start.
*/
SG_DLLEXPORT void sgpem__Plugin__on_init();
SG_DLLEXPORT void sgpem__Plugin__on_init ();
SG_DLLEXPORT void sgpem__Plugin__on_exit();
SG_DLLEXPORT const char* sgpem__Plugin__describe();
SG_DLLEXPORT const char* sgpem__Plugin__get_name();
SG_DLLEXPORT const char* sgpem__Plugin__get_author();
SG_DLLEXPORT float sgpem__Plugin__get_version();
SG_DLLEXPORT void sgpem__Plugin__on_exit ();
SG_DLLEXPORT const char *sgpem__Plugin__describe ();
SG_DLLEXPORT const char *sgpem__Plugin__get_name ();
SG_DLLEXPORT const char *sgpem__Plugin__get_author ();
SG_DLLEXPORT float sgpem__Plugin__get_version ();
// To know why SG_DLLEXPORT must go *before* the return
// value, see http://gcc.gnu.org/ml/gcc-help/2005-04/msg00340.html

View File

@ -23,7 +23,7 @@
namespace sgpem
{
class Module;
class Module;
}
#include <sgpemv2/sgpemv2-visibility.hh>
@ -34,25 +34,24 @@ namespace sgpem
namespace sgpem
{
class PluginManager;
class PluginManager;
class SG_DLLEXPORT PluginManager : public Singleton<PluginManager>
{
class SG_DLLEXPORT PluginManager : public Singleton<PluginManager>
{
friend class Singleton<PluginManager>;
public:
std::vector<Module*> get_module_list() const;
void rescan_dirs();
public:
std::vector<Module *> get_module_list () const;
void rescan_dirs ();
private:
PluginManager();
PluginManager ();
std::vector<Module*> _modules;
std::vector<Module *> _modules;
}
; //~ class PluginManager
}; //~ class PluginManager
} //~ namespace sgpem
} // namespace sgpem
#endif

View File

@ -24,32 +24,31 @@
#include <sgpemv2/sgpemv2-visibility.hh>
#include <map>
#include <string>
#include <stdexcept>
#include <string>
#include "glibmm/ustring.h"
namespace sgpem
{
class SG_DLLEXPORT PolicyParametersException : public std::runtime_error
{
class SG_DLLEXPORT PolicyParametersException : public std::runtime_error
{
public:
PolicyParametersException(std::string msg): std::runtime_error(msg) {}
};
PolicyParametersException (std::string msg) : std::runtime_error (msg)
{
}
};
/** \brief Represents all configurable parameters of a single scheduling policy.
/** \brief Represents all configurable parameters of a single scheduling policy.
Represents all configurable parameters of a single scheduling policy. Is is used by the user
interface: it serves to know which parameters the user will be asked for.
Each Policy object owns only one instance of this class.
*/
class SG_DLLEXPORT PolicyParameters
{
class SG_DLLEXPORT PolicyParameters
{
public:
// -------------------------------------------------------------------------
/** \brief This class represents a sigle parameter of type \c T
@ -57,11 +56,10 @@ namespace sgpem
This class is useful only to store informations about each parameter. No checks
on the values entered are done.
*/
template<typename T>
template <typename T>
class SG_DLLEXPORT Parameter
{
public:
/** \brief Constructs the parameter
\param name The name of the parameter. This string will be used to refer to this parameter, thus it MUST
be uniqe (one string identifies \b only ONE parameter)
@ -71,38 +69,37 @@ namespace sgpem
\param required Denotes if this parameter is required by the policy.
\param default_value The initial value of this parameter. (If not specified it's set to 0).
*/
Parameter(Glib::ustring name, const T& value,
const T& lower_bound, const T& upper_bound,
const bool& required, const T& default_value = 0);
Parameter (Glib::ustring name, const T &value, const T &lower_bound, const T &upper_bound, const bool &required,
const T &default_value = 0);
/** \returns The name of the parameter (its UNIQUE key)
*/
Glib::ustring get_name() const;
Glib::ustring get_name () const;
/** \returns The lower bound
*/
T get_lower_bound() const;
T get_lower_bound () const;
/** \returns The upper bound
*/
T get_upper_bound() const;
T get_upper_bound () const;
/** \returns TRUE if this parameter is required
*/
bool is_required() const;
bool is_required () const;
/** \returns Its default value
*/
T get_default() const;
T get_default () const;
/** \returns Its actual value
*/
T get_value() const;
T get_value () const;
/** \brief Changes the value of the parameter.
\warning NO CHECK is done whether the value repects its bounds!!
*/
void set_value(const T&);
void set_value (const T &);
private:
Glib::ustring _name;
@ -132,7 +129,8 @@ namespace sgpem
\param required Denotes if this parameter is required by the policy.
\param default_value The initial value of this parameter. (If not specified it's set to 0).
*/
void register_int(Glib::ustring name, const int& lower_bound, const int& upper_bound, const bool& required, const int& default_value = 0);
void register_int (Glib::ustring name, const int &lower_bound, const int &upper_bound, const bool &required,
const int &default_value = 0);
/**\brief Registers a FLOAT parameter.
@ -146,7 +144,8 @@ namespace sgpem
\param required Denotes if this parameter is required by the policy.
\param default_value The initial value of this parameter. (If not specified it's set to 0.0f).
*/
void register_float(Glib::ustring name, const float& lower_bound, const float& upper_bound, const bool& required, const float& default_value = 0.0f);
void register_float (Glib::ustring name, const float &lower_bound, const float &upper_bound, const bool &required,
const float &default_value = 0.0f);
/**\brief Registers a STRING parameter.
@ -159,12 +158,12 @@ namespace sgpem
\param required Denotes if this parameter is required by the policy.
\param default_value The initial value of this parameter. (If not specified it's set to the empty string).
*/
void register_string(Glib::ustring name, const bool& required, const Glib::ustring& default_value = "");
void register_string (Glib::ustring name, const bool &required, const Glib::ustring &default_value = "");
/**\brief Deletes all registered parameters.
*/
void clear();
void clear ();
//#############################################
@ -174,17 +173,17 @@ namespace sgpem
/** \brief Permits to retrieve all registered INTEGER parameters
\returns a map of INTEGER parameters identfied by their name
*/
std::map<Glib::ustring, Parameter<int> > get_registered_int_parameters() const;
std::map<Glib::ustring, Parameter<int>> get_registered_int_parameters () const;
/** \brief Permits to retrieve all registered FLOAT parameters
\returns a map of FLOAT parameters identfied by their name
*/
std::map<Glib::ustring, Parameter<float> > get_registered_float_parameters() const;
std::map<Glib::ustring, Parameter<float>> get_registered_float_parameters () const;
/** \brief Permits to retrieve all registered STRING parameters
\returns a map of STRING parameters identfied by their name
*/
std::map<Glib::ustring, Parameter<Glib::ustring> > get_registered_string_parameters() const;
std::map<Glib::ustring, Parameter<Glib::ustring>> get_registered_string_parameters () const;
//#############################################
@ -199,7 +198,7 @@ namespace sgpem
exceed the bounds proper to that parameter
\returns FALSE if the parameter named "name" is not found or if "value" exceeds the bounds
*/
bool set_int(Glib::ustring name, const int& value);
bool set_int (Glib::ustring name, const int &value);
/** \brief Sets the value of a registred FLOAT parameter
@ -209,7 +208,7 @@ namespace sgpem
exceed the bounds proper to that parameter
\returns FALSE if the parameter named "name" is not found or if "value" exceeds the bounds
*/
bool set_float(Glib::ustring name, const float& value);
bool set_float (Glib::ustring name, const float &value);
/** \brief Sets the value of a registred STRING parameter
@ -219,7 +218,7 @@ namespace sgpem
exceed the bounds proper to that parameter
\returns FALSE if the parameter named "name" is not found or if "value" exceeds the bounds
*/
bool set_string(Glib::ustring name, const Glib::ustring& value);
bool set_string (Glib::ustring name, const Glib::ustring &value);
//#############################################
@ -230,28 +229,27 @@ namespace sgpem
\returns the INTEGER value of the parameter named \e name
\throws PolicyParametersException if the parameter named \e name has not been registered
*/
int get_int(Glib::ustring name) const;
int get_int (Glib::ustring name) const;
/** \brief Returns the value of an FLOAT parameter
\returns the FLOAT value of the parameter named \e name
\throws PolicyParametersException if the parameter named \e name has not been registered
*/
float get_float(Glib::ustring name) const;
float get_float (Glib::ustring name) const;
/** \brief Returns the value of an STRING parameter
\returns the STRING value of the parameter named \e name
\throws PolicyParametersException if the parameter named \e name has not been registered
*/
Glib::ustring get_string(Glib::ustring name) const;
Glib::ustring get_string (Glib::ustring name) const;
private:
std::map<Glib::ustring, Parameter<int> > int_map;
std::map<Glib::ustring, Parameter<float> > float_map;
std::map<Glib::ustring, Parameter<Glib::ustring> > string_map;
};
std::map<Glib::ustring, Parameter<int>> int_map;
std::map<Glib::ustring, Parameter<float>> float_map;
std::map<Glib::ustring, Parameter<Glib::ustring>> string_map;
};
}//~ namespace sgpem
} // namespace sgpem
#endif

View File

@ -21,29 +21,28 @@
#ifndef PROCESS_HH
#define PROCESS_HH 1
#include <sgpemv2/sgpemv2-visibility.hh>
#include "glibmm/ustring.h"
#include <sgpemv2/sgpemv2-visibility.hh>
#include <vector>
#include <sgpemv2/schedulable.hh>
namespace sgpem
{
class Process;
class Thread;
class SerializeVisitor;
class Process;
class Thread;
class SerializeVisitor;
class SG_DLLEXPORT Process : public virtual Schedulable
{
class SG_DLLEXPORT Process : public virtual Schedulable
{
public:
virtual ~Process();
virtual ~Process ();
virtual std::vector<Thread*> get_threads() = 0;
virtual std::vector<const Thread*> get_threads() const = 0;
virtual void serialize(SerializeVisitor& translator) const = 0;
};
virtual std::vector<Thread *> get_threads () = 0;
virtual std::vector<const Thread *> get_threads () const = 0;
virtual void serialize (SerializeVisitor &translator) const = 0;
};
}//~namespace sgpem
} // namespace sgpem
#endif //~ PROCESS_HH

View File

@ -23,10 +23,10 @@
#include "thread_statistics.hh"
#include <sgpemv2/sgpemv2-visibility.hh>
#include <sgpemv2/schedulable_statistics.hh>
#include <sgpemv2/thread_statistics.hh>
#include <sgpemv2/process.hh>
#include <sgpemv2/schedulable_statistics.hh>
#include <sgpemv2/sgpemv2-visibility.hh>
#include <sgpemv2/thread_statistics.hh>
#include <glibmm/ustring.h>
@ -34,19 +34,19 @@
namespace sgpem
{
class ProcessStatistics : public SchedulableStatistics
{
class ProcessStatistics : public SchedulableStatistics
{
public:
~ProcessStatistics();
~ProcessStatistics ();
virtual float get_average_response_time() const = 0;
virtual const Process* get_core() const = 0;
virtual float get_average_response_time () const = 0;
virtual const Process *get_core () const = 0;
virtual std::vector<const ThreadStatistics*> get_threads_statistics() const = 0;
virtual std::vector<const ThreadStatistics *> get_threads_statistics () const = 0;
protected:
ProcessStatistics();
};
}
ProcessStatistics ();
};
} // namespace sgpem
#endif

View File

@ -28,10 +28,10 @@
namespace sgpem
{
class ReadyQueue;
class Thread;
class SG_DLLEXPORT ReadyQueue
{
class ReadyQueue;
class Thread;
class SG_DLLEXPORT ReadyQueue
{
public:
typedef unsigned int position;
typedef unsigned int size_t;
@ -43,14 +43,14 @@ namespace sgpem
* \param a first object position
* \param b second object position
*/
void swap(position a, position b);
void swap (position a, position b);
/**
* \brief Return the size of the queue.
*
* \return _scheds.size()
*/
size_t size() const;
size_t size () const;
/**
* \brief Returns an item contained in the vector.
@ -60,7 +60,7 @@ namespace sgpem
* \return The item at positon \a index.
* \throw std::out_of_range if position is < 1 or > size()-1.
*/
Thread& get_item_at(position index);
Thread &get_item_at (position index);
/**
@ -71,38 +71,37 @@ namespace sgpem
* \return A constant reference to the item at positon \a index.
* \throw std::out_of_range if position is < 1 or > size()-1
*/
const Thread& get_item_at(position index) const;
const Thread &get_item_at (position index) const;
/**
* \brief Add a new ::Thread at the end of the queue.
*
* \param schedulable A reference to the appending thread.
*/
void append(Thread& schedulable);
void append (Thread &schedulable);
/**
* \brief Bubble element x to the front of the queue
*/
void bubble_to_front(position x);
void bubble_to_front (position x);
/**
* \brief Remove the first item from the threads vector.
*/
void erase_first();
void erase_first ();
private:
/**
* \brief Threads container definition.
*/
typedef std::vector<Thread*> Threads;
typedef std::vector<Thread *> Threads;
/**
* \brief Threads container member.
*/
Threads _scheds;
};
};
}
} // namespace sgpem
#endif

View File

@ -23,19 +23,19 @@
namespace sgpem
{
class Request;
class SerializeVisitor;
class SubRequest;
class Thread;
}
class Request;
class SerializeVisitor;
class SubRequest;
class Thread;
} // namespace sgpem
#include <sgpemv2/sgpemv2-visibility.hh>
#include <vector>
namespace sgpem
{
class SG_DLLEXPORT Request
{
class SG_DLLEXPORT Request
{
public:
enum state
{
@ -46,21 +46,20 @@ namespace sgpem
state_allocable = 1 << 4
};
virtual ~Request();
virtual ~Request ();
virtual Thread& get_thread() = 0;
virtual Thread &get_thread () = 0;
virtual bool operator==(const Request& op2) const = 0;
virtual bool operator== (const Request &op2) const = 0;
virtual std::vector<SubRequest*> get_subrequests() = 0;
virtual unsigned int get_instant() const = 0;
virtual std::vector<SubRequest *> get_subrequests () = 0;
virtual unsigned int get_instant () const = 0;
virtual state get_state() const = 0;
virtual state get_state () const = 0;
virtual void serialize(SerializeVisitor& translator) const = 0;
};
virtual void serialize (SerializeVisitor &translator) const = 0;
};
}
} // namespace sgpem
#endif

View File

@ -21,29 +21,29 @@
#ifndef RESOURCE_HH
#define RESOURCE_HH 1
#include <sgpemv2/sgpemv2-visibility.hh>
#include "glibmm/ustring.h"
#include <sgpemv2/sgpemv2-visibility.hh>
namespace sgpem
{
class Resource;
class SerializeVisitor;
class Resource;
class SerializeVisitor;
/** \brief An abstract class representing a resource
/** \brief An abstract class representing a resource
*
* A resource in a real operating system could be a printer,
* a socket, a chunk of memory, or a simple file.
*/
class SG_DLLEXPORT Resource
{
class SG_DLLEXPORT Resource
{
public:
virtual ~Resource();
virtual ~Resource ();
/** \brief See if two different states point to the same resource */
virtual bool operator==(const Resource& op2) const = 0;
virtual bool operator== (const Resource &op2) const = 0;
/** \brief Returns the resource name */
virtual Glib::ustring get_name() const = 0;
virtual Glib::ustring get_name () const = 0;
/** \brief Return the number of places this resource has available
* before becoming unavailable
@ -51,13 +51,12 @@ namespace sgpem
* E.g. if a resource has two places, it can fulfill only two
* ::SubRequests at each instant
*/
virtual unsigned int get_places() const = 0;
virtual unsigned int get_places () const = 0;
/** \brief Used to serialize the informations of this entity */
virtual void serialize(SerializeVisitor& translator) const = 0;
};
virtual void serialize (SerializeVisitor &translator) const = 0;
};
}
} // namespace sgpem
#endif

View File

@ -23,48 +23,48 @@
namespace sgpem
{
class ResourcePolicyManager;
class ResourcePolicy;
class History;
}
class ResourcePolicyManager;
class ResourcePolicy;
class History;
} // namespace sgpem
#include <sgpemv2/sgpemv2-visibility.hh>
#include <vector>
#include <map>
#include <stdexcept>
#include <vector>
#include <sgpemv2/templates/singleton.hh>
namespace sgpem
{
class ResourcePoliciesGatekeeper;
class ResourcePoliciesGatekeeper;
/** \brief FIXME document me
/** \brief FIXME document me
*/
class SG_DLLEXPORT ResourcePoliciesGatekeeper : public Singleton<ResourcePoliciesGatekeeper>
{
class SG_DLLEXPORT ResourcePoliciesGatekeeper : public Singleton<ResourcePoliciesGatekeeper>
{
friend class Singleton<ResourcePoliciesGatekeeper>;
public:
typedef ResourcePolicyManager Manager;
typedef std::vector<Manager*> Managers;
typedef std::vector<Manager *> Managers;
/**
* \brief Returns registered resources policy managers.
*
* \return Registered resources policy managers.
*/
const Managers& get_registered() const;
const Managers &get_registered () const;
/**
* \brief Register a new resources policy manager.
* A no-op if a manager of the same type already exists.
*/
void register_manager(ResourcePolicyManager* manager);
void register_manager (ResourcePolicyManager *manager);
/**
* \brief Unregister a given manager. If not present, it is a no-op.
@ -74,7 +74,7 @@ namespace sgpem
*
* \param manager The resource policy manager to remove.
*/
void unregister_manager(ResourcePolicyManager* manager);
void unregister_manager (ResourcePolicyManager *manager);
/**
* \brief Returns the currently active policy.
@ -83,29 +83,29 @@ namespace sgpem
*
* \return The current policy.
*/
ResourcePolicy& get_current_policy(History* history);
ResourcePolicy &get_current_policy (History *history);
/**
\brief Given a policy, sets it as the history current one.
Also deactivates the old policy if present, and then activates
the new policy before use. If old_policy == new_policy, it's a no-op.
*/
void activate_policy(History* history, ResourcePolicy* policy);
void activate_policy (History *history, ResourcePolicy *policy);
private:
/**
\brief Private constructor.
*/
ResourcePoliciesGatekeeper(); //private constructor.
ResourcePoliciesGatekeeper (); //private constructor.
/**
\brief Private copy constructor.
*/
ResourcePoliciesGatekeeper(const ResourcePoliciesGatekeeper&);
ResourcePoliciesGatekeeper (const ResourcePoliciesGatekeeper &);
/**
\brief Private assignment operator.
*/
ResourcePoliciesGatekeeper& operator=(const ResourcePoliciesGatekeeper&);
ResourcePoliciesGatekeeper &operator= (const ResourcePoliciesGatekeeper &);
void deactivate_policies(const ResourcePolicyManager& manager);
void deactivate_policies (const ResourcePolicyManager &manager);
/**
\brief Container of registered managers.
*/
@ -113,10 +113,9 @@ namespace sgpem
/**
\brief Container of active policies.
*/
std::map<History*, ResourcePolicy*> _active_policies;
};
std::map<History *, ResourcePolicy *> _active_policies;
};
}//~ namespace sgpem
} // namespace sgpem
#endif //RESOURCE_POLICIES_GATEKEEPER_HH

View File

@ -23,41 +23,39 @@
namespace sgpem
{
class ResourcePolicy;
class ResourcePolicy;
}
#include "gettext.h"
#include <sgpemv2/sgpemv2-visibility.hh>
#include <sgpemv2/policy_parameters.hh>
#include <sgpemv2/user_interrupt_exception.hh>
#include <sgpemv2/environment.hh>
#include <sgpemv2/policy_parameters.hh>
#include <sgpemv2/sgpemv2-visibility.hh>
#include <sgpemv2/sub_request.hh>
#include <sgpemv2/user_interrupt_exception.hh>
#include <glibmm/ustring.h>
namespace sgpem
{
/// \brief A resource allocation policy.
///
/// A resource allocation policy manages the queues of requests.
/// Its purpose is to decide which threads may use the available
/// resources first.
class SG_DLLEXPORT ResourcePolicy
{
/// \brief A resource allocation policy.
///
/// A resource allocation policy manages the queues of requests.
/// Its purpose is to decide which threads may use the available
/// resources first.
class SG_DLLEXPORT ResourcePolicy
{
public:
/// \brief Standard virtual destructor.
///
/// Standard virtual destructor.
virtual ~ResourcePolicy();
virtual ~ResourcePolicy ();
/// \brief Initializes the inner components of the policy.
///
/// Because it's a pure virtual method, must be re-implemented
/// in concrete derived classes.
virtual void configure() = 0;
virtual void configure () = 0;
/// \brief Sorts the subrequest queue.
///
@ -67,7 +65,7 @@ namespace sgpem
/// \param environment the environment on which the policy applies.
/// \param queue the queue where a subrequest has just been added.
/// \param sr the subrequest which has just been added.
virtual void enforce(Environment& environment, Environment::SubRequestQueue& queue, SubRequest& sr) = 0;
virtual void enforce (Environment &environment, Environment::SubRequestQueue &queue, SubRequest &sr) = 0;
/// \brief Returns a description of the policy.
///
@ -75,7 +73,7 @@ namespace sgpem
/// in concrete derived classes.
/// Returns a description of the policy.
/// \return a description of the policy.
virtual Glib::ustring get_description() const = 0;
virtual Glib::ustring get_description () const = 0;
/// \brief Returns the name of the policy.
///
@ -83,32 +81,32 @@ namespace sgpem
/// in concrete derived classes.
/// Returns the name of the policy.
/// \return the name of the policy.
virtual Glib::ustring get_name() const = 0;
virtual Glib::ustring get_name () const = 0;
/// \brief Activates the policy.
///
/// Because it's a pure virtual method, must be re-implemented
/// in concrete derived classes.
virtual void activate() = 0;
virtual void activate () = 0;
/// \brief Deactivates the policy.
///
/// Because it's a pure virtual method, must be re-implemented
/// in concrete derived classes.
virtual void deactivate() = 0;
virtual void deactivate () = 0;
/// \brief Returns the parameters used to customize the policy.
///
/// Returns the parameters used to customize the policy.
/// The user may modify them directly.
/// \return the parameters used to customize the policy.
PolicyParameters& get_parameters();
PolicyParameters &get_parameters ();
protected:
PolicyParameters _parameters;
};
};
}//~ namespace sgpem
} // namespace sgpem
#endif

View File

@ -23,7 +23,7 @@
namespace sgpem
{
class ResourcePolicy;
class ResourcePolicy;
}
#include <sgpemv2/sgpemv2-visibility.hh>
@ -33,28 +33,27 @@ namespace sgpem
namespace sgpem
{
class ResourcePolicyManager;
class ResourcePolicyManager;
/**
/**
ResourcePolicyManager is the Abstract Factory for \ref ResourcePolicy objects.
*/
class SG_DLLEXPORT ResourcePolicyManager
{
class SG_DLLEXPORT ResourcePolicyManager
{
public:
typedef ResourcePolicy Policy;
typedef std::vector<Policy*> Policies;
typedef std::vector<Policy *> Policies;
/** \brief ResourcePolicyManager constructor
*
* Registers itself to the ResourcePoliciesGatekeeper singleton.
*/
ResourcePolicyManager();
ResourcePolicyManager ();
virtual ~ResourcePolicyManager();
virtual ~ResourcePolicyManager ();
virtual const Policies& get_avail_policies() const = 0;
};
virtual const Policies &get_avail_policies () const = 0;
};
} //~ namespace sgpem
} // namespace sgpem
#endif // ~ RESOURCE_POLICY_MANAGER_HH

View File

@ -27,22 +27,21 @@
namespace sgpem
{
/// \brief Represents a schedulable entity within the simulated system.
///
/// Represents a schedulable entity within the simulated system.
/// Real world schedulable entities are, for example: batch jobs, processes
/// threads, fibers.
/// This class factors out some of their features.
///
/// This is an abstract class. Known subclasses are ::Process, and ::Thread
class Schedulable;
/// \brief Represents a schedulable entity within the simulated system.
///
/// Represents a schedulable entity within the simulated system.
/// Real world schedulable entities are, for example: batch jobs, processes
/// threads, fibers.
/// This class factors out some of their features.
///
/// This is an abstract class. Known subclasses are ::Process, and ::Thread
class Schedulable;
class SerializeVisitor;
class SerializeVisitor;
class SG_DLLEXPORT Schedulable
{
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
@ -61,7 +60,7 @@ namespace sgpem
/// \brief Virtual destructor
///
/// Abstract virtual destructor
virtual ~Schedulable() = 0;
virtual ~Schedulable () = 0;
/// \brief Redefined operator equals (static equality).
///
@ -73,14 +72,14 @@ namespace sgpem
/// time and elapsed time do count.
/// \param op2 the Schedulable to compare this with.
/// \return true if the Schedulable equal, false otherwise.
virtual bool operator==(const Schedulable& op2) const = 0;
virtual bool operator== (const Schedulable &op2) const = 0;
/// \brief Returns the name of the Schedulable.
///
/// Returns the name of the Schedulable.
/// \return the name of the Schedulable.
virtual Glib::ustring get_name() const = 0;
virtual Glib::ustring get_name () const = 0;
/// \brief Returns the arrival time of the Schedulable.
///
@ -91,7 +90,7 @@ namespace sgpem
///
/// The arrival time is a static (respect to the simulation) property.
/// \return the arrival time of the Schedulable.
virtual unsigned int get_arrival_time() const = 0;
virtual unsigned int get_arrival_time () const = 0;
/// \brief Returns the elapsed time of the Schedulable.
///
@ -101,7 +100,7 @@ namespace sgpem
///
/// The elapsed time is a dynamic (respect to the simulation) property.
/// \return the elapsed time of the Schedulable.
virtual unsigned int get_elapsed_time() const = 0;
virtual unsigned int get_elapsed_time () const = 0;
/// \brief Returns the remaining time of the Schedulable.
///
@ -114,7 +113,7 @@ namespace sgpem
///
/// The remaining time is a dynamic (respect to the simulation) property.
/// \return the remaining time of the Schedulable.
virtual unsigned int get_remaining_time() const;
virtual unsigned int get_remaining_time () const;
/// \brief Returns the last aquisition instant of the Schedulable.
///
@ -127,7 +126,7 @@ namespace sgpem
///
/// The last aquisition instant is a dynamic (respect to the simulation) property.
/// \return the last aquisition instant of the Schedulable.
virtual int get_last_acquisition() const = 0;
virtual int get_last_acquisition () const = 0;
/// \brief Returns the last release instant of the Schedulable.
///
@ -140,7 +139,7 @@ namespace sgpem
///
/// The last release instant is a dynamic (respect to the simulation) property.
/// \return the last release instant of the Schedulable.
virtual int get_last_release() const = 0;
virtual int get_last_release () const = 0;
/// \brief Returns the base priority of the Schedulable.
///
@ -154,7 +153,7 @@ namespace sgpem
///
/// The base priority is a static (respect to the simulation) property.
/// \return the base priority of the Schedulable.
virtual int get_base_priority() const = 0;
virtual int get_base_priority () const = 0;
/// \brief Returns the total required CPU time of the Schedulable.
///
@ -167,7 +166,7 @@ namespace sgpem
///
/// The total required CPU time is a static (respect to the simulation) property.
/// \return the total required CPU time of the Schedulable.
virtual unsigned int get_total_cpu_time() const = 0;
virtual unsigned int get_total_cpu_time () const = 0;
/// \brief Returns the current priority of the Schedulable.
///
@ -181,7 +180,7 @@ namespace sgpem
///
/// The current priority is a dynamic (respect to the simulation) property.
/// \return the dynamic priority of the Schedulable.
virtual int get_current_priority() const = 0;
virtual int get_current_priority () const = 0;
/// \brief Returns the current priority push of the Schedulable.
///
@ -195,7 +194,7 @@ namespace sgpem
///
/// The priority push is a dynamic (respect to the simulation) property.
/// \return the current priority push of the Schedulable.
virtual int get_priority_push() const;
virtual int get_priority_push () const;
/// \brief Sets the priority push of the Schedulable, returning the old one.
///
@ -210,7 +209,7 @@ namespace sgpem
/// The priority push is a dynamic (respect to the simulation) property.
/// \param new_value the new push to be set.
/// \return the old priority push of the Schedulable.
virtual int set_priority_push(int new_value = 0) = 0;
virtual int set_priority_push (int new_value = 0) = 0;
/// \brief Returns the current state of the Schedulable.
///
@ -221,13 +220,13 @@ namespace sgpem
///
/// The current state is a dynamic (respect to the simulation) property.
/// \return the current state of the Schedulable.
virtual state get_state() const = 0;
virtual state get_state () const = 0;
/// \brief Serializes this entity using a visitor pattern.
///
/// \param translator the visitor used to serialize this entity.
virtual void serialize(SerializeVisitor& translator) const = 0;
};
}
virtual void serialize (SerializeVisitor &translator) const = 0;
};
} // namespace sgpem
#endif

View File

@ -29,70 +29,69 @@
namespace sgpem
{
/** \brief Represents the statistics of a Schedulable
/** \brief Represents the statistics of a Schedulable
Represents the statistics of a Schedulable. This class is created by "Statistics" class
and presents only "getters" methods which execute no calculations: they only return the
internal results calulated at construction time. To retrieve these results the whole History
(until the instant specified through Statistics::calculateStatisticsAt(int)) is scanned.
*/
class SchedulableStatistics
{
class SchedulableStatistics
{
public:
virtual ~SchedulableStatistics();
virtual ~SchedulableStatistics ();
/** \brief Returns the total execution time
\returns the number of instants during which the state of the schedulable was "running"
*/
virtual int get_execution_time() const =0;
virtual int get_execution_time () const = 0;
/** \brief Returns the percentage of the execution
\returns the number of instants during which the state of the schedulable was "running"
divided by the total running time of the schedulable
*/
virtual int get_execution_progress() const =0;
virtual int get_execution_progress () const = 0;
/** \brief Returns the total incativity time
\returns the number of instants during which the state of the schedulable was "ready" or "blocked"
*/
virtual int get_total_inactivity() const =0;
virtual int get_total_inactivity () const = 0;
/** \brief Returns the response time of the schedulable
\returns the number of instants during which the state of the schedulable was "ready" or "blocked"
before the first execution instant
*/
virtual int get_response_time() const =0;
virtual int get_response_time () const = 0;
/** \brief Returns the turn-around time of the schedulable
\returns the number of instants during which the state of the schedulable was "ready" or "blocked"
or "running"
*/
virtual int get_turn_around() const =0;
virtual int get_turn_around () const = 0;
/** \brief Returns the percentage of the execution efficiency
\returns The percentage of the efficiency. This value is calucated this way: turn_around/execution_time
*/
virtual int get_efficiency() const =0;
virtual int get_efficiency () const = 0;
/** \brief Returns the resources usage time of the schedulable
\returns the number of instants during which the the schedulable used a resource. If the schedulable
used more than one resource a time then this value is increased accordingly.
*/
virtual int get_resource_usage_time() const =0;
virtual int get_resource_usage_time () const = 0;
/** \brief Returns the number of instants this schedulable was waiting for a resource to be allocable
\returns the number of instants during which the state of the schedulable was "blocked"
*/
virtual int get_resource_waitings_time() const =0;
virtual int get_resource_waitings_time () const = 0;
/** \brief Returns the Schedulable object these statistics refer to
\returns Returns a const pointer to the Schedulable object these statistics refer to
*/
virtual const Schedulable* get_core() const =0;
virtual const Schedulable *get_core () const = 0;
protected:
SchedulableStatistics();
SchedulableStatistics ();
int _execution_time;
int _execution_progress;
@ -102,7 +101,7 @@ namespace sgpem
int _efficiency;
int _resource_usage_time;
int _resource_waitings_time;
};
}
};
} // namespace sgpem
#endif

View File

@ -22,18 +22,18 @@
#define SCHEDULER_HH 1
namespace sgpem
{
class Scheduler;
class CPUPolicy;
}
class Scheduler;
class CPUPolicy;
} // namespace sgpem
#include <sgpemv2/sgpemv2-visibility.hh>
#include <sgpemv2/history.hh>
#include <sgpemv2/cpu_policy.hh>
#include <sgpemv2/resource_policy.hh>
#include <sgpemv2/ready_queue.hh>
#include <sgpemv2/user_interrupt_exception.hh>
#include <sgpemv2/history.hh>
#include <sgpemv2/malformed_policy_exception.hh>
#include <sgpemv2/ready_queue.hh>
#include <sgpemv2/resource_policy.hh>
#include <sgpemv2/user_interrupt_exception.hh>
// Do not include full template definition here
#include <sgpemv2/templates/singleton.hh>
@ -42,10 +42,10 @@ namespace sgpem
namespace sgpem
{
class Scheduler;
class Scheduler;
/** \brief Manages the DynamicSchedulable 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
@ -56,9 +56,10 @@ namespace sgpem
*/
class SG_DLLEXPORT Scheduler : public Singleton<Scheduler>
{
class SG_DLLEXPORT Scheduler : public Singleton<Scheduler>
{
friend class Singleton<Scheduler>;
public:
/**
Generates a new ReadyQueue representing the status of the processes
@ -68,7 +69,7 @@ namespace sgpem
\return false If the simulation has ended, true otherwise
*/
bool step_forward(History& history, CPUPolicy& cpu_policy, ResourcePolicy& resource_policy);
bool step_forward (History &history, CPUPolicy &cpu_policy, ResourcePolicy &resource_policy);
/**
\brief Returns the policy that will be used to generate the simulation at the next instant.
@ -77,7 +78,7 @@ namespace sgpem
by step_forward(). Else, a nullptr pointer will be returned.
\return A pointer to the active policy, or nullptr if not inside step_forward()
*/
CPUPolicy* get_policy();
CPUPolicy *get_policy ();
/**
\brief Returns a pointer to the queue containing all the ready
@ -87,17 +88,17 @@ namespace sgpem
by step_forward(). Else, a nullptr pointer will be returned.
\return A pointer to the queue, or nullptr if not inside step_forward()
*/
ReadyQueue* get_ready_queue();
ReadyQueue *get_ready_queue ();
private:
Scheduler(); //private constructor.
Scheduler (); //private constructor.
ReadyQueue* _ready_queue;
CPUPolicy* _policy;
ReadyQueue *_ready_queue;
CPUPolicy *_policy;
Glib::Mutex _step_mutex;
};
};
}//~ namespace sgpem
} // namespace sgpem
#endif //SCHEDULER_HH

View File

@ -23,14 +23,14 @@
namespace sgpem
{
class History;
class Environment;
class Resource;
class Process;
class Thread;
class Request;
class SubRequest;
}
class History;
class Environment;
class Resource;
class Process;
class Thread;
class Request;
class SubRequest;
} // namespace sgpem
#include <sgpemv2/sgpemv2-visibility.hh>
@ -40,63 +40,62 @@ namespace sgpem
namespace sgpem
{
class SerializeVisitor;
class SerializeVisitor;
/**
/**
\brief Interface class to serialize data
This class is a virtual class and each method must be reimplemented
in derived classes to have effective serialization.
*/
class SG_DLLEXPORT SerializeVisitor
{
class SG_DLLEXPORT SerializeVisitor
{
public:
virtual ~SerializeVisitor() = 0;
virtual ~SerializeVisitor () = 0;
/**
\brief Add output to the serializer taking data from history
*/
virtual void from_history(const History& obj) = 0;
virtual void from_history (const History &obj) = 0;
/**
\brief Add output to the serializer taking data from environment
*/
virtual void from_environment(const Environment& obj) = 0;
virtual void from_environment (const Environment &obj) = 0;
/**
\brief Add output to the serializer taking data from resource
BUG: a resource must be saved with her own associated key.
*/
virtual void from_resource(const Resource& obj) = 0;
virtual void from_resource (const Resource &obj) = 0;
/**
\brief Add output to the serializer taking data from resource and key
BUG FIXED: This save a resource with her own associated key.
*/
virtual void from_resource(const Resource& obj, const Glib::ustring& key) = 0;
virtual void from_resource (const Resource &obj, const Glib::ustring &key) = 0;
/**
\brief Add output to the serializer taking data from process
*/
virtual void from_process(const Process& obj) = 0;
virtual void from_process (const Process &obj) = 0;
/**
\brief Add output to the serializer taking data from thread
*/
virtual void from_thread(const Thread& obj) = 0;
virtual void from_thread (const Thread &obj) = 0;
/**
\brief Add output to the serializer taking data from request
*/
virtual void from_request(const Request& obj) = 0;
virtual void from_request (const Request &obj) = 0;
/**
\brief Add output to the serializer taking data from subrequest
*/
virtual void from_subrequest(const SubRequest& obj) = 0;
};
}
virtual void from_subrequest (const SubRequest &obj) = 0;
};
} // namespace sgpem
#endif

Some files were not shown because too many files have changed in this diff Show More