}
+#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
+int
+_PyEval_ThreadsInitialized(PyInterpreterState *interp)
+{
+ return gil_created(&interp->ceval.gil);
+}
+
+int
+PyEval_ThreadsInitialized(void)
+{
+ // Fatal error if there is no current interpreter
+ PyInterpreterState *interp = PyInterpreterState_Get();
+ return _PyEval_ThreadsInitialized(interp);
+}
+#else
int
_PyEval_ThreadsInitialized(_PyRuntimeState *runtime)
{
_PyRuntimeState *runtime = &_PyRuntime;
return _PyEval_ThreadsInitialized(runtime);
}
+#endif
PyStatus
_PyEval_InitGIL(PyThreadState *tstate)
{
+#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
if (!_Py_IsMainInterpreter(tstate)) {
/* Currently, the GIL is shared by all interpreters,
and only the main interpreter is responsible to create
and destroy it. */
return _PyStatus_OK();
}
+#endif
+#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
+ struct _gil_runtime_state *gil = &tstate->interp->ceval.gil;
+#else
struct _gil_runtime_state *gil = &tstate->interp->runtime->ceval.gil;
+#endif
assert(!gil_created(gil));
PyThread_init_thread();
void
_PyEval_FiniGIL(PyThreadState *tstate)
{
+#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
if (!_Py_IsMainInterpreter(tstate)) {
/* Currently, the GIL is shared by all interpreters,
and only the main interpreter is responsible to create
and destroy it. */
return;
}
+#endif
+#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
+ struct _gil_runtime_state *gil = &tstate->interp->ceval.gil;
+#else
struct _gil_runtime_state *gil = &tstate->interp->runtime->ceval.gil;
+#endif
if (!gil_created(gil)) {
/* First Py_InitializeFromConfig() call: the GIL doesn't exist
yet: do nothing. */
void
_PyEval_ReInitThreads(_PyRuntimeState *runtime)
{
+ PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
+ ensure_tstate_not_null(__func__, tstate);
+
+#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
+ struct _gil_runtime_state *gil = &tstate->interp->ceval.gil;
+#else
struct _gil_runtime_state *gil = &runtime->ceval.gil;
+#endif
if (!gil_created(gil)) {
return;
}
recreate_gil(gil);
- PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
- ensure_tstate_not_null(__func__, tstate);
take_gil(tstate);
struct _ceval_runtime_state *ceval = &runtime->ceval;
struct _ceval_state *ceval2 = &tstate->interp->ceval;
+#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
+ assert(gil_created(&ceval2->gil));
+#else
assert(gil_created(&ceval->gil));
+#endif
drop_gil(ceval, ceval2, tstate);
return tstate;
}
_PyEval_InitRuntimeState(struct _ceval_runtime_state *ceval)
{
_Py_CheckRecursionLimit = Py_DEFAULT_RECURSION_LIMIT;
+#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
_gil_initialize(&ceval->gil);
+#endif
}
int
if (pending->lock == NULL) {
return -1;
}
+
+#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
+ _gil_initialize(&ceval->gil);
+#endif
+
return 0;
}
drop_gil(struct _ceval_runtime_state *ceval, struct _ceval_state *ceval2,
PyThreadState *tstate)
{
+#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
+ struct _gil_runtime_state *gil = &ceval2->gil;
+#else
struct _gil_runtime_state *gil = &ceval->gil;
+#endif
if (!_Py_atomic_load_relaxed(&gil->locked)) {
Py_FatalError("drop_gil: GIL is not locked");
}
PyInterpreterState *interp = tstate->interp;
struct _ceval_runtime_state *ceval = &interp->runtime->ceval;
struct _ceval_state *ceval2 = &interp->ceval;
+#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
+ struct _gil_runtime_state *gil = &ceval2->gil;
+#else
struct _gil_runtime_state *gil = &ceval->gil;
+#endif
/* Check that _PyEval_InitThreads() was called to create the lock */
assert(gil_created(gil));
void _PyEval_SetSwitchInterval(unsigned long microseconds)
{
- _PyRuntime.ceval.gil.interval = microseconds;
+#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
+ PyInterpreterState *interp = PyInterpreterState_Get();
+ struct _gil_runtime_state *gil = &interp->ceval.gil;
+#else
+ struct _gil_runtime_state *gil = &_PyRuntime.ceval.gil;
+#endif
+ gil->interval = microseconds;
}
unsigned long _PyEval_GetSwitchInterval()
{
- return _PyRuntime.ceval.gil.interval;
+#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
+ PyInterpreterState *interp = PyInterpreterState_Get();
+ struct _gil_runtime_state *gil = &interp->ceval.gil;
+#else
+ struct _gil_runtime_state *gil = &_PyRuntime.ceval.gil;
+#endif
+ return gil->interval;
}