mirror of
https://github.com/python/cpython.git
synced 2024-11-25 02:44:06 +08:00
bpo-39984: Pass tstate to handle_signals() (GH-19050)
handle_signals() and make_pending_calls() now expect tstate rather than runtime.
This commit is contained in:
parent
2fe815edd6
commit
d7fabc1162
@ -506,8 +506,10 @@ Py_AddPendingCall(int (*func)(void *), void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
handle_signals(_PyRuntimeState *runtime)
|
handle_signals(PyThreadState *tstate)
|
||||||
{
|
{
|
||||||
|
_PyRuntimeState *runtime = tstate->interp->runtime;
|
||||||
|
|
||||||
/* Only handle signals on main thread */
|
/* Only handle signals on main thread */
|
||||||
if (PyThread_get_thread_ident() != runtime->main_thread) {
|
if (PyThread_get_thread_ident() != runtime->main_thread) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -516,7 +518,7 @@ handle_signals(_PyRuntimeState *runtime)
|
|||||||
* Ensure that the thread isn't currently running some other
|
* Ensure that the thread isn't currently running some other
|
||||||
* interpreter.
|
* interpreter.
|
||||||
*/
|
*/
|
||||||
PyInterpreterState *interp = _PyRuntimeState_GetThreadState(runtime)->interp;
|
PyInterpreterState *interp = tstate->interp;
|
||||||
if (interp != runtime->interpreters.main) {
|
if (interp != runtime->interpreters.main) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -531,10 +533,12 @@ handle_signals(_PyRuntimeState *runtime)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
make_pending_calls(_PyRuntimeState *runtime)
|
make_pending_calls(PyThreadState *tstate)
|
||||||
{
|
{
|
||||||
static int busy = 0;
|
static int busy = 0;
|
||||||
|
|
||||||
|
_PyRuntimeState *runtime = tstate->interp->runtime;
|
||||||
|
|
||||||
/* only service pending calls on main thread */
|
/* only service pending calls on main thread */
|
||||||
if (PyThread_get_thread_ident() != runtime->main_thread) {
|
if (PyThread_get_thread_ident() != runtime->main_thread) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -586,8 +590,7 @@ _Py_FinishPendingCalls(PyThreadState *tstate)
|
|||||||
{
|
{
|
||||||
assert(PyGILState_Check());
|
assert(PyGILState_Check());
|
||||||
|
|
||||||
_PyRuntimeState *runtime = tstate->interp->runtime;
|
struct _pending_calls *pending = &tstate->interp->runtime->ceval.pending;
|
||||||
struct _pending_calls *pending = &runtime->ceval.pending;
|
|
||||||
|
|
||||||
PyThread_acquire_lock(pending->lock, WAIT_LOCK);
|
PyThread_acquire_lock(pending->lock, WAIT_LOCK);
|
||||||
pending->finishing = 1;
|
pending->finishing = 1;
|
||||||
@ -597,7 +600,7 @@ _Py_FinishPendingCalls(PyThreadState *tstate)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (make_pending_calls(runtime) < 0) {
|
if (make_pending_calls(tstate) < 0) {
|
||||||
PyObject *exc, *val, *tb;
|
PyObject *exc, *val, *tb;
|
||||||
_PyErr_Fetch(tstate, &exc, &val, &tb);
|
_PyErr_Fetch(tstate, &exc, &val, &tb);
|
||||||
PyErr_BadInternalCall();
|
PyErr_BadInternalCall();
|
||||||
@ -613,15 +616,16 @@ Py_MakePendingCalls(void)
|
|||||||
{
|
{
|
||||||
assert(PyGILState_Check());
|
assert(PyGILState_Check());
|
||||||
|
|
||||||
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
|
|
||||||
/* Python signal handler doesn't really queue a callback: it only signals
|
/* Python signal handler doesn't really queue a callback: it only signals
|
||||||
that a signal was received, see _PyEval_SignalReceived(). */
|
that a signal was received, see _PyEval_SignalReceived(). */
|
||||||
_PyRuntimeState *runtime = &_PyRuntime;
|
int res = handle_signals(tstate);
|
||||||
int res = handle_signals(runtime);
|
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = make_pending_calls(runtime);
|
res = make_pending_calls(tstate);
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -1231,12 +1235,12 @@ main_loop:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_Py_atomic_load_relaxed(&ceval->signals_pending)) {
|
if (_Py_atomic_load_relaxed(&ceval->signals_pending)) {
|
||||||
if (handle_signals(runtime) != 0) {
|
if (handle_signals(tstate) != 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_Py_atomic_load_relaxed(&ceval->pending.calls_to_do)) {
|
if (_Py_atomic_load_relaxed(&ceval->pending.calls_to_do)) {
|
||||||
if (make_pending_calls(runtime) != 0) {
|
if (make_pending_calls(tstate) != 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user