- Corrected get_front() issues.

- Widget tests are now working properly.



git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@990 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
matrevis 2006-09-02 01:56:00 +00:00
parent 4b3cce6bea
commit 47d4fe65b4
10 changed files with 49 additions and 30 deletions

View File

@ -122,7 +122,7 @@ ConcreteHistory::get_last_environment() const
{ {
// Should always be true: // Should always be true:
assert(_snapshots.size() > 0); assert(_snapshots.size() > 0);
return *_snapshots.back(); return get_environment_at(get_front());
} }
@ -487,6 +487,16 @@ ConcreteHistory::edit_subrequest(SubRequest& subrequest,
reset(true); reset(true);
} }
void
ConcreteHistory::step_front(position p)
{
_front = p;
if (p > _snapshots.size())
_front = _snapshots.size();
notify_change();
}
void void
ConcreteHistory::reset(bool notify) ConcreteHistory::reset(bool notify)
{ {
@ -496,6 +506,7 @@ ConcreteHistory::reset(bool notify)
for_each(it, _snapshots.end(), deletor<ConcreteEnvironment>()); for_each(it, _snapshots.end(), deletor<ConcreteEnvironment>());
_snapshots.resize(1); // Truncate to keep only our "model" _snapshots.resize(1); // Truncate to keep only our "model"
_front = 0;
if (notify) if (notify)
notify_change(); notify_change();

View File

@ -110,6 +110,7 @@ namespace sgpem
time_t duration); time_t duration);
virtual void step_front(position p);
virtual void reset(bool notify = true); virtual void reset(bool notify = true);

View File

@ -65,7 +65,6 @@ ConcreteSimulation::jump_to(History::position p) throw(UserInterruptException, N
break; break;
case state_stopped: case state_stopped:
_history.reset(true); _history.reset(true);
_front = 0;
break; break;
default: default:
break; break;
@ -81,12 +80,15 @@ ConcreteSimulation::jump_to(History::position p) throw(UserInterruptException, N
_history.set_notify_enabled(false); _history.set_notify_enabled(false);
bool yet_to_finish = true; bool yet_to_finish = true;
while (yet_to_finish && p > _front) History::position increment = 0;
while (yet_to_finish && p > _history.get_front() + increment)
{
yet_to_finish = step(); yet_to_finish = step();
increment++;
}
get_history().step_front(p);
if (!yet_to_finish) if (!yet_to_finish)
stop(); stop();
_front = std::min(p, _front);
// Reenables updates to registered observers. // Reenables updates to registered observers.
// Calls _history.notify_change() on reactivation. // Calls _history.notify_change() on reactivation.
@ -125,7 +127,6 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException, Mal
{ {
case state_stopped: case state_stopped:
_history.reset(true); _history.reset(true);
_front = 0;
break; break;
default: default:
break; break;
@ -135,6 +136,7 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException, Mal
//step forward //step forward
bool yet_to_finish = step(); bool yet_to_finish = step();
get_history().step_front(get_history().get_front() + 1);
if (yet_to_finish) if (yet_to_finish)
{ {
if(_mode == mode_step_by_step) if(_mode == mode_step_by_step)
@ -173,9 +175,8 @@ ConcreteSimulation::step()
{ {
//step forward //step forward
bool yet_to_finish = true; bool yet_to_finish = true;
if (_front == get_history().get_size() - 1) if (get_history().get_front() == get_history().get_size() - 1)
yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy(), *get_resource_policy()); yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy(), *get_resource_policy());
_front++;
return yet_to_finish; return yet_to_finish;
} }
catch (const CPUPolicyException& e) catch (const CPUPolicyException& e)

View File

@ -30,7 +30,7 @@ using namespace std;
History::History() History::History()
: _notify(true) : _front(0), _notify(true)
{} {}
@ -65,6 +65,11 @@ History::notify_change()
} }
unsigned int History::get_front() const
{
return _front;
}
bool bool
History::set_notify_enabled(bool enabled) History::set_notify_enabled(bool enabled)
{ {

View File

@ -128,6 +128,7 @@ namespace sgpem
resource_key_t resource_key, resource_key_t resource_key,
time_t duration) = 0; time_t duration) = 0;
virtual position get_front() const;
virtual void attach(HistoryObserver& observer); virtual void attach(HistoryObserver& observer);
virtual void detach(const HistoryObserver& observer); virtual void detach(const HistoryObserver& observer);
@ -148,7 +149,11 @@ namespace sgpem
virtual void notify_change(); virtual void notify_change();
position _front;
private: private:
bool _notify; bool _notify;
} }

View File

