Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d581d77

Browse files
author
Skip Montanaro
committed
replace thread state objects' ticker and checkinterval fields with two
globals, _Py_Ticker and _Py_CheckInterval. This also implements Jeremy's shortcut in Py_AddPendingCall that zeroes out _Py_Ticker. This allows the test in the main loop to only test a single value. The gory details are at http://python.org/sf/602191
1 parent d229b3a commit d581d77

5 files changed

Lines changed: 15 additions & 10 deletions

File tree

Include/ceval.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ PyAPI_FUNC(int) Py_GetRecursionLimit(void);
4848
PyAPI_FUNC(char *) PyEval_GetFuncName(PyObject *);
4949
PyAPI_FUNC(char *) PyEval_GetFuncDesc(PyObject *);
5050

51+
/* this used to be handled on a per-thread basis - now just two globals */
52+
PyAPI_DATA(volatile int) _Py_Ticker;
53+
PyAPI_DATA(int) _Py_CheckInterval;
54+
5155
/* Interface for threads.
5256
5357
A module that plans to do a blocking system call (or something else

Include/pystate.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ typedef struct _is {
2222
PyObject *sysdict;
2323
PyObject *builtins;
2424

25-
int checkinterval;
2625
#ifdef HAVE_DLOPEN
2726
int dlopenflags;
2827
#endif
@@ -50,7 +49,6 @@ typedef struct _ts {
5049

5150
struct _frame *frame;
5251
int recursion_depth;
53-
int ticker;
5452
int tracing;
5553
int use_tracing;
5654

Objects/longobject.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ static PyLongObject *muladd1(PyLongObject *, wdigit, wdigit);
2828
static PyLongObject *divrem1(PyLongObject *, digit, digit *);
2929
static PyObject *long_format(PyObject *aa, int base, int addL);
3030

31-
static int ticker; /* XXX Could be shared with ceval? */
32-
3331
#define SIGCHECK(PyTryBlock) \
34-
if (--ticker < 0) { \
35-
ticker = 100; \
32+
if (--_Py_Ticker < 0) { \
33+
_Py_Ticker = _Py_CheckInterval; \
3634
if (PyErr_CheckSignals()) { PyTryBlock; } \
3735
}
3836

Python/ceval.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ Py_AddPendingCall(int (*func)(void *), void *arg)
395395
pendingcalls[i].func = func;
396396
pendingcalls[i].arg = arg;
397397
pendinglast = j;
398+
399+
_Py_Ticker = 0;
398400
things_to_do = 1; /* Signal main loop */
399401
busy = 0;
400402
/* XXX End critical section */
@@ -465,6 +467,10 @@ enum why_code {
465467
static enum why_code do_raise(PyObject *, PyObject *, PyObject *);
466468
static int unpack_iterable(PyObject *, int, PyObject **);
467469

470+
/* for manipulating the thread switch and periodic "stuff" - used to be
471+
per thread, now just a pair o' globals */
472+
int _Py_CheckInterval = 10;
473+
volatile int _Py_Ticker = 10;
468474

469475
PyObject *
470476
PyEval_EvalCode(PyCodeObject *co, PyObject *globals, PyObject *locals)
@@ -669,8 +675,8 @@ eval_frame(PyFrameObject *f)
669675
async I/O handler); see Py_AddPendingCall() and
670676
Py_MakePendingCalls() above. */
671677

672-
if (things_to_do || --tstate->ticker < 0) {
673-
tstate->ticker = tstate->interp->checkinterval;
678+
if (--_Py_Ticker < 0) {
679+
_Py_Ticker = _Py_CheckInterval;
674680
if (things_to_do) {
675681
if (Py_MakePendingCalls() < 0) {
676682
why = WHY_EXCEPTION;

Python/sysmodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,7 @@ and return. See the profiler chapter in the library manual."
352352
static PyObject *
353353
sys_setcheckinterval(PyObject *self, PyObject *args)
354354
{
355-
PyThreadState *tstate = PyThreadState_Get();
356-
if (!PyArg_ParseTuple(args, "i:setcheckinterval", &tstate->interp->checkinterval))
355+
if (!PyArg_ParseTuple(args, "i:setcheckinterval", &_Py_CheckInterval))
357356
return NULL;
358357
Py_INCREF(Py_None);
359358
return Py_None;

0 commit comments

Comments
 (0)