mirror of
https://github.com/microsoft/mimalloc.git
synced 2024-12-28 05:50:51 +08:00
Perform thread cleanup for main threads as late as possible for Windows static builds
This commit is contained in:
parent
d24262f477
commit
f456bc75ea
@ -493,6 +493,11 @@ void mi_process_init(void) mi_attr_noexcept {
|
||||
#endif
|
||||
_mi_verbose_message("secure level: %d\n", MI_SECURE);
|
||||
mi_thread_init();
|
||||
#if defined(_WIN32) && !defined(MI_SHARED_LIB)
|
||||
// When building as a static lib FLS cleanup happens to early for the main thread.
|
||||
// Make it a no-op and perform it explicitly later.
|
||||
FlsSetValue(mi_fls_key, NULL);
|
||||
#endif
|
||||
mi_stats_reset(); // only call stat reset *after* thread init (or the heap tld == NULL)
|
||||
|
||||
if (mi_option_is_enabled(mi_option_reserve_huge_os_pages)) {
|
||||
@ -522,6 +527,8 @@ static void mi_process_done(void) {
|
||||
process_done = true;
|
||||
|
||||
#if defined(_WIN32) && !defined(MI_SHARED_LIB)
|
||||
// Explicitly clean up main thread
|
||||
_mi_thread_done(_mi_heap_default);
|
||||
FlsSetValue(mi_fls_key, NULL); // don't call main-thread callback
|
||||
FlsFree(mi_fls_key); // call thread-done on all threads to prevent dangling callback pointer if statically linked with a DLL; Issue #208
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user