#define _Py_CURRENTLY_FINALIZING(runtime, tstate) \
(runtime->finalizing == tstate)
+PyAPI_FUNC(int) _Py_IsMainInterpreter(PyThreadState* tstate);
+
/* Variable and macro for in-line access to current thread
and interpreter state */
_thread__is_main_interpreter_impl(PyObject *module)
/*[clinic end generated code: output=7dd82e1728339adc input=cc1eb00fd4598915]*/
{
- _PyRuntimeState *runtime = &_PyRuntime;
- PyInterpreterState *interp = _PyRuntimeState_GetThreadState(runtime)->interp;
- return PyBool_FromLong(interp == runtime->interpreters.main);
+ PyThreadState *tstate = _PyThreadState_GET();
+ int is_main = _Py_IsMainInterpreter(tstate);
+ return PyBool_FromLong(is_main);
}
static PyMethodDef thread_methods[] = {
#define HEAD_UNLOCK(runtime) \
PyThread_release_lock((runtime)->interpreters.mutex)
+int
+_Py_IsMainInterpreter(PyThreadState* tstate)
+{
+ return (tstate->interp == tstate->interp->runtime->interpreters.main);
+}
+
/* Forward declaration */
static void _PyGILState_NoteThreadState(
struct _gilstate_runtime_state *gilstate, PyThreadState* tstate);