diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2023-05-15 19:59:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-15 19:59:26 (GMT) |
commit | 26baa747c2ebc2beeff769bb07b5fb5a51ad5f4b (patch) | |
tree | e54b52c2c950d59a20f4b0658d8eb2af3adec246 /Include | |
parent | cb88ae635e96d7020ba6187bcfd45ace4dcd8395 (diff) | |
download | cpython-26baa747c2ebc2beeff769bb07b5fb5a51ad5f4b.zip cpython-26baa747c2ebc2beeff769bb07b5fb5a51ad5f4b.tar.gz cpython-26baa747c2ebc2beeff769bb07b5fb5a51ad5f4b.tar.bz2 |
gh-104341: Adjust tstate_must_exit() to Respect Interpreter Finalization (gh-104437)
With the move to a per-interpreter GIL, this check slipped through the cracks.
Diffstat (limited to 'Include')
-rw-r--r-- | Include/cpython/pylifecycle.h | 1 | ||||
-rw-r--r-- | Include/internal/pycore_interp.h | 18 |
2 files changed, 19 insertions, 0 deletions
diff --git a/Include/cpython/pylifecycle.h b/Include/cpython/pylifecycle.h index 08569ee..314a5cc 100644 --- a/Include/cpython/pylifecycle.h +++ b/Include/cpython/pylifecycle.h @@ -52,6 +52,7 @@ PyAPI_FUNC(const char *) _Py_gitidentifier(void); PyAPI_FUNC(const char *) _Py_gitversion(void); PyAPI_FUNC(int) _Py_IsFinalizing(void); +PyAPI_FUNC(int) _Py_IsInterpreterFinalizing(PyInterpreterState *interp); /* Random */ PyAPI_FUNC(int) _PyOS_URandom(void *buffer, Py_ssize_t size); diff --git a/Include/internal/pycore_interp.h b/Include/internal/pycore_interp.h index 527b212..edc076f 100644 --- a/Include/internal/pycore_interp.h +++ b/Include/internal/pycore_interp.h @@ -83,6 +83,13 @@ struct _is { int _initialized; int finalizing; + /* Set by Py_EndInterpreter(). + + Use _PyInterpreterState_GetFinalizing() + and _PyInterpreterState_SetFinalizing() + to access it, don't access it directly. */ + _Py_atomic_address _finalizing; + struct _obmalloc_state obmalloc; struct _ceval_state ceval; @@ -191,6 +198,17 @@ struct _is { extern void _PyInterpreterState_Clear(PyThreadState *tstate); +static inline PyThreadState* +_PyInterpreterState_GetFinalizing(PyInterpreterState *interp) { + return (PyThreadState*)_Py_atomic_load_relaxed(&interp->_finalizing); +} + +static inline void +_PyInterpreterState_SetFinalizing(PyInterpreterState *interp, PyThreadState *tstate) { + _Py_atomic_store_relaxed(&interp->_finalizing, (uintptr_t)tstate); +} + + /* cross-interpreter data registry */ /* For now we use a global registry of shareable classes. An |