From 6c79bc361c62e2db653240a6b0fd2791a081749b Mon Sep 17 00:00:00 2001 From: tchernobog Date: Fri, 28 Jul 2006 12:21:49 +0000 Subject: [PATCH] - Fix deadlock that blocked PythonPolicy::sort_queue git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@796 3ecf2c5c-341e-0410-92b4-d18e462d057c --- plugins/pyloader/src/python_policy.cc | 5 +---- src/backend/scheduler.cc | 8 ++++---- src/backend/scheduler.hh | 14 ++++++-------- src/templates/singleton.hh | 2 +- src/templates/singleton.tcc | 6 +++--- 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/plugins/pyloader/src/python_policy.cc b/plugins/pyloader/src/python_policy.cc index d51477e..358e75d 100644 --- a/plugins/pyloader/src/python_policy.cc +++ b/plugins/pyloader/src/python_policy.cc @@ -100,15 +100,12 @@ PythonPolicy::configure() throw(UserInterruptException) void PythonPolicy::sort_queue() const throw(UserInterruptException) { - PyObject* pMethodName = PyString_FromString("async_sort_queue"); - PyObject* retval = PyObject_CallMethodObjArgs(_adapter, pMethodName, NULL, NULL); + PyObject* retval = PyObject_CallMethod(_adapter, "async_sort_queue", NULL); // Do minimal debugging if(!retval) PyErr_Print(); else Py_DECREF(retval); - Py_DECREF(pMethodName); - wait_unlock(); } diff --git a/src/backend/scheduler.cc b/src/backend/scheduler.cc index 005b441..fcff134 100644 --- a/src/backend/scheduler.cc +++ b/src/backend/scheduler.cc @@ -131,14 +131,14 @@ update_requests_for_old_running_thread(DynamicThread& running_thread) //private constructor. The parameter is discarded Scheduler::Scheduler() - : _ready_queue(NULL), _policy(NULL) -{} + : _ready_queue(NULL), _policy(NULL), _step_mutex() +{ +} ReadyQueue* Scheduler::get_ready_queue() { - // FIXME return the correct queue accordingly to the value returned by Policy::wants() return _ready_queue; } @@ -168,7 +168,7 @@ Scheduler::step_forward(History& history, Policy& cpu_policy) throw(UserInterrup // store a readyqueue and policy pointer for the user-policy to retrieve, to when // the policy returns // TODO: restrict this area to maximise parallelism - Glib::Mutex::Lock lock(_mutex); + Glib::Mutex::Lock lock(_step_mutex); // NOTE: Be sure to read the *ORIGINAL* documentation in the design document for this method! diff --git a/src/backend/scheduler.hh b/src/backend/scheduler.hh index 1284f8c..65a8f21 100644 --- a/src/backend/scheduler.hh +++ b/src/backend/scheduler.hh @@ -37,6 +37,8 @@ namespace sgpem // Do not include full template definition here #include "singleton.hh" +#include + namespace sgpem { class Scheduler; @@ -74,13 +76,7 @@ namespace sgpem one instant with it. */ void step_forward(History& history, Policy& cpu_policy) throw(UserInterruptException); - /** - Sets the policy that will be used to generate the simulation at the next instant. - \param policy the policy that will be used to generate the simulation at the next instant. - */ - /* DISABLED until we don't have PolicyManager::set_policy() - void set_policy(Policy* policy); - */ + /** Returns the policy that will be used to generate the simulation at the next instant. \return the policy that will be used to generate the simulation at the next instant. @@ -89,9 +85,11 @@ namespace sgpem private: Scheduler(); //private constructor. - + ReadyQueue* _ready_queue; Policy* _policy; + + Glib::Mutex _step_mutex; }; }//~ namespace sgpem diff --git a/src/templates/singleton.hh b/src/templates/singleton.hh index 341cb78..4053645 100644 --- a/src/templates/singleton.hh +++ b/src/templates/singleton.hh @@ -46,7 +46,7 @@ namespace sgpem static Instantiated_class& get_instance(); protected: - static Glib::StaticMutex SG_DLLLOCAL _mutex; + static Glib::RecMutex SG_DLLLOCAL _mutex; private: static SG_DLLLOCAL Instantiated_class* _instance; diff --git a/src/templates/singleton.tcc b/src/templates/singleton.tcc index bcecc88..b5d30e7 100644 --- a/src/templates/singleton.tcc +++ b/src/templates/singleton.tcc @@ -26,15 +26,15 @@ Instantiated_class* sgpem::Singleton::_instance = NULL; template -Glib::StaticMutex -sgpem::Singleton::_mutex = GLIBMM_STATIC_MUTEX_INIT; +Glib::RecMutex +sgpem::Singleton::_mutex; template Instantiated_class& sgpem::Singleton::get_instance() { - Glib::Mutex::Lock lock(_mutex); + Glib::RecMutex::Lock lock(_mutex); if(_instance == NULL) _instance = new Instantiated_class(); return *_instance;