
python-checkins at python
Nov 6, 2009, 12:20 PM
Post #1 of 1
(47 views)
Permalink
|
|
r76135 - in sandbox/trunk/newgil: Include/ceval.h Python/ceval_gil.h Python/sysmodule.c
|
|
Author: antoine.pitrou Date: Fri Nov 6 21:00:13 2009 New Revision: 76135 Log: Store the interval as microseconds. The Python API still uses seconds though. Modified: sandbox/trunk/newgil/Include/ceval.h sandbox/trunk/newgil/Python/ceval_gil.h sandbox/trunk/newgil/Python/sysmodule.c Modified: sandbox/trunk/newgil/Include/ceval.h ============================================================================== --- sandbox/trunk/newgil/Include/ceval.h (original) +++ sandbox/trunk/newgil/Include/ceval.h Fri Nov 6 21:00:13 2009 @@ -171,8 +171,8 @@ PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate); PyAPI_FUNC(void) PyEval_ReInitThreads(void); -PyAPI_FUNC(void) _PyEval_SetSwitchInterval(double seconds); -PyAPI_FUNC(double) _PyEval_GetSwitchInterval(void); +PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds); +PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void); #define Py_BEGIN_ALLOW_THREADS { \ PyThreadState *_save; \ Modified: sandbox/trunk/newgil/Python/ceval_gil.h ============================================================================== --- sandbox/trunk/newgil/Python/ceval_gil.h (original) +++ sandbox/trunk/newgil/Python/ceval_gil.h Fri Nov 6 21:00:13 2009 @@ -8,10 +8,10 @@ /* First some general settings */ -/* milliseconds (the public API uses seconds, though) */ -#define DEFAULT_INTERVAL 5 -static double gil_interval = DEFAULT_INTERVAL; -#define INTERVAL (gil_interval >= 1.0 ? gil_interval : 1.0) +/* microseconds (the Python API uses seconds, though) */ +#define DEFAULT_INTERVAL 5000 +static unsigned long gil_interval = DEFAULT_INTERVAL; +#define INTERVAL (gil_interval >= 1 ? gil_interval : 1) /* Enable if you want to force the switching of threads at least every `gil_interval` */ #undef FORCE_SWITCHING @@ -77,9 +77,9 @@ #include <pthread.h> -#define ADD_MILLISECONDS(tv, interval) \ +#define ADD_MICROSECONDS(tv, interval) \ do { \ - tv.tv_usec += (long) interval * 1000; \ + tv.tv_usec += (long) interval; \ tv.tv_sec += tv.tv_usec / 1000000; \ tv.tv_usec %= 1000000; \ } while (0) @@ -113,14 +113,14 @@ #define COND_WAIT(cond, mut) \ if (pthread_cond_wait(&cond, &mut)) { \ Py_FatalError("pthread_cond_wait(" #cond ") failed"); }; -#define COND_TIMED_WAIT(cond, mut, milliseconds, timeout_result) \ +#define COND_TIMED_WAIT(cond, mut, microseconds, timeout_result) \ { \ int r; \ struct timespec ts; \ struct timeval deadline; \ \ GETTIMEOFDAY(&deadline); \ - ADD_MILLISECONDS(deadline, milliseconds); \ + ADD_MICROSECONDS(deadline, microseconds); \ ts.tv_sec = deadline.tv_sec; \ ts.tv_nsec = deadline.tv_usec * 1000; \ \ @@ -175,12 +175,12 @@ if (r != WAIT_OBJECT_0) \ Py_FatalError("WaitForSingleObject(" #cond ") failed"); \ } -#define COND_TIMED_WAIT(cond, mut, milliseconds, timeout_result) \ +#define COND_TIMED_WAIT(cond, mut, microseconds, timeout_result) \ { \ DWORD r; \ HANDLE objects[2] = { cond, mut }; \ MUTEX_UNLOCK(mut); \ - r = WaitForMultipleObjects(2, objects, TRUE, milliseconds); \ + r = WaitForMultipleObjects(2, objects, TRUE, microseconds / 1000); \ if (r == WAIT_TIMEOUT) { \ MUTEX_LOCK(mut); \ timeout_result = 1; \ @@ -404,14 +404,12 @@ #endif } -void _PyEval_SetSwitchInterval(double seconds) +void _PyEval_SetSwitchInterval(unsigned long microseconds) { - if (seconds <= 0) - Py_FatalError("switch interval must be strictly positive"); - gil_interval = seconds * 1000.0; + gil_interval = microseconds; } -double _PyEval_GetSwitchInterval() +unsigned long _PyEval_GetSwitchInterval() { - return gil_interval / 1000.0; + return gil_interval; } Modified: sandbox/trunk/newgil/Python/sysmodule.c ============================================================================== --- sandbox/trunk/newgil/Python/sysmodule.c (original) +++ sandbox/trunk/newgil/Python/sysmodule.c Fri Nov 6 21:00:13 2009 @@ -489,7 +489,7 @@ "switch interval must be strictly positive"); return NULL; } - _PyEval_SetSwitchInterval(d); + _PyEval_SetSwitchInterval((unsigned long) (1e6 * d)); Py_INCREF(Py_None); return Py_None; } @@ -509,7 +509,7 @@ static PyObject * sys_getswitchinterval(PyObject *self, PyObject *args) { - return PyFloat_FromDouble(_PyEval_GetSwitchInterval()); + return PyFloat_FromDouble(1e-6 * _PyEval_GetSwitchInterval()); } PyDoc_STRVAR(getswitchinterval_doc, _______________________________________________ Python-checkins mailing list Python-checkins[at]python.org http://mail.python.org/mailman/listinfo/python-checkins
|