mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
bpo-33608: Factor out a private, per-interpreter _Py_AddPendingCall(). (GH-11617)
This involves moving the global "pending calls" state to PyInterpreterState. https://bugs.python.org/issue33608
This commit is contained in:
parent
463572c8be
commit
ef4ac967e2
10 changed files with 201 additions and 121 deletions
|
|
@ -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. */
|
||||
|
|
|
|||
|
|
@ -11,8 +11,12 @@ extern "C" {
|
|||
#include "pycore_atomic.h"
|
||||
#include "pythread.h"
|
||||
|
||||
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*);
|
||||
|
||||
struct _pending_calls {
|
||||
unsigned long main_thread;
|
||||
PyThread_type_lock lock;
|
||||
/* Request for running pending calls. */
|
||||
_Py_atomic_int calls_to_do;
|
||||
|
|
@ -22,6 +26,7 @@ struct _pending_calls {
|
|||
int async_exc;
|
||||
#define NPENDINGCALLS 32
|
||||
struct {
|
||||
unsigned long thread_id;
|
||||
int (*func)(void *);
|
||||
void *arg;
|
||||
} calls[NPENDINGCALLS];
|
||||
|
|
@ -29,6 +34,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 {
|
||||
|
|
@ -39,12 +51,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;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,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"
|
||||
|
|
@ -31,6 +32,8 @@ struct _is {
|
|||
int64_t id_refcount;
|
||||
PyThread_type_lock id_mutex;
|
||||
|
||||
int finalizing;
|
||||
|
||||
PyObject *modules;
|
||||
PyObject *modules_by_index;
|
||||
PyObject *sysdict;
|
||||
|
|
@ -78,6 +81,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);
|
||||
|
|
@ -207,6 +212,8 @@ typedef struct pyruntimestate {
|
|||
struct _xidregitem *head;
|
||||
} xidregistry;
|
||||
|
||||
unsigned long main_thread;
|
||||
|
||||
#define NEXITFUNCS 32
|
||||
void (*exitfuncs[NEXITFUNCS])(void);
|
||||
int nexitfuncs;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue