- Make Scheduler::step_forward return a bool representing if

the step went okay or otherwise if the simulation ended
- Fix simulation states in concrete_simulation.cc
- Manage end of input (now CTRL+D exits the program, and 
you can redirect a file in input knowing that at EOF
sgpemv2 will terminate)
- Fix a bug in Scheduler that didn't add the newly created
environment to History when the simulation ended, thus leading
both to a memory leak and an inconsistency in representing
the simulation


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@807 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-08-01 09:19:26 +00:00
parent 6f8625d308
commit c6ebe792e4
6 changed files with 57 additions and 85 deletions

View file

@ -82,98 +82,64 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException)
case state_stopped:
_history.reset(true);
break;
default:
;
}
_state = state_running;
// chech for termination
const Environment &env = _history.get_last_environment();
const Environment::Processes& processes = env.get_processes();
typedef Environment::Processes::const_iterator ProcessesIt;
if(get_policy() == NULL)
{
stop();
throw NullPolicyException("no policy selected");
}
//******* CONTINUOUS TIME
if (_mode)
{
do
{
bool all_term = true;
for(ProcessesIt it = processes.begin(); it != processes.end(); ++it)
if((*it)->get_state() != Schedulable::state_terminated)
{
all_term = false;
break;
}
//if there are no processes left the termination message has already been notified
//by the last execution of upadate()
if (all_term)
{
_state = state_stopped;
return; // Exit from loop
try
{
//step forward
bool yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy());
if(!yet_to_finish) stop();
//sleep
Glib::usleep(_timer_interval*1000);
}
catch(UserInterruptException e)
{
stop();
throw;
}
//check the state
if (_state == state_stopped || _state == state_paused)
return;
}
try
{
if(get_policy() == NULL)
{
stop();
throw NullPolicyException("no policy selected");
}
//step forward
Scheduler::get_instance().step_forward(_history, *get_policy());
//sleep
Glib::usleep(_timer_interval*1000);
}
catch(UserInterruptException e)
{
stop();
throw;
}
//check the state
if (_state == state_stopped || _state == state_paused)
return;
}
while(true);
}
//******* STEP by STEP
else
{
bool all_term = true;
for(ProcessesIt it = processes.begin(); it != processes.end(); ++it)
if((*it)->get_state() != Schedulable::state_terminated)
try
{
all_term = false;
break;
assert(get_policy() != NULL);
//step forward
bool yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy());
if(yet_to_finish)
pause();
else
stop();
}
if (all_term)
//if there are no processes left the termination message has already been notified
//by the last execution of upadate()
_state = state_paused;
else
{
try
catch(UserInterruptException e)
{
assert(get_policy() != NULL);
//step forward
Scheduler::get_instance().step_forward(_history, *get_policy());
}
catch(UserInterruptException e)
{
throw;
}
}
stop();
throw;
}
}
}
Simulation::state