summaryrefslogtreecommitdiffstats
path: root/Python/ceval_gil.h
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-04-08 21:35:05 (GMT)
committerGitHub <noreply@github.com>2020-04-08 21:35:05 (GMT)
commitb54a99d6432de93de85be2b42a63774f8b4581a0 (patch)
tree59e273ca69f89e6c7eedf91f458ee3cc50eb7cf8 /Python/ceval_gil.h
parentcfc3c2f8b34d3864717ab584c5b6c260014ba55a (diff)
downloadcpython-b54a99d6432de93de85be2b42a63774f8b4581a0.zip
cpython-b54a99d6432de93de85be2b42a63774f8b4581a0.tar.gz
cpython-b54a99d6432de93de85be2b42a63774f8b4581a0.tar.bz2
bpo-40082: trip_signal() uses the main interpreter (GH-19441)
Fix the signal handler: it now always uses the main interpreter, rather than trying to get the current Python thread state. The following function now accepts an interpreter, instead of a Python thread state: * _PyEval_SignalReceived() * _Py_ThreadCanHandleSignals() * _PyEval_AddPendingCall() * COMPUTE_EVAL_BREAKER() * SET_GIL_DROP_REQUEST(), RESET_GIL_DROP_REQUEST() * SIGNAL_PENDING_CALLS(), UNSIGNAL_PENDING_CALLS() * SIGNAL_PENDING_SIGNALS(), UNSIGNAL_PENDING_SIGNALS() * SIGNAL_ASYNC_EXC(), UNSIGNAL_ASYNC_EXC() Py_AddPendingCall() now uses the main interpreter if it fails to the current Python thread state. Convert _PyThreadState_GET() and PyInterpreterState_GET_UNSAFE() macros to static inline functions.
Diffstat (limited to 'Python/ceval_gil.h')
-rw-r--r--Python/ceval_gil.h16
1 files changed, 10 insertions, 6 deletions
diff --git a/Python/ceval_gil.h b/Python/ceval_gil.h
index b9e48a5..a025a9f 100644
--- a/Python/ceval_gil.h
+++ b/Python/ceval_gil.h
@@ -168,7 +168,8 @@ drop_gil(struct _ceval_runtime_state *ceval, PyThreadState *tstate)
/* Not switched yet => wait */
if (((PyThreadState*)_Py_atomic_load_relaxed(&gil->last_holder)) == tstate)
{
- RESET_GIL_DROP_REQUEST(tstate);
+ assert(is_tstate_valid(tstate));
+ RESET_GIL_DROP_REQUEST(tstate->interp);
/* NOTE: if COND_WAIT does not atomically start waiting when
releasing the mutex, another thread can run through, take
the GIL and drop it again, and reset the condition
@@ -223,7 +224,8 @@ take_gil(PyThreadState *tstate)
}
assert(is_tstate_valid(tstate));
- struct _ceval_runtime_state *ceval = &tstate->interp->runtime->ceval;
+ PyInterpreterState *interp = tstate->interp;
+ struct _ceval_runtime_state *ceval = &interp->runtime->ceval;
struct _gil_runtime_state *gil = &ceval->gil;
/* Check that _PyEval_InitThreads() was called to create the lock */
@@ -252,8 +254,9 @@ take_gil(PyThreadState *tstate)
MUTEX_UNLOCK(gil->mutex);
PyThread_exit_thread();
}
+ assert(is_tstate_valid(tstate));
- SET_GIL_DROP_REQUEST(tstate);
+ SET_GIL_DROP_REQUEST(interp);
}
}
@@ -289,9 +292,10 @@ _ready:
drop_gil(ceval, tstate);
PyThread_exit_thread();
}
+ assert(is_tstate_valid(tstate));
if (_Py_atomic_load_relaxed(&ceval->gil_drop_request)) {
- RESET_GIL_DROP_REQUEST(tstate);
+ RESET_GIL_DROP_REQUEST(interp);
}
else {
/* bpo-40010: eval_breaker should be recomputed to be set to 1 if there
@@ -299,8 +303,8 @@ _ready:
handle signals.
Note: RESET_GIL_DROP_REQUEST() calls COMPUTE_EVAL_BREAKER(). */
- struct _ceval_state *ceval2 = &tstate->interp->ceval;
- COMPUTE_EVAL_BREAKER(tstate, ceval, ceval2);
+ struct _ceval_state *ceval2 = &interp->ceval;
+ COMPUTE_EVAL_BREAKER(interp, ceval, ceval2);
}
/* Don't access tstate if the thread must exit */