mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-36818: Add PyInterpreterState.runtime field. (gh-13129)
https://bugs.python.org/issue36818
This commit is contained in:
parent
1c263e39c4
commit
396e0a8d9d
11 changed files with 99 additions and 103 deletions
|
@ -217,8 +217,9 @@ _PyEval_FiniThreads(struct _ceval_runtime_state *ceval)
|
|||
}
|
||||
|
||||
static inline void
|
||||
exit_thread_if_finalizing(_PyRuntimeState *runtime, PyThreadState *tstate)
|
||||
exit_thread_if_finalizing(PyThreadState *tstate)
|
||||
{
|
||||
_PyRuntimeState *runtime = tstate->interp->runtime;
|
||||
/* _Py_Finalizing is protected by the GIL */
|
||||
if (runtime->finalizing != NULL && !_Py_CURRENTLY_FINALIZING(runtime, tstate)) {
|
||||
drop_gil(&runtime->ceval, tstate);
|
||||
|
@ -236,7 +237,7 @@ PyEval_AcquireLock(void)
|
|||
Py_FatalError("PyEval_AcquireLock: current thread state is NULL");
|
||||
}
|
||||
take_gil(ceval, tstate);
|
||||
exit_thread_if_finalizing(runtime, tstate);
|
||||
exit_thread_if_finalizing(tstate);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -257,14 +258,15 @@ PyEval_AcquireThread(PyThreadState *tstate)
|
|||
if (tstate == NULL) {
|
||||
Py_FatalError("PyEval_AcquireThread: NULL new thread state");
|
||||
}
|
||||
assert(tstate->interp != NULL);
|
||||
|
||||
_PyRuntimeState *runtime = &_PyRuntime;
|
||||
_PyRuntimeState *runtime = tstate->interp->runtime;
|
||||
struct _ceval_runtime_state *ceval = &runtime->ceval;
|
||||
|
||||
/* Check someone has called PyEval_InitThreads() to create the lock */
|
||||
assert(gil_created(&ceval->gil));
|
||||
take_gil(ceval, tstate);
|
||||
exit_thread_if_finalizing(runtime, tstate);
|
||||
exit_thread_if_finalizing(tstate);
|
||||
if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
|
||||
Py_FatalError("PyEval_AcquireThread: non-NULL old thread state");
|
||||
}
|
||||
|
@ -276,8 +278,9 @@ PyEval_ReleaseThread(PyThreadState *tstate)
|
|||
if (tstate == NULL) {
|
||||
Py_FatalError("PyEval_ReleaseThread: NULL thread state");
|
||||
}
|
||||
assert(tstate->interp != NULL);
|
||||
|
||||
_PyRuntimeState *runtime = &_PyRuntime;
|
||||
_PyRuntimeState *runtime = tstate->interp->runtime;
|
||||
PyThreadState *new_tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
|
||||
if (new_tstate != tstate) {
|
||||
Py_FatalError("PyEval_ReleaseThread: wrong thread state");
|
||||
|
@ -308,7 +311,7 @@ _PyEval_ReInitThreads(_PyRuntimeState *runtime)
|
|||
}
|
||||
|
||||
/* Destroy all threads except the current one */
|
||||
_PyThreadState_DeleteExcept(runtime, current_tstate);
|
||||
_PyThreadState_DeleteExcept(current_tstate);
|
||||
}
|
||||
|
||||
/* This function is used to signal that async exceptions are waiting to be
|
||||
|
@ -337,17 +340,18 @@ PyEval_SaveThread(void)
|
|||
void
|
||||
PyEval_RestoreThread(PyThreadState *tstate)
|
||||
{
|
||||
_PyRuntimeState *runtime = &_PyRuntime;
|
||||
struct _ceval_runtime_state *ceval = &runtime->ceval;
|
||||
|
||||
if (tstate == NULL) {
|
||||
Py_FatalError("PyEval_RestoreThread: NULL tstate");
|
||||
}
|
||||
assert(tstate->interp != NULL);
|
||||
|
||||
_PyRuntimeState *runtime = tstate->interp->runtime;
|
||||
struct _ceval_runtime_state *ceval = &runtime->ceval;
|
||||
assert(gil_created(&ceval->gil));
|
||||
|
||||
int err = errno;
|
||||
take_gil(ceval, tstate);
|
||||
exit_thread_if_finalizing(runtime, tstate);
|
||||
exit_thread_if_finalizing(tstate);
|
||||
errno = err;
|
||||
|
||||
_PyThreadState_Swap(&runtime->gilstate, tstate);
|
||||
|
@ -1141,7 +1145,7 @@ main_loop:
|
|||
take_gil(ceval, tstate);
|
||||
|
||||
/* Check if we should make a quick exit. */
|
||||
exit_thread_if_finalizing(runtime, tstate);
|
||||
exit_thread_if_finalizing(tstate);
|
||||
|
||||
if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
|
||||
Py_FatalError("ceval: orphan tstate");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue