diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2019-04-12 15:18:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-12 15:18:16 (GMT) |
commit | f13c5c8b9401a9dc19e95d8b420ee100ac022208 (patch) | |
tree | 00e61cfbb38d11341b39c3d5abe6b04a2ccbbbb5 /Include | |
parent | 44235041f3b957abd36d3792450c3540aa09e120 (diff) | |
download | cpython-f13c5c8b9401a9dc19e95d8b420ee100ac022208.zip cpython-f13c5c8b9401a9dc19e95d8b420ee100ac022208.tar.gz cpython-f13c5c8b9401a9dc19e95d8b420ee100ac022208.tar.bz2 |
bpo-33608: Factor out a private, per-interpreter _Py_AddPendingCall(). (gh-12360)
This is effectively an un-revert of #11617 and #12024 (reverted in #12159). Portions of those were merged in other PRs (with lower risk) and this represents the remainder. Note that I found 3 different bugs in the original PRs and have fixed them here.
Diffstat (limited to 'Include')
-rw-r--r-- | Include/ceval.h | 2 | ||||
-rw-r--r-- | Include/internal/pycore_ceval.h | 18 | ||||
-rw-r--r-- | Include/internal/pycore_pystate.h | 3 |
3 files changed, 17 insertions, 6 deletions
diff --git a/Include/ceval.h b/Include/ceval.h index 11283c0..9c6d420 100644 --- a/Include/ceval.h +++ b/Include/ceval.h @@ -221,7 +221,7 @@ PyAPI_FUNC(Py_ssize_t) _PyEval_RequestCodeExtraIndex(freefunc); #ifndef Py_LIMITED_API PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *); PyAPI_FUNC(int) _PyEval_SliceIndexNotNone(PyObject *, Py_ssize_t *); -PyAPI_FUNC(void) _PyEval_SignalAsyncExc(void); +PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyInterpreterState *); #endif /* Masks and values used by FORMAT_VALUE opcode. */ diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h index 2ead96c..1bdcdf5 100644 --- a/Include/internal/pycore_ceval.h +++ b/Include/internal/pycore_ceval.h @@ -11,7 +11,11 @@ extern "C" { #include "pycore_atomic.h" #include "pythread.h" -PyAPI_FUNC(void) _Py_FinishPendingCalls(void); +struct _is; // See PyInterpreterState in cpython/pystate.h. + +PyAPI_FUNC(int) _Py_AddPendingCall(struct _is*, unsigned long, int (*)(void *), void *); +PyAPI_FUNC(int) _Py_MakePendingCalls(struct _is*); +PyAPI_FUNC(void) _Py_FinishPendingCalls(struct _is*); struct _pending_calls { int finishing; @@ -24,6 +28,7 @@ struct _pending_calls { int async_exc; #define NPENDINGCALLS 32 struct { + unsigned long thread_id; int (*func)(void *); void *arg; } calls[NPENDINGCALLS]; @@ -31,6 +36,13 @@ struct _pending_calls { int last; }; +struct _ceval_interpreter_state { + /* This single variable consolidates all requests to break out of + the fast path in the eval loop. */ + _Py_atomic_int eval_breaker; + struct _pending_calls pending; +}; + #include "pycore_gil.h" struct _ceval_runtime_state { @@ -41,12 +53,8 @@ struct _ceval_runtime_state { c_tracefunc. This speeds up the if statement in PyEval_EvalFrameEx() after fast_next_opcode. */ int tracing_possible; - /* This single variable consolidates all requests to break out of - the fast path in the eval loop. */ - _Py_atomic_int eval_breaker; /* Request for dropping the GIL */ _Py_atomic_int gil_drop_request; - struct _pending_calls pending; /* Request for checking signals. */ _Py_atomic_int signals_pending; struct _gil_runtime_state gil; diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h index df3730f..3ae2e0c 100644 --- a/Include/internal/pycore_pystate.h +++ b/Include/internal/pycore_pystate.h @@ -12,6 +12,7 @@ extern "C" { #include "pystate.h" #include "pythread.h" +#include "pycore_atomic.h" #include "pycore_ceval.h" #include "pycore_pathconfig.h" #include "pycore_pymem.h" @@ -83,6 +84,8 @@ struct _is { PyObject *pyexitmodule; uint64_t tstate_next_unique_id; + + struct _ceval_interpreter_state ceval; }; PyAPI_FUNC(struct _is*) _PyInterpreterState_LookUpID(PY_INT64_T); |