mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-07-01 17:24:38 +03:00
do not automatically call mi_process_done if mi_option_destroy_on_exit > 1
This commit is contained in:
parent
e7cbbbfb14
commit
c1249a4b15
4 changed files with 25 additions and 25 deletions
|
@ -135,8 +135,8 @@ static inline uintptr_t _mi_random_shuffle(uintptr_t x);
|
||||||
// init.c
|
// init.c
|
||||||
extern mi_decl_hidden mi_decl_cache_align mi_stats_t _mi_stats_main;
|
extern mi_decl_hidden mi_decl_cache_align mi_stats_t _mi_stats_main;
|
||||||
extern mi_decl_hidden mi_decl_cache_align const mi_page_t _mi_page_empty;
|
extern mi_decl_hidden mi_decl_cache_align const mi_page_t _mi_page_empty;
|
||||||
void _mi_process_load(void);
|
void _mi_auto_process_init(void);
|
||||||
void mi_cdecl _mi_process_done(void);
|
void mi_cdecl _mi_auto_process_done(void) mi_attr_noexcept;
|
||||||
bool _mi_is_redirected(void);
|
bool _mi_is_redirected(void);
|
||||||
bool _mi_allocator_init(const char** message);
|
bool _mi_allocator_init(const char** message);
|
||||||
void _mi_allocator_done(void);
|
void _mi_allocator_done(void);
|
||||||
|
|
12
src/init.c
12
src/init.c
|
@ -555,7 +555,7 @@ mi_decl_nodiscard bool mi_is_redirected(void) mi_attr_noexcept {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called once by the process loader from `src/prim/prim.c`
|
// Called once by the process loader from `src/prim/prim.c`
|
||||||
void _mi_process_load(void) {
|
void _mi_auto_process_init(void) {
|
||||||
mi_heap_main_init();
|
mi_heap_main_init();
|
||||||
#if defined(__APPLE__) || defined(MI_TLS_RECURSE_GUARD)
|
#if defined(__APPLE__) || defined(MI_TLS_RECURSE_GUARD)
|
||||||
volatile mi_heap_t* dummy = _mi_heap_default; // access TLS to allocate it before setting tls_initialized to true;
|
volatile mi_heap_t* dummy = _mi_heap_default; // access TLS to allocate it before setting tls_initialized to true;
|
||||||
|
@ -642,12 +642,8 @@ void mi_process_init(void) mi_attr_noexcept {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mi_cdecl mi_process_done(void) mi_attr_noexcept {
|
|
||||||
_mi_process_done();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called when the process is done (cdecl as it is used with `at_exit` on some platforms)
|
// Called when the process is done (cdecl as it is used with `at_exit` on some platforms)
|
||||||
void mi_cdecl _mi_process_done(void) {
|
void mi_cdecl mi_process_done(void) mi_attr_noexcept {
|
||||||
// only shutdown if we were initialized
|
// only shutdown if we were initialized
|
||||||
if (!_mi_process_is_initialized) return;
|
if (!_mi_process_is_initialized) return;
|
||||||
// ensure we are called once
|
// ensure we are called once
|
||||||
|
@ -690,3 +686,7 @@ void mi_cdecl _mi_process_done(void) {
|
||||||
os_preloading = true; // don't call the C runtime anymore
|
os_preloading = true; // don't call the C runtime anymore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mi_cdecl _mi_auto_process_done(void) mi_attr_noexcept {
|
||||||
|
if (_mi_option_get_fast(mi_option_destroy_on_exit)>1) return;
|
||||||
|
mi_process_done();
|
||||||
|
}
|
||||||
|
|
|
@ -39,25 +39,25 @@ terms of the MIT license. A copy of the license can be found in the file
|
||||||
#define mi_attr_destructor __attribute__((destructor))
|
#define mi_attr_destructor __attribute__((destructor))
|
||||||
#endif
|
#endif
|
||||||
static void mi_attr_constructor mi_process_attach(void) {
|
static void mi_attr_constructor mi_process_attach(void) {
|
||||||
_mi_process_load();
|
_mi_auto_process_init();
|
||||||
}
|
}
|
||||||
static void mi_attr_destructor mi_process_detach(void) {
|
static void mi_attr_destructor mi_process_detach(void) {
|
||||||
_mi_process_done();
|
_mi_auto_process_done();
|
||||||
}
|
}
|
||||||
#elif defined(__cplusplus)
|
#elif defined(__cplusplus)
|
||||||
// C++: use static initialization to detect process start/end
|
// C++: use static initialization to detect process start/end
|
||||||
// This is not guaranteed to be first/last but the best we can generally do?
|
// This is not guaranteed to be first/last but the best we can generally do?
|
||||||
struct mi_init_done_t {
|
struct mi_init_done_t {
|
||||||
mi_init_done_t() {
|
mi_init_done_t() {
|
||||||
_mi_process_load();
|
_mi_auto_process_init();
|
||||||
}
|
}
|
||||||
~mi_init_done_t() {
|
~mi_init_done_t() {
|
||||||
_mi_process_done();
|
_mi_auto_process_done();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static mi_init_done_t mi_init_done;
|
static mi_init_done_t mi_init_done;
|
||||||
#else
|
#else
|
||||||
#pragma message("define a way to call _mi_process_load/done on your platform")
|
#pragma message("define a way to call _mi_auto_process_init/done on your platform")
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -669,10 +669,10 @@ static void NTAPI mi_win_main(PVOID module, DWORD reason, LPVOID reserved) {
|
||||||
MI_UNUSED(module);
|
MI_UNUSED(module);
|
||||||
mi_win_tls_init(reason);
|
mi_win_tls_init(reason);
|
||||||
if (reason==DLL_PROCESS_ATTACH) {
|
if (reason==DLL_PROCESS_ATTACH) {
|
||||||
_mi_process_load();
|
_mi_auto_process_init();
|
||||||
}
|
}
|
||||||
else if (reason==DLL_PROCESS_DETACH) {
|
else if (reason==DLL_PROCESS_DETACH) {
|
||||||
_mi_process_done();
|
_mi_auto_process_done();
|
||||||
}
|
}
|
||||||
else if (reason==DLL_THREAD_DETACH && !_mi_is_redirected()) {
|
else if (reason==DLL_THREAD_DETACH && !_mi_is_redirected()) {
|
||||||
_mi_thread_done(NULL);
|
_mi_thread_done(NULL);
|
||||||
|
@ -762,7 +762,7 @@ static void NTAPI mi_win_main(PVOID module, DWORD reason, LPVOID reserved) {
|
||||||
|
|
||||||
static int mi_process_attach(void) {
|
static int mi_process_attach(void) {
|
||||||
mi_win_main(NULL,DLL_PROCESS_ATTACH,NULL);
|
mi_win_main(NULL,DLL_PROCESS_ATTACH,NULL);
|
||||||
atexit(&_mi_process_done);
|
atexit(&_mi_auto_process_done);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
typedef int(*mi_crt_callback_t)(void);
|
typedef int(*mi_crt_callback_t)(void);
|
||||||
|
|
Loading…
Add table
Reference in a new issue