From 9ff7502bb41e803688c2f33418e728cd9daac028 Mon Sep 17 00:00:00 2001 From: tchernobog Date: Sat, 12 Aug 2006 17:04:21 +0000 Subject: [PATCH] - 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 --- .../src/builtin-policies/rr_priority.py | 2 +- src/backend/cpu_policies_gatekeeper.cc | 18 +++++++++---- src/backend/scheduler.cc | 27 ++----------------- 3 files changed, 16 insertions(+), 31 deletions(-) diff --git a/plugins/pyloader/src/builtin-policies/rr_priority.py b/plugins/pyloader/src/builtin-policies/rr_priority.py index 7942ab6..e1d11ac 100644 --- a/plugins/pyloader/src/builtin-policies/rr_priority.py +++ b/plugins/pyloader/src/builtin-policies/rr_priority.py @@ -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?") diff --git a/src/backend/cpu_policies_gatekeeper.cc b/src/backend/cpu_policies_gatekeeper.cc index 2637cdc..f85d143 100644 --- a/src/backend/cpu_policies_gatekeeper.cc +++ b/src/backend/cpu_policies_gatekeeper.cc @@ -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)); } } } diff --git a/src/backend/scheduler.cc b/src/backend/scheduler.cc index 92e9012..f248a86 100644 --- a/src/backend/scheduler.cc +++ b/src/backend/scheduler.cc @@ -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& 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& 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;