From eec74de63266a9fa6872b65c29ac66aeb49726e1 Mon Sep 17 00:00:00 2001 From: tchernobog Date: Sat, 9 Sep 2006 12:30:49 +0000 Subject: [PATCH] - Poll more often to make "jump_to()" faster. Also increase time given to a policy before judging it dead to ~5 seconds. git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1076 3ecf2c5c-341e-0410-92b4-d18e462d057c --- plugins/pyloader/src/python_cpu_policy.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/pyloader/src/python_cpu_policy.cc b/plugins/pyloader/src/python_cpu_policy.cc index 40e9d5f..57b612d 100644 --- a/plugins/pyloader/src/python_cpu_policy.cc +++ b/plugins/pyloader/src/python_cpu_policy.cc @@ -18,6 +18,8 @@ // along with SGPEMv2; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#include "config.h" + #include "python_cpu_policy.hh" #include @@ -27,9 +29,6 @@ using namespace sgpem; using namespace std; -#define WAIT_FOR (250000) - - // Static member data Glib::StaticRecMutex PythonCPUPolicy::_mtx = GLIBMM_STATIC_REC_MUTEX_INIT; @@ -225,6 +224,9 @@ PythonCPUPolicy::get_time_slice() const throw(UserInterruptException, MalformedP void PythonCPUPolicy::wait_unlock() const throw(UserInterruptException, MalformedPolicyException) { + // Polling time + static const int wait_for = 150000; + PyThreadState* _save; int i = 0; // We give the sort_queue() three seconds max time, then... // we shot it stone dead! Bang. @@ -233,7 +235,7 @@ PythonCPUPolicy::wait_unlock() const throw(UserInterruptException, MalformedPoli do { Py_UNBLOCK_THREADS; - usleep(WAIT_FOR); // hack'a'ton! magggggiccc nummmbeeerrrrrs!! + usleep(wait_for); // hack'a'ton! magggggiccc nummmbeeerrrrrs!! Py_BLOCK_THREADS; PyObject* retval = PyObject_CallMethod(_adapter, "mutex_test_lock", NULL); @@ -241,7 +243,7 @@ PythonCPUPolicy::wait_unlock() const throw(UserInterruptException, MalformedPoli still_locked = PyObject_IsTrue(retval); Py_DECREF(retval); - if (i++ > 12) /* waits for WAIT_FOR * 12 microseconds == 3 secs */ + if (i++ > (1000000 / wait_for) * 5) /* waits for ~5 seconds */ { PyThreadState_Clear(_save); // As the API documentation says, the caller of PyEval_RestoreThread