- This was an *evil* "chicken-or-egg-first" bug in CPUPoliciesGatekeeper. Now

CPUPolicy->activate() should run properly.


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@846 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-08-12 17:04:21 +00:00
parent 59edb09c14
commit 9ff7502bb4
3 changed files with 16 additions and 31 deletions

View File

@ -29,7 +29,7 @@ class rr_priority(CPUPolicy) :
def configure(self):
param = self.get_parameters()
param.register_int("Time slice", 1, 10000, True, 2)
param.register_int("Is preemptive?", 0, 1, True, 0)
param.register_int("Is preemptive?", 0, 1, True, 1)
def is_preemptive(self):
value = self.get_parameters().get_int("Is preemptive?")

View File

@ -109,15 +109,23 @@ CPUPoliciesGatekeeper::activate_policy(History *history, CPUPolicy* policy)
{
try
{
policy->activate();
// policy->activate() needs already an active policy, because:
// * it calls the configure() method on the
// insert-your-favourite-scripting-language-here-policy
// * which in turn calls the configure() method in the
// code written by the user
// * which probably uses Simulation to get the _active_ C++ policy,
// so it can get its policy_parameters()
// ... so **DON'T** play Mr. Clever Dick and swap the following two
// lines in an optimization frenzy! Or the user policy WILL fail.
_active_policies[history] = policy;
policy->activate();
}
catch(const CPUPolicyException& e)
{
//FIXME what to do here???
//probably throwing again a MalformedPolicyException
//maybe the best idea. or can we just fallback
//to the previous policy?
// See the comment above to understand why we do this
// in this way
_active_policies.erase(_active_policies.find(history));
}
}
}

View File

@ -22,7 +22,7 @@
#include "concrete_history.hh"
#include "cpu_policy.hh"
#include "scheduler.hh"
#include "user_interrupt_exception.hh"
#include "cpu_policy_exception.hh"
// Do not include full template definition in the header file
#include "singleton.tcc"
@ -71,14 +71,6 @@ Scheduler::get_policy()
//.............................................................................
static bool
validate_environment(ConcreteEnvironment& e)
{
return true;
}
// Introduces newly arrived processes.
// Postcondition:
// for each process p in next_snapshot
@ -542,21 +534,6 @@ check_if_simulation_is_terminated(unsigned int front, auto_ptr<ConcreteEnvironme
}
static void
print_queue(unsigned int front, auto_ptr<ConcreteEnvironment>& next_snapshot)
{
ReadyQueue& queue = next_snapshot->get_sorted_queue();
for(unsigned int i = 0; i < queue.size(); i++)
{
std::cout << queue.get_item_at(i).get_name();
}
}
static bool
try_to_run(unsigned int front, auto_ptr<ConcreteEnvironment>& next_snapshot)
{
@ -731,7 +708,7 @@ Scheduler::step_forward(ConcreteHistory& concrete_history, CPUPolicy& cpu_policy
return !terminated; // watch out for the !
}
catch(UserInterruptException& e)
catch(CPUPolicyException& e)
{
// Reset values that the policy doesn't need anymore
_policy = NULL;