- Added NullPolicyException to scheduler

- Started code for printing the state of the scheduling
- Fixed a bug in the copy constructor of DynamicThread

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@794 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-07-23 22:27:33 +00:00
parent f26b80f76b
commit 6a88e3d85e
13 changed files with 167 additions and 23 deletions

View file

@ -89,10 +89,13 @@ namespace sgpem
}
TextSimulation::TextSimulation()
{
}
TextSimulation::~TextSimulation()
{}
{
}
/**
Adds an IO_device and creates a thread which loops the read-parse-execute process
@ -120,7 +123,7 @@ TextSimulation::check_arguments_num(const Tokens& arguments, unsigned int num)
return false;
}
else if(arguments.size() > num)
p_stderr(_("\nWARNING: some arguments will be ignored"));
p_stderr(_("\nWARNING: some arguments will be ignored\n"));
return true;
}
@ -187,10 +190,12 @@ template <typename T>
void
TextSimulation::get_parameter(CommandParameter<T>& parameter)
{
bool correct = true;
bool correct;
do
{
correct = true;
ostringstream buf;
buf << "\n";
@ -333,6 +338,9 @@ TextSimulation::on_run(const Tokens& arguments)
{
check_arguments_num(arguments, 0);
// Listen for updates only during scheduling
Simulation::get_instance().get_history().attach(*this);
try
{
Simulation::get_instance().run();
@ -343,6 +351,14 @@ TextSimulation::on_run(const Tokens& arguments)
p_stderr(e.what());
p_stderr(_("\nSimulation is now stopped"));
}
catch(NullPolicyException e)
{
p_stderr(_("\nERROR: "));
p_stderr(e.what());
p_stderr(_("\nSimulation is now stopped"));
}
Simulation::get_instance().get_history().detach(*this);
}
void
@ -920,8 +936,8 @@ TextSimulation::on_show_cpu_policies(const Tokens& arguments)
oss << "\t" << (*it)->get_description() << endl;
p_stdout(oss.str());
++index;
}
++index;
}
}
@ -944,7 +960,10 @@ TextSimulation::on_add(const Tokens& arguments)
}
if(Simulation::get_instance().get_state() != Simulation::state_stopped)
p_stderr(_("WARNING: Simulation is not stopped, it will be automatically stopped"));
{
p_stderr(_("WARNING: Simulation is not stopped, it will be automatically stopped\n"));
Simulation::get_instance().stop();
}
//make a local copy which we'll probably modify
Tokens args = arguments;
@ -1034,7 +1053,7 @@ TextSimulation::on_add_thread(const Tokens& arguments)
}
CommandParameter<ustring> name(_("name"), "", "", false, "");
CommandParameter<int> cpu_time(_("cpu time"), 0, INT_MAX, true, 0);
CommandParameter<int> cpu_time(_("cpu time"), 1, INT_MAX, true, 0);
CommandParameter<int> arrival_time(_("arrival time"), 0, INT_MAX, false, 0);
CommandParameter<int> base_priority(_("base priority"), 0, INT_MAX, false, 0);
@ -1209,10 +1228,9 @@ TextSimulation::on_remove_resource(const Tokens& arguments)
ustring resource = arguments[0];
const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
const Environment::Processes& processes = env.get_processes();
//const Environment& env = Simulation::get_instance().get_history().get_environment_at(0);
ConcreteHistory::resource_key_t rid;
History::resource_key_t rid;
try
{
@ -1795,8 +1813,22 @@ TextSimulation::parse_command(TextSimulation& sim, const ustring& str)
void
TextSimulation::update()
TextSimulation::update(const History& changed_history)
{
p_stdout(_("\nqueue: { "));
const Environment& env = changed_history.get_last_environment();
const ReadyQueue& q = env.get_sorted_queue();
for(unsigned int i = 0; i < q.size(); ++i)
{
const Thread& t = q.get_item_at(i);
p_stdout(t.get_name() + " ~ ");
}
p_stdout("}\n");
// History& h = History::get_instance();
// int when, arr;
// ustring temp;