- 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
|
@ -28,193 +28,194 @@ using namespace memory;
|
|||
using Glib::usleep;
|
||||
|
||||
Simulation::Simulation(): _state(state_paused), _mode(true), _timer_interval(1000)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
void
|
||||
void
|
||||
Simulation::set_timer(const int& t)
|
||||
{
|
||||
_timer_interval = t;
|
||||
_timer_interval = t;
|
||||
}
|
||||
|
||||
int
|
||||
int
|
||||
Simulation::get_timer() const
|
||||
{
|
||||
return _timer_interval;
|
||||
return _timer_interval;
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
Simulation::set_mode(const bool& b)
|
||||
{
|
||||
_mode = b;
|
||||
_mode = b;
|
||||
}
|
||||
|
||||
bool
|
||||
Simulation::get_mode() const
|
||||
{
|
||||
return _mode;
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void
|
||||
Simulation::pause()
|
||||
{
|
||||
_state = state_paused;
|
||||
_state = state_paused;
|
||||
}
|
||||
|
||||
void
|
||||
Simulation::stop()
|
||||
{
|
||||
_state = state_stopped;
|
||||
_state = state_stopped;
|
||||
}
|
||||
|
||||
void
|
||||
Simulation::reset()
|
||||
{
|
||||
_state = state_paused;
|
||||
History::get_instance().truncate_at(0);
|
||||
_state = state_paused;
|
||||
History::get_instance().truncate_at(0);
|
||||
}
|
||||
|
||||
void
|
||||
Simulation::run() throw(UserInterruptException)
|
||||
{
|
||||
History& h = History::get_instance();
|
||||
|
||||
switch(_state)
|
||||
{
|
||||
case state_running:
|
||||
// FIXME: write out something, or just ignore user input?
|
||||
return;
|
||||
case state_stopped:
|
||||
h.truncate_at(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
_state = state_running;
|
||||
|
||||
//******* CONTINUOUS TIME
|
||||
|
||||
if (_mode)
|
||||
{
|
||||
do {
|
||||
// chech for termination
|
||||
bool all_term = true;
|
||||
smart_ptr<SchedulableQueue> left = h.get_simulation_status_at(h.get_current_time());
|
||||
for(uint i = 0; i < left->size(); i++)
|
||||
if (left->get_item_at(i)->get_state() != DynamicSchedulable::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
|
||||
Scheduler::get_instance().step_forward();
|
||||
|
||||
//sleep
|
||||
Glib::usleep(_timer_interval*1000);
|
||||
|
||||
}
|
||||
catch(UserInterruptException e)
|
||||
{
|
||||
stop();
|
||||
throw;
|
||||
}
|
||||
History& h = History::get_instance();
|
||||
|
||||
switch(_state)
|
||||
{
|
||||
case state_running:
|
||||
// FIXME: write out something, or just ignore user input?
|
||||
return;
|
||||
case state_stopped:
|
||||
h.truncate_at(0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
_state = state_running;
|
||||
|
||||
//******* CONTINUOUS TIME
|
||||
|
||||
if (_mode)
|
||||
{
|
||||
do
|
||||
{
|
||||
// chech for termination
|
||||
bool all_term = true;
|
||||
smart_ptr<SchedulableQueue> left = h.get_simulation_status_at(h.get_current_time());
|
||||
for(uint i = 0; i < left->size(); i++)
|
||||
if (left->get_item_at(i)->get_state() != DynamicSchedulable::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
|
||||
Scheduler::get_instance().step_forward();
|
||||
|
||||
//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
|
||||
{
|
||||
// chech for termination
|
||||
bool all_term = true;
|
||||
smart_ptr<SchedulableQueue> left = h.get_simulation_status_at(h.get_current_time());
|
||||
for(uint i = 0; i < left->size(); i++)
|
||||
if (left->get_item_at(i)->get_state() != DynamicSchedulable::state_terminated)
|
||||
{
|
||||
all_term = false;
|
||||
break;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
//step forward
|
||||
Scheduler::get_instance().step_forward();
|
||||
}
|
||||
catch(UserInterruptException e)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//check the state
|
||||
if (_state == state_stopped || _state == state_paused)
|
||||
return;
|
||||
|
||||
} while(true);
|
||||
}
|
||||
|
||||
//******* STEP by STEP
|
||||
else
|
||||
{
|
||||
// chech for termination
|
||||
bool all_term = true;
|
||||
smart_ptr<SchedulableQueue> left = h.get_simulation_status_at(h.get_current_time());
|
||||
for(uint i = 0; i < left->size(); i++)
|
||||
if (left->get_item_at(i)->get_state() != DynamicSchedulable::state_terminated)
|
||||
{
|
||||
all_term = false;
|
||||
break;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
//step forward
|
||||
Scheduler::get_instance().step_forward();
|
||||
}
|
||||
catch(UserInterruptException e)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Simulation::jump_to(const uint& where) throw(UserInterruptException)
|
||||
{
|
||||
//jump to position 0
|
||||
reset();
|
||||
bool old = _mode;
|
||||
_mode = false;
|
||||
|
||||
//jump to position 0
|
||||
reset();
|
||||
bool old = _mode;
|
||||
_mode = false;
|
||||
|
||||
try
|
||||
{
|
||||
// executes "where" steps
|
||||
for (uint i=0; i < where; i++)
|
||||
run();
|
||||
}
|
||||
catch(UserInterruptException e)
|
||||
{
|
||||
_mode = old;
|
||||
throw;
|
||||
}
|
||||
|
||||
_state = state_paused;
|
||||
_mode = old;
|
||||
|
||||
try
|
||||
{
|
||||
// executes "where" steps
|
||||
for (uint i = 0; i < where; i++)
|
||||
run();
|
||||
}
|
||||
catch(UserInterruptException e)
|
||||
{
|
||||
_mode = old;
|
||||
throw;
|
||||
}
|
||||
|
||||
_state = state_paused;
|
||||
_mode = old;
|
||||
}
|
||||
|
||||
/*void
|
||||
Simulation::set_policy(Policy* p)
|
||||
{
|
||||
Scheduler::get_instance().set_policy(p);
|
||||
}*/
|
||||
Scheduler::get_instance().set_policy(p);
|
||||
}*/
|
||||
|
||||
|
||||
Policy*
|
||||
Simulation::get_policy()
|
||||
{
|
||||
return &Scheduler::get_instance().get_policy();
|
||||
return &Scheduler::get_instance().get_policy();
|
||||
}
|
||||
|
||||
vector<Policy*>
|
||||
Simulation::get_avaiable_policies()
|
||||
{
|
||||
vector<Policy*> v;
|
||||
v.push_back(&Scheduler::get_instance().get_policy());
|
||||
return v;
|
||||
vector<Policy*> v;
|
||||
v.push_back(&Scheduler::get_instance().get_policy());
|
||||
return v;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue