summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2024-11-21 18:08:38 (GMT)
committerGitHub <noreply@github.com>2024-11-21 18:08:38 (GMT)
commit9dabace39d118ec7a204b6970f8a3f475a11522c (patch)
treee03d07af2bcfcd399b993b1e0faf5dae67fc4e39 /Objects
parentbf542f8bb9f12f0df9481f2222b21545806dd9e1 (diff)
downloadcpython-9dabace39d118ec7a204b6970f8a3f475a11522c.zip
cpython-9dabace39d118ec7a204b6970f8a3f475a11522c.tar.gz
cpython-9dabace39d118ec7a204b6970f8a3f475a11522c.tar.bz2
gh-114940: Add _Py_FOR_EACH_TSTATE_UNLOCKED(), and Friends (gh-127077)
This is a precursor to the actual fix for gh-114940, where we will change these macros to use the new lock. This change is almost entirely mechanical; the exceptions are the loops in codeobject.c and ceval.c, which now hold the "head" lock. Note that almost all of the uses of _Py_FOR_EACH_TSTATE_UNLOCKED() here will change to _Py_FOR_EACH_TSTATE_BEGIN() once we add the new per-interpreter lock.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/codeobject.c6
-rw-r--r--Objects/object.c2
-rw-r--r--Objects/obmalloc.c2
3 files changed, 6 insertions, 4 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index ec5d8a5..148350c 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -2895,20 +2895,22 @@ get_indices_in_use(PyInterpreterState *interp, struct flag_set *in_use)
assert(interp->stoptheworld.world_stopped);
assert(in_use->flags == NULL);
int32_t max_index = 0;
- for (PyThreadState *p = interp->threads.head; p != NULL; p = p->next) {
+ _Py_FOR_EACH_TSTATE_BEGIN(interp, p) {
int32_t idx = ((_PyThreadStateImpl *) p)->tlbc_index;
if (idx > max_index) {
max_index = idx;
}
}
+ _Py_FOR_EACH_TSTATE_END(interp);
in_use->size = (size_t) max_index + 1;
in_use->flags = PyMem_Calloc(in_use->size, sizeof(*in_use->flags));
if (in_use->flags == NULL) {
return -1;
}
- for (PyThreadState *p = interp->threads.head; p != NULL; p = p->next) {
+ _Py_FOR_EACH_TSTATE_BEGIN(interp, p) {
in_use->flags[((_PyThreadStateImpl *) p)->tlbc_index] = 1;
}
+ _Py_FOR_EACH_TSTATE_END(interp);
return 0;
}
diff --git a/Objects/object.c b/Objects/object.c
index b115bc7..8868fa2 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -119,7 +119,7 @@ get_reftotal(PyInterpreterState *interp)
since we can't determine which interpreter updated it. */
Py_ssize_t total = REFTOTAL(interp);
#ifdef Py_GIL_DISABLED
- for (PyThreadState *p = interp->threads.head; p != NULL; p = p->next) {
+ _Py_FOR_EACH_TSTATE_UNLOCKED(interp, p) {
/* This may race with other threads modifications to their reftotal */
_PyThreadStateImpl *tstate_impl = (_PyThreadStateImpl *)p;
total += _Py_atomic_load_ssize_relaxed(&tstate_impl->reftotal);
diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c
index 3d6b1ab..2cc0377 100644
--- a/Objects/obmalloc.c
+++ b/Objects/obmalloc.c
@@ -1439,7 +1439,7 @@ get_mimalloc_allocated_blocks(PyInterpreterState *interp)
{
size_t allocated_blocks = 0;
#ifdef Py_GIL_DISABLED
- for (PyThreadState *t = interp->threads.head; t != NULL; t = t->next) {
+ _Py_FOR_EACH_TSTATE_UNLOCKED(interp, t) {
_PyThreadStateImpl *tstate = (_PyThreadStateImpl *)t;
for (int i = 0; i < _Py_MIMALLOC_HEAP_COUNT; i++) {
mi_heap_t *heap = &tstate->mimalloc.heaps[i];