- fixed a number of bugs

- added dummy_policy written in C++
- the interpreter is now finished (hopefully)


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@366 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
fpaparel 2006-02-21 11:09:55 +00:00
parent ea70e2f092
commit 4482b98df7
17 changed files with 230 additions and 106 deletions

View file

@ -75,29 +75,46 @@ Scheduler::get_policy()
void
Scheduler::step_forward()
{
History& h = History::get_instance();
//******************
//check for arrivals and prepare the queue
//******************
smart_ptr<const SchedulableList> initial = h.get_simulation_status_at(h.get_current_time());
smart_ptr<SchedulableList> initial = h.get_simulation_status_at(h.get_current_time());
if (!initial)
{
cout << _("\nNo initial state inserted!!\n");
return;
}
_ready_queue.clear();
//adds running schedulable
smart_ptr<const SchedulableStatus> running_ptr = h.get_scheduled_at(h.get_current_time());
smart_ptr<SchedulableStatus> 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)
_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_ready
if (initial->get_item_at(i)->get_state() == SchedulableStatus::state_future
&& (int)initial->get_item_at(i)->get_schedulable()->get_arrival_time() == h.get_current_time())
{
_ready_queue.add_at_bottom(*initial->get_item_at(i));
//pops the running schedulable only if the policy is not preemptive
//cout << "\nnuovo running: " << initial->get_item_at(i)->get_schedulable()->get_name();
//restore the old running schedulable
if (_policy->is_pre_emptive() == false && running_ptr)
_ready_queue.remove(0);
//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);
// Sort the queue
_policy->sort_queue(event_schedulable_arrival);
@ -106,22 +123,27 @@ Scheduler::step_forward()
_ready_queue.add_at_top(*running_ptr);
}
//****************
// Check for termination
//****************
if (running_ptr && running_ptr->get_cpu_time_left() == 0)
{
//there was a running schedulable and it's terminated. Remove it!
//there is a running schedulable and it's terminated. Append at the bottom with the state TERMINATED
for(uint i=0; i < _ready_queue.size(); i++)
if (*_ready_queue.get_item_at(i) == *running_ptr)
{
_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);
break;
}
//cout << "\nTERMINATO!!";
running_ptr = NULL;
//IF _ready_queue.size() == 0 sort_queue(...) is called but has no effect!!
_policy->sort_queue(event_schedulable_termination);
//IF _ready_queue.size() == 0 sort_queue(...) is called but has no effect!!
_policy->sort_queue(event_schedulable_termination);
}
//*****************
@ -134,30 +156,31 @@ Scheduler::step_forward()
// Create the final list of schedulable
//******************
SchedulableList final = _ready_queue;
if (final.size() != 0)
//the firs element IS the running one (if != *running_ptr then there is a CONTEXT SWICH)
final.get_item_at(0)->set_state(SchedulableStatus::state_running);
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))
{
//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)->give_cpu_time(1);
}
//all the others are ready
for (uint i = 1; i < final.size(); i++)
if (final.get_item_at(i)->get_state() == SchedulableStatus::state_running)
final.get_item_at(i)->set_state(SchedulableStatus::state_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);
//append blocked, future, terminated and the old running schedulables
//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
|| (initial->get_item_at(i)->get_state() == SchedulableStatus::state_ready
&& (int)initial->get_item_at(i)->get_schedulable()->get_arrival_time() != h.get_current_time()) )
final.add_at_bottom(*initial->get_item_at(i));
h.enqueue_slice(final);
|| initial->get_item_at(i)->get_state() == SchedulableStatus::state_terminated)
_ready_queue.add_at_bottom(*initial->get_item_at(i));
cout << "\n";
/* for (uint i = 0; i < _ready_queue.size(); i++)
cout << " " << _ready_queue.get_item_at(i)->get_schedulable()->get_name()
<<"_" << _ready_queue.get_item_at(i)->get_state();
*/
h.enqueue_slice(_ready_queue);
}