@ -36,7 +36,7 @@ using namespace sgpem;
template class SG_DLLEXPORT Singleton<ConcreteSimulation>; template class SG_DLLEXPORT Singleton<ConcreteSimulation>;
Simulation::Simulation() Simulation::Simulation()
: _notify(true), _front(0) : _notify(true)
{ {
} }
@ -65,11 +65,6 @@ Simulation::detach(const SimulationObserver& observer)
&observer)); &observer));
} }
unsigned int Simulation::get_front() const
{
return _front;
}
void void
Simulation::notify_change() Simulation::notify_change()
{ {

View File

@ -159,8 +159,6 @@ namespace sgpem
virtual const History& get_history() const = 0; virtual const History& get_history() const = 0;
virtual unsigned int get_front() const;
/** /**
* Small kludge to avoid the need for declaration of ConcreteSimulation * Small kludge to avoid the need for declaration of ConcreteSimulation
* by the calling code of Simulation::get_instance() * by the calling code of Simulation::get_instance()
@ -186,9 +184,6 @@ namespace sgpem
typedef std::vector<SimulationObserver*> RegisteredObservers; typedef std::vector<SimulationObserver*> RegisteredObservers;
RegisteredObservers _observers; RegisteredObservers _observers;
// since no constructor is available, these fields must be defined in concrete subclasses.
History::position _front;
Simulation(); // Constructor Simulation(); // Constructor
virtual void notify_change(); virtual void notify_change();

View File

@ -230,7 +230,7 @@ SimulationWidget::draw_grid(cairo_t* ctx)
// useful constants // useful constants
const History& hist = _simulation->get_history(); const History& hist = _simulation->get_history();
//const int hist_size = hist.get_size(); //const int hist_size = hist.get_size();
const unsigned int simu_front = _simulation->get_front(); const unsigned int hist_front = hist.get_front();
const double top_margin = _yu_top_margin * _y_unit; const double top_margin = _yu_top_margin * _y_unit;
const double left_margin = _x_unit; const double left_margin = _x_unit;
const double left_graph_margin = _xu_left_graph_margin * _x_unit; const double left_graph_margin = _xu_left_graph_margin * _x_unit;
@ -238,7 +238,7 @@ SimulationWidget::draw_grid(cairo_t* ctx)
const double process_bar_height = _yu_process_bar_height * _y_unit; const double process_bar_height = _yu_process_bar_height * _y_unit;
const double process_height = (_yu_process_bar_height + 2*_yu_process_bar_spacing) * _y_unit; const double process_height = (_yu_process_bar_height + 2*_yu_process_bar_spacing) * _y_unit;
const double thread_height = (2.0*_yu_thread_bar_spacing+_yu_thread_bar_height) * _y_unit; const double thread_height = (2.0*_yu_thread_bar_spacing+_yu_thread_bar_height) * _y_unit;
const double graph_width = (2.0 + simu_front) * _x_unit; const double graph_width = (2.0 + hist_front) * _x_unit;
const double graph_height = _n_proc * process_height + (_show_threads?_n_thr:0) * thread_height; const double graph_height = _n_proc * process_height + (_show_threads?_n_thr:0) * thread_height;
// draw graph grid // draw graph grid
@ -282,7 +282,7 @@ SimulationWidget::draw_grid(cairo_t* ctx)
top_margin + graph_height + 2.0 * _y_unit); top_margin + graph_height + 2.0 * _y_unit);
cairo_show_text(ctx,"T"); cairo_show_text(ctx,"T");
for(int t=0; t<=simu_front; t++) for(int t=0; t<=hist_front; t++)
{ {
cairo_move_to(ctx, left_graph_margin + (t+1)*_x_unit, cairo_move_to(ctx, left_graph_margin + (t+1)*_x_unit,
top_margin + graph_height); top_margin + graph_height);
@ -305,7 +305,7 @@ SimulationWidget::draw_bars(cairo_t* ctx)
// useful constants // useful constants
const History& hist = _simulation->get_history(); const History& hist = _simulation->get_history();
const unsigned int simu_front = _simulation->get_front(); const unsigned int hist_front = hist.get_front();
const double top_margin = _yu_top_margin * _y_unit; const double top_margin = _yu_top_margin * _y_unit;
const double left_margin = _x_unit; const double left_margin = _x_unit;
const double left_graph_margin = _xu_left_graph_margin * _x_unit; const double left_graph_margin = _xu_left_graph_margin * _x_unit;
@ -315,11 +315,11 @@ SimulationWidget::draw_bars(cairo_t* ctx)
const double thread_bar_height = _yu_thread_bar_height * _y_unit; const double thread_bar_height = _yu_thread_bar_height * _y_unit;
const double process_height = (_yu_process_bar_height + 2*_yu_process_bar_spacing) * _y_unit; const double process_height = (_yu_process_bar_height + 2*_yu_process_bar_spacing) * _y_unit;
const double thread_height = (2.0*_yu_thread_bar_spacing+_yu_thread_bar_height) * _y_unit; const double thread_height = (2.0*_yu_thread_bar_spacing+_yu_thread_bar_height) * _y_unit;
const double graph_width = (2.0 + simu_front) * _x_unit; const double graph_width = (2.0 + hist_front) * _x_unit;
const double graph_height = _n_proc * process_height + (_show_threads?_n_thr:0) * thread_height; const double graph_height = _n_proc * process_height + (_show_threads?_n_thr:0) * thread_height;
for(int t=1; t<=simu_front; t++) for(int t=1; t<=hist_front; t++)
{ {
// draw schedulables bars // draw schedulables bars
double xpos = left_graph_margin + t * _x_unit; // left start of first process double xpos = left_graph_margin + t * _x_unit; // left start of first process
@ -456,7 +456,7 @@ SimulationWidget::draw_widget(cairo_t* ctx)
cairo_reset_clip(ctx); // remove clip region cairo_reset_clip(ctx); // remove clip region
// std::cout << " draw_widget not_stop " << std::endl; // std::cout << " draw_widget not_stop " << std::endl;
unsigned int pos = _simulation->get_front(); unsigned int pos = _simulation->get_history().get_front();
// show grid // show grid
cairo_save(ctx); cairo_save(ctx);
@ -589,7 +589,7 @@ SimulationWidget::calc_drawing_size(cairo_t* ctx, size_t& width, size_t& height)
return; return;
const History& hist = _simulation->get_history(); const History& hist = _simulation->get_history();
const Environment::Processes& processes = hist.get_last_environment().get_processes(); const Environment::Processes& processes = hist.get_last_environment().get_processes();
int pos = _simulation->get_front(); int pos = _simulation->get_history().get_front();
cairo_text_extents_t extents; cairo_text_extents_t extents;
// std::cout << " x_unit: " << std::endl; // std::cout << " x_unit: " << std::endl;

View File

@ -41,6 +41,9 @@
#include "backend/cpu_policies_gatekeeper.hh" #include "backend/cpu_policies_gatekeeper.hh"
#include "backend/cpu_policy.hh" #include "backend/cpu_policy.hh"
#include "backend/cpu_policy_manager.hh" #include "backend/cpu_policy_manager.hh"
#include "backend/resource_policies_gatekeeper.hh"
#include "backend/resource_policy.hh"
#include "backend/resource_policy_manager.hh"
#include "backend/history_observer.hh" #include "backend/history_observer.hh"
#include "backend/scheduler.hh" #include "backend/scheduler.hh"
#include "backend/simulation.hh" #include "backend/simulation.hh"
@ -419,6 +422,9 @@ main(int argc, char** argv)
History& hist = Simulation::get_instance().get_history(); History& hist = Simulation::get_instance().get_history();
info << "gets history \n"; info << "gets history \n";
ResourcePolicyManager & rpm = *ResourcePoliciesGatekeeper::get_instance().get_registered().at(0);
Simulation::get_instance().set_resource_policy(rpm.get_avail_policies().at(0));
DummyPolicyManager dummy_manager; DummyPolicyManager dummy_manager;
const std::vector<CPUPolicy*>& policies = dummy_manager.get_avail_policies(); const std::vector<CPUPolicy*>& policies = dummy_manager.get_avail_policies();

View File

@ -1664,7 +1664,7 @@ TextSimulation::update(const Simulation& changed_simulation)
// Print header for each instant: // Print header for each instant:
printed_instant = static_cast<int>(changed_simulation.get_front()) - 1; printed_instant = static_cast<int>(changed_simulation.get_history().get_front()) - 1;
oss << endl << ">>>> " << printed_instant; oss << endl << ">>>> " << printed_instant;
@ -1672,7 +1672,7 @@ TextSimulation::update(const Simulation& changed_simulation)
// Print ready queue // Print ready queue
oss << endl << _("READY QUEUE: { "); oss << endl << _("READY QUEUE: { ");
const Environment& env = changed_simulation.get_history().get_environment_at(changed_simulation.get_front()); const Environment& env = changed_simulation.get_history().get_last_environment();
const ReadyQueue& q = env.get_sorted_queue(); const ReadyQueue& q = env.get_sorted_queue();
for (unsigned int i = 0; i < q.size(); ++i) for (unsigned int i = 0; i < q.size(); ++i)