- Incapsulate code so that the hack we previously used in CPUPoliciesGatekeeper isn't needed anymore

- Now CPUPolicy has a callback method for scripting languages, but it is up to derived classes to take
mutexes and set the value when needed (maybe we can improve this?)


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@862 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-08-14 14:28:41 +00:00
parent 390af1f09d
commit 45ef305a1b
7 changed files with 80 additions and 39 deletions

View file

@ -118,25 +118,11 @@ CPUPoliciesGatekeeper::activate_policy(History *history, CPUPolicy* policy) thro
try
{
// 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();
_active_policies[history] = policy;
}
catch(const CPUPolicyException& e)
{
//std::cerr << e.what() << std::endl;
// See the comment above to understand why we do this
// in this way
_active_policies.erase(_active_policies.find(history));
{
// the caller need to know if it failed
throw;
}

View file

@ -22,6 +22,11 @@
using namespace std;
using namespace sgpem;
// Static member data
CPUPolicy* CPUPolicy::_callback_policy = NULL;
CPUPolicy::~CPUPolicy()
{}
@ -31,3 +36,20 @@ CPUPolicy::get_parameters()
{
return _parameters;
}
CPUPolicy*
CPUPolicy::callback_get_policy() throw(std::runtime_error)
{
if(_callback_policy == NULL)
throw std::runtime_error("CPUPolicy::callback_get_policy() not used as a callback method. NULL ptr returned.");
return _callback_policy;
}
void
CPUPolicy::set_callback_policy(CPUPolicy* ptr)
{
_callback_policy = ptr;
}

View file

@ -30,6 +30,8 @@
#include "user_interrupt_exception.hh"
#include "malformed_policy_exception.hh"
#include <stdexcept>
namespace sgpem
{
class CPUPolicy;
@ -102,8 +104,18 @@ namespace sgpem
*/
PolicyParameters& get_parameters();
/** This method is used only as a callback by scripting languages */
static CPUPolicy* callback_get_policy() throw(std::runtime_error);
protected:
PolicyParameters _parameters;
PolicyParameters _parameters;
static void set_callback_policy(CPUPolicy* ptr = NULL);
private:
// Used by callback_get_policy:
static CPUPolicy* _callback_policy;
};
}//~ namespace sgpem