diff options
Diffstat (limited to 'Include')
-rw-r--r-- | Include/internal/pycore_pystate.h | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h index 405efb9..b5f5095 100644 --- a/Include/internal/pycore_pystate.h +++ b/Include/internal/pycore_pystate.h @@ -223,8 +223,11 @@ typedef struct pyruntimestate { int initialized; /* Set by Py_FinalizeEx(). Only reset to NULL if Py_Initialize() - is called again. */ - PyThreadState *finalizing; + is called again. + + Use _PyRuntimeState_GetFinalizing() and _PyRuntimeState_SetFinalizing() + to access it, don't access it directly. */ + _Py_atomic_address _finalizing; struct pyinterpreters { PyThread_type_lock mutex; @@ -279,8 +282,15 @@ PyAPI_FUNC(PyStatus) _PyRuntime_Initialize(void); PyAPI_FUNC(void) _PyRuntime_Finalize(void); -#define _Py_CURRENTLY_FINALIZING(runtime, tstate) \ - (runtime->finalizing == tstate) +static inline PyThreadState* +_PyRuntimeState_GetFinalizing(_PyRuntimeState *runtime) { + return (PyThreadState*)_Py_atomic_load_relaxed(&runtime->_finalizing); +} + +static inline void +_PyRuntimeState_SetFinalizing(_PyRuntimeState *runtime, PyThreadState *tstate) { + _Py_atomic_store_relaxed(&runtime->_finalizing, (uintptr_t)tstate); +} PyAPI_FUNC(int) _Py_IsMainInterpreter(PyThreadState* tstate); @@ -288,8 +298,9 @@ PyAPI_FUNC(int) _Py_IsMainInterpreter(PyThreadState* tstate); /* Variable and macro for in-line access to current thread and interpreter state */ -#define _PyRuntimeState_GetThreadState(runtime) \ - ((PyThreadState*)_Py_atomic_load_relaxed(&(runtime)->gilstate.tstate_current)) +static inline PyThreadState* _PyRuntimeState_GetThreadState(_PyRuntimeState *runtime) { + return (PyThreadState*)_Py_atomic_load_relaxed(&runtime->gilstate.tstate_current); +} /* Get the current Python thread state. |