diff options
author | Brett Simmers <swtaarrs@users.noreply.github.com> | 2024-02-20 14:57:48 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-20 14:57:48 (GMT) |
commit | 0749244d13412d7cb5b53d834f586f2198f5b9a6 (patch) | |
tree | 06387c5b41cd14cdf230f71eab6fd92873c3d5a9 /Modules | |
parent | e71468ba4f5fb2da0cefe9e923b01811cb53fb5f (diff) | |
download | cpython-0749244d13412d7cb5b53d834f586f2198f5b9a6.zip cpython-0749244d13412d7cb5b53d834f586f2198f5b9a6.tar.gz cpython-0749244d13412d7cb5b53d834f586f2198f5b9a6.tar.bz2 |
gh-112175: Add `eval_breaker` to `PyThreadState` (#115194)
This change adds an `eval_breaker` field to `PyThreadState`. The primary
motivation is for performance in free-threaded builds: with thread-local eval
breakers, we can stop a specific thread (e.g., for an async exception) without
interrupting other threads.
The source of truth for the global instrumentation version is stored in the
`instrumentation_version` field in PyInterpreterState. Threads usually read the
version from their local `eval_breaker`, where it continues to be colocated
with the eval breaker bits.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/signalmodule.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 394a997..652e69b 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -276,11 +276,7 @@ trip_signal(int sig_num) cleared in PyErr_CheckSignals() before .tripped. */ _Py_atomic_store_int(&is_tripped, 1); - /* Signals are always handled by the main interpreter */ - PyInterpreterState *interp = _PyInterpreterState_Main(); - - /* Notify ceval.c */ - _PyEval_SignalReceived(interp); + _PyEval_SignalReceived(); /* And then write to the wakeup fd *after* setting all the globals and doing the _PyEval_SignalReceived. We used to write to the wakeup fd @@ -303,6 +299,7 @@ trip_signal(int sig_num) int fd = wakeup.fd; if (fd != INVALID_FD) { + PyInterpreterState *interp = _PyInterpreterState_Main(); unsigned char byte = (unsigned char)sig_num; #ifdef MS_WINDOWS if (wakeup.use_send) { @@ -1770,8 +1767,8 @@ PyErr_CheckSignals(void) Python code to ensure signals are handled. Checking for the GC here allows long running native code to clean cycles created using the C-API even if it doesn't run the evaluation loop */ - if (_Py_eval_breaker_bit_is_set(tstate->interp, _PY_GC_SCHEDULED_BIT)) { - _Py_set_eval_breaker_bit(tstate->interp, _PY_GC_SCHEDULED_BIT, 0); + if (_Py_eval_breaker_bit_is_set(tstate, _PY_GC_SCHEDULED_BIT)) { + _Py_unset_eval_breaker_bit(tstate, _PY_GC_SCHEDULED_BIT); _Py_RunGC(tstate); } |