summaryrefslogtreecommitdiffstats
path: root/Python/pystate.c
diff options
context:
space:
mode:
authorDonghee Na <donghee.na@python.org>2024-01-09 23:04:41 (GMT)
committerGitHub <noreply@github.com>2024-01-09 23:04:41 (GMT)
commit57bdc6c30d2665c2760ff5a88487e57c8b3c397a (patch)
treede5a4efb2a25eac14672c6a538ca6e50ae7ed582 /Python/pystate.c
parentcdca0ce0ad47604b7007229415817a7a152f7f9a (diff)
downloadcpython-57bdc6c30d2665c2760ff5a88487e57c8b3c397a.zip
cpython-57bdc6c30d2665c2760ff5a88487e57c8b3c397a.tar.gz
cpython-57bdc6c30d2665c2760ff5a88487e57c8b3c397a.tar.bz2
gh-111968: Introduce _PyFreeListState and _PyFreeListState_GET API (gh-113584)
Diffstat (limited to 'Python/pystate.c')
-rw-r--r--Python/pystate.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index 21f16b7..ddd57f7 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -1456,6 +1456,12 @@ clear_datastack(PyThreadState *tstate)
}
void
+_Py_ClearFreeLists(_PyFreeListState *state, int is_finalization)
+{
+ _PyList_ClearFreeList(state, is_finalization);
+}
+
+void
PyThreadState_Clear(PyThreadState *tstate)
{
assert(tstate->_status.initialized && !tstate->_status.cleared);
@@ -1537,6 +1543,11 @@ PyThreadState_Clear(PyThreadState *tstate)
// don't call _PyInterpreterState_SetNotRunningMain() yet.
tstate->on_delete(tstate->on_delete_data);
}
+#ifdef Py_GIL_DISABLED
+ // Each thread should clear own freelists in free-threading builds.
+ _PyFreeListState *freelist_state = &((_PyThreadStateImpl*)tstate)->freelist_state;
+ _Py_ClearFreeLists(freelist_state, 0);
+#endif
_PyThreadState_ClearMimallocHeaps(tstate);