summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaan Leijen <daan@microsoft.com>2022-01-10 16:07:22 -0800
committerDaan Leijen <daan@microsoft.com>2022-01-10 16:07:22 -0800
commit320f95f6cdc9b73e7cbb9acf37e0948f545ecdd0 (patch)
tree48359b149ad36630d048391b32c7bb0c4810b69a /src
parent5bc9a1c95f5d058af707543b9220ed6e4156de15 (diff)
further fixes to allow statically linking mimalloc in DLL modules (issue #508)
Diffstat (limited to 'src')
-rw-r--r--src/init.c22
-rw-r--r--src/region.c2
2 files changed, 11 insertions, 13 deletions
diff --git a/src/init.c b/src/init.c
index e69208d..1f1b272 100644
--- a/src/init.c
+++ b/src/init.c
@@ -493,14 +493,14 @@ 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 the FLS cleanup happens to early for the main thread.
- * To avoid that set the FLS value for the main thread to NULL; the eventual
- * mi_fls_done() execution won't call _mi_thread_done().
- * The latter function is later called explicitly from mi_process_done().
- * See GitHub issue #508 for more background and explanation. */
+
+ #if defined(_WIN32) && !defined(MI_SHARED_LIB)
+ // When building as a static lib the FLS cleanup happens to early for the main thread.
+ // To avoid this, set the FLS value for the main thread to NULL so the fls cleanup
+ // will not call _mi_thread_done on the (still executing) main thread. See issue #508.
FlsSetValue(mi_fls_key, NULL);
-#endif
+ #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)) {
@@ -530,9 +530,7 @@ static void mi_process_done(void) {
process_done = true;
#if defined(_WIN32) && !defined(MI_SHARED_LIB)
- // Explicitly clean up main thread. See comment in mi_process_init() for reason
- _mi_thread_done(_mi_heap_default);
- 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 (except the main thread) to prevent dangling callback pointer if statically linked with a DLL; Issue #208
#endif
#if (MI_DEBUG != 0) || !defined(MI_SHARED_LIB)
@@ -573,7 +571,7 @@ static void mi_process_done(void) {
mi_process_load();
return 0;
}
- typedef int(*_crt_cb)(void);
+ typedef int(*_mi_crt_callback_t)(void);
#if defined(_M_X64) || defined(_M_ARM64)
__pragma(comment(linker, "/include:" "_mi_msvc_initu"))
#pragma section(".CRT$XIU", long, read)
@@ -581,7 +579,7 @@ static void mi_process_done(void) {
__pragma(comment(linker, "/include:" "__mi_msvc_initu"))
#endif
#pragma data_seg(".CRT$XIU")
- extern "C" _crt_cb _mi_msvc_initu[] = { &_mi_process_init };
+ extern "C" _mi_crt_callback_t _mi_msvc_initu[] = { &_mi_process_init };
#pragma data_seg()
#elif defined(__cplusplus)
diff --git a/src/region.c b/src/region.c
index f864f73..2d73025 100644
--- a/src/region.c
+++ b/src/region.c
@@ -94,7 +94,7 @@ typedef struct mem_region_s {
mi_bitmap_field_t commit; // track if committed per block
mi_bitmap_field_t reset; // track if reset per block
_Atomic(size_t) arena_memid; // if allocated from a (huge page) arena
- size_t padding; // round to 8 fields
+ _Atomic(size_t) padding; // round to 8 fields (needs to be atomic for msvc, see issue #508)
} mem_region_t;
// The region map