diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2019-06-01 03:16:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-01 03:16:47 (GMT) |
commit | 396e0a8d9dc65453cb9d53500d0a620602656cfe (patch) | |
tree | e960fe3a38051fd3013bae7fd1b788ca94e9aeca /Python/ceval.c | |
parent | 1c263e39c4ed28225a7dc8ca1f24953225ac48ca (diff) | |
download | cpython-396e0a8d9dc65453cb9d53500d0a620602656cfe.zip cpython-396e0a8d9dc65453cb9d53500d0a620602656cfe.tar.gz cpython-396e0a8d9dc65453cb9d53500d0a620602656cfe.tar.bz2 |
bpo-36818: Add PyInterpreterState.runtime field. (gh-13129)
https://bugs.python.org/issue36818
Diffstat (limited to 'Python/ceval.c')
-rw-r--r-- | Python/ceval.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 71e6eb8..f9ff4e0 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -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"); |