- Added ConcreteSimulation, but not coded it`s behaviour
- Made Simulation a singleton git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@771 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
1506c46287
commit
4ab7123ced
7 changed files with 316 additions and 231 deletions
|
@ -19,204 +19,22 @@
|
|||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
#include "simulation.hh"
|
||||
#include "concrete_simulation.hh"
|
||||
|
||||
#include "smartp.tcc"
|
||||
|
||||
using namespace std;
|
||||
// Do not include in header file:
|
||||
#include "singleton.tcc"
|
||||
using namespace sgpem;
|
||||
using namespace memory;
|
||||
using Glib::usleep;
|
||||
|
||||
Simulation::Simulation(): _state(state_paused), _mode(true), _timer_interval(1000)
|
||||
{}
|
||||
// Explicit template instantiation to allow to export symbols from the DSO.
|
||||
template class SG_DLLEXPORT Singleton<ConcreteSimulation>;
|
||||
|
||||
void
|
||||
Simulation::set_timer(const int& t)
|
||||
|
||||
Simulation::~Simulation()
|
||||
{
|
||||
_timer_interval = t;
|
||||
}
|
||||
|
||||
int
|
||||
Simulation::get_timer() const
|
||||
Simulation&
|
||||
Simulation::get_instance()
|
||||
{
|
||||
return _timer_interval;
|
||||
}
|
||||
|
||||
void
|
||||
Simulation::set_mode(const bool& b)
|
||||
{
|
||||
_mode = b;
|
||||
}
|
||||
|
||||
bool
|
||||
Simulation::get_mode() const
|
||||
{
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void
|
||||
Simulation::pause()
|
||||
{
|
||||
_state = state_paused;
|
||||
}
|
||||
|
||||
void
|
||||
Simulation::stop()
|
||||
{
|
||||
_state = state_stopped;
|
||||
}
|
||||
|
||||
void
|
||||
Simulation::reset()
|
||||
{
|
||||
_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<ReadyQueue> 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<ReadyQueue> 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;
|
||||
|
||||
|
||||
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);
|
||||
}*/
|
||||
|
||||
|
||||
Policy*
|
||||
Simulation::get_policy()
|
||||
{
|
||||
//return &Scheduler::get_instance().get_policy();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vector<Policy*>
|
||||
Simulation::get_avaiable_policies()
|
||||
{
|
||||
vector<Policy*> v;
|
||||
//v.push_back(&Scheduler::get_instance().get_policy());
|
||||
return v;
|
||||
return Singleton<ConcreteSimulation>::get_instance();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue