- Added the Schedulable interface

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

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

View file

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