mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-07-01 17:24:38 +03:00
Perform thread cleanup for main threads as late as possible for Windows static builds
This commit is contained in:
parent
d24262f477
commit
f456bc75ea
1 changed files with 7 additions and 0 deletions
|
@ -493,6 +493,11 @@ void mi_process_init(void) mi_attr_noexcept {
|
||||||
#endif
|
#endif
|
||||||
_mi_verbose_message("secure level: %d\n", MI_SECURE);
|
_mi_verbose_message("secure level: %d\n", MI_SECURE);
|
||||||
mi_thread_init();
|
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)
|
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)) {
|
if (mi_option_is_enabled(mi_option_reserve_huge_os_pages)) {
|
||||||
|
@ -522,6 +527,8 @@ static void mi_process_done(void) {
|
||||||
process_done = true;
|
process_done = true;
|
||||||
|
|
||||||
#if defined(_WIN32) && !defined(MI_SHARED_LIB)
|
#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
|
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
|
FlsFree(mi_fls_key); // call thread-done on all threads to prevent dangling callback pointer if statically linked with a DLL; Issue #208
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue