mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-59956: Allow the "Trashcan" Mechanism to Work Without a Thread State (gh-101209)
We've factored out a struct from the two PyThreadState fields. This accomplishes two things: * make it clear that the trashcan-related code doesn't need any other parts of PyThreadState * allows us to use the trashcan mechanism even when there isn't a "current" thread state We still expect the caller to hold the GIL. https://github.com/python/cpython/issues/59956
This commit is contained in:
parent
984387f39a
commit
7b20a0f55a
5 changed files with 92 additions and 24 deletions
|
@ -400,6 +400,11 @@ _PyRuntimeState_Init(_PyRuntimeState *runtime)
|
|||
return status;
|
||||
}
|
||||
|
||||
if (PyThread_tss_create(&runtime->trashTSSkey) != 0) {
|
||||
_PyRuntimeState_Fini(runtime);
|
||||
return _PyStatus_NO_MEMORY();
|
||||
}
|
||||
|
||||
init_runtime(runtime, open_code_hook, open_code_userdata, audit_hook_head,
|
||||
unicode_next_index, lock1, lock2, lock3, lock4);
|
||||
|
||||
|
@ -413,6 +418,10 @@ _PyRuntimeState_Fini(_PyRuntimeState *runtime)
|
|||
current_tss_fini(runtime);
|
||||
}
|
||||
|
||||
if (PyThread_tss_is_created(&runtime->trashTSSkey)) {
|
||||
PyThread_tss_delete(&runtime->trashTSSkey);
|
||||
}
|
||||
|
||||
/* Force the allocator used by _PyRuntimeState_Init(). */
|
||||
PyMemAllocatorEx old_alloc;
|
||||
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
|
||||
|
@ -471,6 +480,13 @@ _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime)
|
|||
return status;
|
||||
}
|
||||
|
||||
if (PyThread_tss_is_created(&runtime->trashTSSkey)) {
|
||||
PyThread_tss_delete(&runtime->trashTSSkey);
|
||||
}
|
||||
if (PyThread_tss_create(&runtime->trashTSSkey) != 0) {
|
||||
return _PyStatus_NO_MEMORY();
|
||||
}
|
||||
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue