sgpemv2/src/backend/dynamic_schedulable.cc
tchernobog fa06e2f4f1 - Add operator== methods to dynamic schedulables, and in their interfaces too
- Write class ReadyQueue


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@688 3ecf2c5c-341e-0410-92b4-d18e462d057c
2006-07-02 12:44:05 +00:00

165 lines
3.2 KiB
C++

// src/backend/dynamic_schedulable.cc - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
// This file is part of SGPEMv2.
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SGPEMv2 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "dynamic_schedulable.hh"
#include "smartp.tcc"
#include <cassert>
using namespace sgpem;
using namespace std;
DynamicSchedulable::DynamicSchedulable(StaticSchedulable& obj) :
_time_left(obj.get_total_cpu_time()), _ref(&obj), _last_acquisition(-1),
_last_release(-1), _priority_push(0), _last(-1),
_my_state(state_future)
{}
bool
DynamicSchedulable::operator==(const Schedulable& op2) const
{
assert(dynamic_cast<const DynamicSchedulable*>(&op2) != NULL);
return _ref == dynamic_cast<const DynamicSchedulable&>(op2)._ref;
}
Glib::ustring
DynamicSchedulable::get_name() const
{
return _ref->get_name();
}
unsigned int
DynamicSchedulable::get_arrival_time() const
{
return _ref->get_arrival_time();
}
int
DynamicSchedulable::get_base_priority() const
{
return _ref->get_priority();
}
unsigned int
DynamicSchedulable::get_total_cpu_time() const
{
return _ref->get_total_cpu_time();
}
int
DynamicSchedulable::get_priority_push() const
{
return _priority_push;
}
void
DynamicSchedulable::set_priority_push(int new_value)
{
_priority_push = new_value;
}
int
DynamicSchedulable::get_current_priority() const
{
return get_base_priority() + get_priority_push();
}
unsigned int
DynamicSchedulable::get_remaining_time() const
{
return _time_left;
}
void
DynamicSchedulable::decrease_remaining_time()
{
--_time_left;
}
int
DynamicSchedulable::get_last_acquisition() const
{
return _last_acquisition;
}
void
DynamicSchedulable::set_last_acquisition(int instant)
{
_last_acquisition = instant;
}
int
DynamicSchedulable::get_last_release() const
{
return _last_release;
}
void
DynamicSchedulable::set_last_release(int instant)
{
_last_release = instant;
}
int
DynamicSchedulable::get_cpu_time_left() const
{
return _time_left;
}
void
DynamicSchedulable::give_cpu_time(const int& time)
{
_time_left -= time;
if (_time_left < 0)
_time_left = 0;
}
void
DynamicSchedulable::set_last_scheduled(const int& time)
{
_last = time;
}
int
DynamicSchedulable::get_last_scheduled() const
{
return _last;
}
DynamicSchedulable::state
DynamicSchedulable::get_state() const
{
return _my_state;
}
void
DynamicSchedulable::set_state(state s)
{
_my_state = s;
}
StaticSchedulable*
DynamicSchedulable::get_schedulable() const
{
//HACK This is an enormous hack!!!
return (StaticSchedulable*)&(*_ref);
}