Skip to content

Commit ebd5980

Browse files
committed
Extract tstate_from_heap helper in obmalloc.c
1 parent 4d059c9 commit ebd5980

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

Objects/obmalloc.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ should_advance_qsbr_for_page(struct _qsbr_thread_state *qsbr, mi_page_t *page)
153153
}
154154
#endif
155155

156+
static _PyThreadStateImpl *
157+
tstate_from_heap(mi_heap_t *heap)
158+
{
159+
return _Py_CONTAINER_OF(heap->tld, _PyThreadStateImpl, mimalloc.tld);
160+
}
161+
156162
static bool
157163
_PyMem_mi_page_maybe_free(mi_page_t *page, mi_page_queue_t *pq, bool force)
158164
{
@@ -187,8 +193,7 @@ _PyMem_mi_page_maybe_free(mi_page_t *page, mi_page_queue_t *pq, bool force)
187193

188194
// We may be freeing a page belonging to a different thread during a
189195
// stop-the-world event. Find the _PyThreadStateImpl for the page.
190-
mi_heap_t *heap = mi_page_heap(page);
191-
_PyThreadStateImpl *tstate = _Py_CONTAINER_OF(heap->tld, _PyThreadStateImpl, mimalloc.tld);
196+
_PyThreadStateImpl *tstate = tstate_from_heap(mi_page_heap(page));
192197
llist_insert_tail(&tstate->mimalloc.page_list, &page->qsbr_node);
193198
return false;
194199
}
@@ -205,7 +210,8 @@ _PyMem_mi_page_reclaimed(mi_page_t *page)
205210
if (page->qsbr_goal != 0) {
206211
if (mi_page_all_free(page)) {
207212
assert(page->qsbr_node.next == NULL);
208-
_PyThreadStateImpl *tstate = (_PyThreadStateImpl *)PyThreadState_GET();
213+
_PyThreadStateImpl *tstate = tstate_from_heap(mi_page_heap(page));
214+
assert(tstate == (_PyThreadStateImpl *)_PyThreadState_GET());
209215
page->retire_expire = 0;
210216
llist_insert_tail(&tstate->mimalloc.page_list, &page->qsbr_node);
211217
}

0 commit comments

Comments
 (0)