summaryrefslogtreecommitdiffstats
path: root/Python/gc_free_threading.c
diff options
context:
space:
mode:
authorBrett Simmers <swtaarrs@users.noreply.github.com>2024-02-20 14:57:48 (GMT)
committerGitHub <noreply@github.com>2024-02-20 14:57:48 (GMT)
commit0749244d13412d7cb5b53d834f586f2198f5b9a6 (patch)
tree06387c5b41cd14cdf230f71eab6fd92873c3d5a9 /Python/gc_free_threading.c
parente71468ba4f5fb2da0cefe9e923b01811cb53fb5f (diff)
downloadcpython-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 'Python/gc_free_threading.c')
-rw-r--r--Python/gc_free_threading.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/Python/gc_free_threading.c b/Python/gc_free_threading.c
index a758c99..2993ef4 100644
--- a/Python/gc_free_threading.c
+++ b/Python/gc_free_threading.c
@@ -981,7 +981,7 @@ record_allocation(PyThreadState *tstate)
if (gc_should_collect(gcstate) &&
!_Py_atomic_load_int_relaxed(&gcstate->collecting))
{
- _Py_ScheduleGC(tstate->interp);
+ _Py_ScheduleGC(tstate);
}
}
}
@@ -1564,9 +1564,12 @@ PyObject_IS_GC(PyObject *obj)
}
void
-_Py_ScheduleGC(PyInterpreterState *interp)
+_Py_ScheduleGC(PyThreadState *tstate)
{
- _Py_set_eval_breaker_bit(interp, _PY_GC_SCHEDULED_BIT, 1);
+ if (!_Py_eval_breaker_bit_is_set(tstate, _PY_GC_SCHEDULED_BIT))
+ {
+ _Py_set_eval_breaker_bit(tstate, _PY_GC_SCHEDULED_BIT);
+ }
}
void