- Added full-featured jumpto command.
- Minor fixes on the gui. git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@901 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
d8694b2f5b
commit
df4b32f1ba
9 changed files with 339 additions and 68 deletions
|
@ -19,6 +19,7 @@
|
|||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
#include "concrete_simulation.hh"
|
||||
#include "simulation_observer.hh"
|
||||
#include "scheduler.hh"
|
||||
#include "cpu_policies_gatekeeper.hh"
|
||||
#include <glibmm/timer.h>
|
||||
|
@ -27,6 +28,11 @@
|
|||
|
||||
#include "smartp.tcc"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace sgpem;
|
||||
using namespace memory;
|
||||
|
@ -34,7 +40,10 @@ using Glib::usleep;
|
|||
|
||||
ConcreteSimulation::ConcreteSimulation() :
|
||||
_state(state_stopped), _mode(true), _timer_interval(1000), _policy(NULL)
|
||||
{}
|
||||
{
|
||||
_notify = false;
|
||||
_front = 0;
|
||||
}
|
||||
|
||||
void
|
||||
ConcreteSimulation::set_timer(unsigned int t)
|
||||
|
@ -60,6 +69,37 @@ ConcreteSimulation::get_mode() const
|
|||
return _mode;
|
||||
}
|
||||
|
||||
void
|
||||
ConcreteSimulation::jump_to(History::position p)
|
||||
{
|
||||
|
||||
switch (_state)
|
||||
{
|
||||
case state_running:
|
||||
pause();
|
||||
break;
|
||||
case state_stopped:
|
||||
_history.reset(true);
|
||||
_front = 0;
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
||||
pause();
|
||||
|
||||
bool yet_to_finish = true;
|
||||
while (yet_to_finish && p > _front)
|
||||
yet_to_finish = step();
|
||||
|
||||
if (!yet_to_finish)
|
||||
stop();
|
||||
_history.get_size() << std::endl;
|
||||
_front = p < _front ? p : _front;
|
||||
notify_change();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConcreteSimulation::pause()
|
||||
{
|
||||
|
@ -81,6 +121,7 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException, Mal
|
|||
return;
|
||||
case state_stopped:
|
||||
_history.reset(true);
|
||||
_front = 0;
|
||||
break;
|
||||
default:
|
||||
;
|
||||
|
@ -102,8 +143,12 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException, Mal
|
|||
try
|
||||
{
|
||||
//step forward
|
||||
bool yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy());
|
||||
bool yet_to_finish = true;
|
||||
if (_front == get_history().get_size() - 1)
|
||||
yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy());
|
||||
if (!yet_to_finish) stop();
|
||||
_front++;
|
||||
notify_change();
|
||||
|
||||
//sleep
|
||||
Glib::usleep(_timer_interval*1000);
|
||||
|
@ -128,7 +173,11 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException, Mal
|
|||
{
|
||||
assert(get_policy() != NULL);
|
||||
//step forward
|
||||
bool yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy());
|
||||
bool yet_to_finish = true;
|
||||
if (_front == get_history().get_size() - 1)
|
||||
yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy());
|
||||
_front++;
|
||||
notify_change();
|
||||
if (yet_to_finish)
|
||||
pause();
|
||||
else
|
||||
|
@ -142,6 +191,34 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException, Mal
|
|||
}
|
||||
}
|
||||
|
||||
bool
|
||||
ConcreteSimulation::step()
|
||||
throw(UserInterruptException, NullPolicyException, MalformedPolicyException)
|
||||
{
|
||||
if (get_policy() == NULL)
|
||||
{
|
||||
stop();
|
||||
throw NullPolicyException("no policy selected");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
assert(get_policy() != NULL);
|
||||
//step forward
|
||||
bool yet_to_finish = true;
|
||||
if (_front == get_history().get_size() - 1)
|
||||
yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy());
|
||||
_front++;
|
||||
return yet_to_finish;
|
||||
}
|
||||
catch (const CPUPolicyException& e)
|
||||
{
|
||||
stop();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Simulation::state
|
||||
ConcreteSimulation::get_state() const
|
||||
{
|
||||
|
@ -154,6 +231,13 @@ ConcreteSimulation::get_history()
|
|||
return _history;
|
||||
}
|
||||
|
||||
const ConcreteHistory&
|
||||
ConcreteSimulation::get_history() const
|
||||
{
|
||||
return _history;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ConcreteSimulation::set_policy(CPUPolicy* p) throw(CPUPolicyException)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue