- 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:
parent
59edb09c14
commit
9ff7502bb4
|
@ -29,7 +29,7 @@ class rr_priority(CPUPolicy) :
|
||||||
def configure(self):
|
def configure(self):
|
||||||
param = self.get_parameters()
|
param = self.get_parameters()
|
||||||
param.register_int("Time slice", 1, 10000, True, 2)
|
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):
|
def is_preemptive(self):
|
||||||
value = self.get_parameters().get_int("Is preemptive?")
|
value = self.get_parameters().get_int("Is preemptive?")
|
||||||
|
|
|
@ -109,15 +109,23 @@ CPUPoliciesGatekeeper::activate_policy(History *history, CPUPolicy* policy)
|
||||||
{
|
{
|
||||||
try
|
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;
|
_active_policies[history] = policy;
|
||||||
|
policy->activate();
|
||||||
}
|
}
|
||||||
catch(const CPUPolicyException& e)
|
catch(const CPUPolicyException& e)
|
||||||
{
|
{
|
||||||
//FIXME what to do here???
|
// See the comment above to understand why we do this
|
||||||
//probably throwing again a MalformedPolicyException
|
// in this way
|
||||||
//maybe the best idea. or can we just fallback
|
_active_policies.erase(_active_policies.find(history));
|
||||||
//to the previous policy?
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "concrete_history.hh"
|
#include "concrete_history.hh"
|
||||||
#include "cpu_policy.hh"
|
#include "cpu_policy.hh"
|
||||||
#include "scheduler.hh"
|
#include "scheduler.hh"
|
||||||
#include "user_interrupt_exception.hh"
|
#include "cpu_policy_exception.hh"
|
||||||
|
|
||||||
// Do not include full template definition in the header file
|
// Do not include full template definition in the header file
|
||||||
#include "singleton.tcc"
|
#include "singleton.tcc"
|
||||||
|
@ -71,14 +71,6 @@ Scheduler::get_policy()
|
||||||
//.............................................................................
|
//.............................................................................
|
||||||
|
|
||||||
|
|
||||||
static bool
|
|
||||||
validate_environment(ConcreteEnvironment& e)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Introduces newly arrived processes.
|
// Introduces newly arrived processes.
|
||||||
// Postcondition:
|
// Postcondition:
|
||||||
// for each process p in next_snapshot
|
// 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
|
static bool
|
||||||
try_to_run(unsigned int front, auto_ptr<ConcreteEnvironment>& next_snapshot)
|
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 !
|
return !terminated; // watch out for the !
|
||||||
}
|
}
|
||||||
catch(UserInterruptException& e)
|
catch(CPUPolicyException& e)
|
||||||
{
|
{
|
||||||
// Reset values that the policy doesn't need anymore
|
// Reset values that the policy doesn't need anymore
|
||||||
_policy = NULL;
|
_policy = NULL;
|
||||||
|
|
Loading…
Reference in New Issue