diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-05-10 21:39:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-10 21:39:09 (GMT) |
commit | 09532feeece39d5ba68a0d47115ce1967bfbd58e (patch) | |
tree | 95224bb8455ae1d824f7d05fad29d542058eab6d /Python/pystate.c | |
parent | f22cc69b012f52882d434a5c44a004bc3aa5c33c (diff) | |
download | cpython-09532feeece39d5ba68a0d47115ce1967bfbd58e.zip cpython-09532feeece39d5ba68a0d47115ce1967bfbd58e.tar.gz cpython-09532feeece39d5ba68a0d47115ce1967bfbd58e.tar.bz2 |
bpo-36710: Add 'ceval' local variable to ceval.c (GH-12934)
Add "struct _ceval_runtime_state *ceval = &_PyRuntime.ceval;" local
variables to function to better highlight the dependency on the
global variable _PyRuntime and to point directly to _PyRuntime.ceval
field rather than on the larger _PyRuntime.
Changes:
* Add _PyRuntimeState_GetThreadState(runtime) macro.
* Add _PyEval_AddPendingCall(ceval, ...) and
_PyThreadState_Swap(gilstate, ...) functions.
* _PyThreadState_GET() macro now calls
_PyRuntimeState_GetThreadState() using &_PyRuntime.
* Add 'ceval' parameter to COMPUTE_EVAL_BREAKER(),
SIGNAL_PENDING_SIGNALS(), _PyEval_SignalAsyncExc(),
_PyEval_SignalReceived() and _PyEval_FiniThreads() macros and
functions.
* Add 'tstate' parameter to call_function(), do_call_core() and
do_raise().
* Add 'runtime' parameter to _Py_CURRENTLY_FINALIZING(),
_Py_FinishPendingCalls() and _PyThreadState_DeleteExcept()
macros and functions.
* Declare 'runtime', 'tstate', 'ceval' and 'eval_breaker' variables
as constant.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r-- | Python/pystate.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index 44acfed..6731575 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -2,6 +2,7 @@ /* Thread and interpreter state structures and their interfaces */ #include "Python.h" +#include "pycore_ceval.h" #include "pycore_coreconfig.h" #include "pycore_pymem.h" #include "pycore_pystate.h" @@ -39,7 +40,6 @@ extern "C" { /* Forward declarations */ static PyThreadState *_PyGILState_GetThisThreadState(struct _gilstate_runtime_state *gilstate); static void _PyThreadState_Delete(_PyRuntimeState *runtime, PyThreadState *tstate); -static PyThreadState *_PyThreadState_Swap(struct _gilstate_runtime_state *gilstate, PyThreadState *newts); static _PyInitError @@ -867,9 +867,8 @@ PyThreadState_DeleteCurrent() * be kept in those other interpreteres. */ void -_PyThreadState_DeleteExcept(PyThreadState *tstate) +_PyThreadState_DeleteExcept(_PyRuntimeState *runtime, PyThreadState *tstate) { - _PyRuntimeState *runtime = &_PyRuntime; PyInterpreterState *interp = tstate->interp; PyThreadState *p, *next, *garbage; HEAD_LOCK(runtime); @@ -915,7 +914,7 @@ PyThreadState_Get(void) } -static PyThreadState * +PyThreadState * _PyThreadState_Swap(struct _gilstate_runtime_state *gilstate, PyThreadState *newts) { PyThreadState *oldts = _PyRuntimeGILState_GetThreadState(gilstate); @@ -980,8 +979,8 @@ PyThreadState_GetDict(void) int PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc) { - PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE(); - PyThreadState *p; + _PyRuntimeState *runtime = &_PyRuntime; + PyInterpreterState *interp = _PyRuntimeState_GetThreadState(runtime)->interp; /* Although the GIL is held, a few C API functions can be called * without the GIL held, and in particular some that create and @@ -989,9 +988,8 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc) * list of thread states we're traversing, so to prevent that we lock * head_mutex for the duration. */ - _PyRuntimeState *runtime = &_PyRuntime; HEAD_LOCK(runtime); - for (p = interp->tstate_head; p != NULL; p = p->next) { + for (PyThreadState *p = interp->tstate_head; p != NULL; p = p->next) { if (p->thread_id == id) { /* Tricky: we need to decref the current value * (if any) in p->async_exc, but that can in turn @@ -1005,7 +1003,7 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc) p->async_exc = exc; HEAD_UNLOCK(runtime); Py_XDECREF(old_exc); - _PyEval_SignalAsyncExc(); + _PyEval_SignalAsyncExc(&runtime->ceval); return 1; } } |