- Pretty-indenting code
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@674 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
7aecc910ba
commit
6b27a8461b
94 changed files with 3073 additions and 3066 deletions
|
@ -37,29 +37,29 @@ template class SG_DLLEXPORT Singleton<Scheduler>;
|
|||
|
||||
//private constructor. The parameter is discarded
|
||||
Scheduler::Scheduler()
|
||||
: _policy_manager(PolicyManager::get_registered_manager())
|
||||
: _policy_manager(PolicyManager::get_registered_manager())
|
||||
{
|
||||
_policy_manager.init();
|
||||
}
|
||||
|
||||
SchedulableQueue*
|
||||
SchedulableQueue*
|
||||
Scheduler::get_ready_queue()
|
||||
{
|
||||
// FIXME return the correct queue accordingly to the value returned by Policy::wants()
|
||||
return &_ready_queue;
|
||||
return &_ready_queue;
|
||||
}
|
||||
|
||||
|
||||
/** \note E' fondamentale che questo metodo memorizzi localmente qualora la politica
|
||||
attuale sia a prerilascio o meno, e la durata del quanto di tempo, in quanto la politica
|
||||
e' libera di variare questi parametri a piacere durante l'esecuzione della simulazione
|
||||
/** \note E' fondamentale che questo metodo memorizzi localmente qualora la politica
|
||||
attuale sia a prerilascio o meno, e la durata del quanto di tempo, in quanto la politica
|
||||
e' libera di variare questi parametri a piacere durante l'esecuzione della simulazione
|
||||
*/
|
||||
void
|
||||
Scheduler::reset_status()
|
||||
{
|
||||
_ready_queue.clear();
|
||||
History::get_instance().truncate_at(0);
|
||||
// restore the policy
|
||||
_ready_queue.clear();
|
||||
History::get_instance().truncate_at(0);
|
||||
// restore the policy
|
||||
}
|
||||
|
||||
/* void
|
||||
|
@ -80,134 +80,134 @@ Scheduler::get_policy()
|
|||
void
|
||||
Scheduler::step_forward() throw(UserInterruptException)
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
Policy& policy = get_policy();
|
||||
|
||||
History& h = History::get_instance();
|
||||
//******************
|
||||
//check for arrivals and prepare the queue
|
||||
//******************
|
||||
smart_ptr<SchedulableQueue> initial = h.get_simulation_status_at(h.get_current_time());
|
||||
if (!initial)
|
||||
{
|
||||
Policy& policy = get_policy();
|
||||
|
||||
History& h = History::get_instance();
|
||||
//******************
|
||||
//check for arrivals and prepare the queue
|
||||
//******************
|
||||
smart_ptr<SchedulableQueue> 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<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() == 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() == 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();
|
||||
|
||||
//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(DynamicSchedulable::state_ready);
|
||||
initial->get_item_at(i)->set_state(DynamicSchedulable::state_ready);
|
||||
|
||||
// Sort the queue
|
||||
policy.sort_queue();
|
||||
|
||||
//restore the old running schedulable
|
||||
if (policy.is_pre_emptive() == false && running_ptr)
|
||||
_ready_queue.add_at_top(*running_ptr);
|
||||
}
|
||||
|
||||
|
||||
//****************
|
||||
// Check for termination
|
||||
//****************
|
||||
|
||||
if (running_ptr && running_ptr->get_cpu_time_left() == 0)
|
||||
{
|
||||
//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(DynamicSchedulable::state_terminated);
|
||||
break;
|
||||
}
|
||||
//cout << "\nTERMINATO!!";
|
||||
running_ptr = NULL;
|
||||
|
||||
//IF _ready_queue.size() == 0 sort_queue(...) is called but has no effect!!
|
||||
policy.sort_queue();
|
||||
}
|
||||
|
||||
//*****************
|
||||
// Check for time slice
|
||||
//*****************
|
||||
if (policy.get_time_slice() != numeric_limits<int>::max()) //time-slice
|
||||
policy.sort_queue();
|
||||
|
||||
//******************
|
||||
// Create the final list of schedulable
|
||||
//******************
|
||||
|
||||
|
||||
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(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() == 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() == 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";
|
||||
/* 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);
|
||||
}
|
||||
catch( UserInterruptException e )
|
||||
{
|
||||
_policy_manager.init();
|
||||
|
||||
throw;
|
||||
|
||||
//TODO Do we need to perform some cleanup operation here?
|
||||
// Do we need to update something?
|
||||
|
||||
// https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1165761&group_id=5470
|
||||
// maybe it's that??? oh, damn.
|
||||
// or maybe not. see http://www.python.org/doc/2.4.2/api/initialization.html
|
||||
|
||||
// Tell:
|
||||
// - the user that the policy sucks
|
||||
// - SimulationController that everything stopped
|
||||
cout << _("\nNo initial state inserted!!\n");
|
||||
return;
|
||||
}
|
||||
_ready_queue.clear();
|
||||
|
||||
|
||||
//adds running schedulable
|
||||
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() == 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() == 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();
|
||||
|
||||
//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(DynamicSchedulable::state_ready);
|
||||
initial->get_item_at(i)->set_state(DynamicSchedulable::state_ready);
|
||||
|
||||
// Sort the queue
|
||||
policy.sort_queue();
|
||||
|
||||
//restore the old running schedulable
|
||||
if (policy.is_pre_emptive() == false && running_ptr)
|
||||
_ready_queue.add_at_top(*running_ptr);
|
||||
}
|
||||
|
||||
|
||||
//****************
|
||||
// Check for termination
|
||||
//****************
|
||||
|
||||
if (running_ptr && running_ptr->get_cpu_time_left() == 0)
|
||||
{
|
||||
//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(DynamicSchedulable::state_terminated);
|
||||
break;
|
||||
}
|
||||
//cout << "\nTERMINATO!!";
|
||||
running_ptr = NULL;
|
||||
|
||||
//IF _ready_queue.size() == 0 sort_queue(...) is called but has no effect!!
|
||||
policy.sort_queue();
|
||||
}
|
||||
|
||||
//*****************
|
||||
// Check for time slice
|
||||
//*****************
|
||||
if (policy.get_time_slice() != numeric_limits<int>::max()) //time-slice
|
||||
policy.sort_queue();
|
||||
|
||||
//******************
|
||||
// Create the final list of schedulable
|
||||
//******************
|
||||
|
||||
|
||||
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(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() == 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() == 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";
|
||||
/* 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);
|
||||
}
|
||||
catch( UserInterruptException e )
|
||||
{
|
||||
_policy_manager.init();
|
||||
|
||||
throw;
|
||||
|
||||
//TODO Do we need to perform some cleanup operation here?
|
||||
// Do we need to update something?
|
||||
|
||||
// https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1165761&group_id=5470
|
||||
// maybe it's that??? oh, damn.
|
||||
// or maybe not. see http://www.python.org/doc/2.4.2/api/initialization.html
|
||||
|
||||
// Tell:
|
||||
// - the user that the policy sucks
|
||||
// - SimulationController that everything stopped
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue