Skip to content

Commit 4087acb

Browse files
committed
Merge branch 'dev' into dev2
2 parents 47c0f90 + c1249a4 commit 4087acb

File tree

5 files changed

+34
-26
lines changed

5 files changed

+34
-26
lines changed

include/mimalloc.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,20 @@ mi_decl_export void mi_stats_reset(void) mi_attr_noexcept;
154154
mi_decl_export void mi_stats_merge(void) mi_attr_noexcept;
155155
mi_decl_export void mi_stats_print(void* out) mi_attr_noexcept; // backward compatibility: `out` is ignored and should be NULL
156156
mi_decl_export void mi_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept;
157+
mi_decl_export void mi_thread_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept;
157158
mi_decl_export void mi_options_print(void) mi_attr_noexcept;
158159

160+
mi_decl_export void mi_process_info(size_t* elapsed_msecs, size_t* user_msecs, size_t* system_msecs,
161+
size_t* current_rss, size_t* peak_rss,
162+
size_t* current_commit, size_t* peak_commit, size_t* page_faults) mi_attr_noexcept;
163+
164+
165+
// Generally do not use the following as these are usually called automatically
159166
mi_decl_export void mi_process_init(void) mi_attr_noexcept;
167+
mi_decl_export void mi_cdecl mi_process_done(void) mi_attr_noexcept;
160168
mi_decl_export void mi_thread_init(void) mi_attr_noexcept;
161169
mi_decl_export void mi_thread_done(void) mi_attr_noexcept;
162-
mi_decl_export void mi_thread_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept;
163170

164-
mi_decl_export void mi_process_info(size_t* elapsed_msecs, size_t* user_msecs, size_t* system_msecs,
165-
size_t* current_rss, size_t* peak_rss,
166-
size_t* current_commit, size_t* peak_commit, size_t* page_faults) mi_attr_noexcept;
167171

168172
// -------------------------------------------------------------------------------------
169173
// Aligned allocation

include/mimalloc/internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ terms of the MIT license. A copy of the license can be found in the file
6363
#define mi_decl_noinline
6464
#define mi_decl_thread __thread // hope for the best :-)
6565
#define mi_decl_align(a)
66-
#define mi_decl_noreturn
66+
#define mi_decl_noreturn
6767
#define mi_decl_weak
6868
#define mi_decl_hidden
6969
#define mi_decl_cold
@@ -135,8 +135,8 @@ static inline uintptr_t _mi_random_shuffle(uintptr_t x);
135135
// init.c
136136
extern mi_decl_hidden mi_decl_cache_align mi_stats_t _mi_stats_main;
137137
extern mi_decl_hidden mi_decl_cache_align const mi_page_t _mi_page_empty;
138-
void _mi_process_load(void);
139-
void mi_cdecl _mi_process_done(void);
138+
void _mi_auto_process_init(void);
139+
void mi_cdecl _mi_auto_process_done(void) mi_attr_noexcept;
140140
bool _mi_is_redirected(void);
141141
bool _mi_allocator_init(const char** message);
142142
void _mi_allocator_done(void);

src/init.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ static mi_thread_data_t* mi_thread_data_zalloc(void) {
342342
return NULL;
343343
}
344344
}
345-
td->memid = memid;
345+
td->memid = memid;
346346
return td;
347347
}
348348

@@ -577,7 +577,7 @@ mi_decl_nodiscard bool mi_is_redirected(void) mi_attr_noexcept {
577577
}
578578

579579
// Called once by the process loader from `src/prim/prim.c`
580-
void _mi_process_load(void) {
580+
void _mi_auto_process_init(void) {
581581
mi_heap_main_init();
582582
#if defined(__APPLE__) || defined(MI_TLS_RECURSE_GUARD)
583583
volatile mi_heap_t* dummy = _mi_heap_default; // access TLS to allocate it before setting tls_initialized to true;
@@ -664,8 +664,8 @@ void mi_process_init(void) mi_attr_noexcept {
664664
}
665665
}
666666

667-
// Called when the process is done (through `at_exit`)
668-
void mi_cdecl _mi_process_done(void) {
667+
// Called when the process is done (cdecl as it is used with `at_exit` on some platforms)
668+
void mi_cdecl mi_process_done(void) mi_attr_noexcept {
669669
// only shutdown if we were initialized
670670
if (!_mi_process_is_initialized) return;
671671
// ensure we are called once
@@ -708,3 +708,7 @@ void mi_cdecl _mi_process_done(void) {
708708
os_preloading = true; // don't call the C runtime anymore
709709
}
710710

711+
void mi_cdecl _mi_auto_process_done(void) mi_attr_noexcept {
712+
if (_mi_option_get_fast(mi_option_destroy_on_exit)>1) return;
713+
mi_process_done();
714+
}

src/prim/prim.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,29 @@ terms of the MIT license. A copy of the license can be found in the file
3939
#define mi_attr_destructor __attribute__((destructor))
4040
#endif
4141
static void mi_attr_constructor mi_process_attach(void) {
42-
_mi_process_load();
42+
_mi_auto_process_init();
4343
}
4444
static void mi_attr_destructor mi_process_detach(void) {
45-
_mi_process_done();
45+
_mi_auto_process_done();
4646
}
4747
#elif defined(__cplusplus)
4848
// C++: use static initialization to detect process start/end
4949
// This is not guaranteed to be first/last but the best we can generally do?
5050
struct mi_init_done_t {
5151
mi_init_done_t() {
52-
_mi_process_load();
52+
_mi_auto_process_init();
5353
}
5454
~mi_init_done_t() {
55-
_mi_process_done();
55+
_mi_auto_process_done();
5656
}
5757
};
5858
static mi_init_done_t mi_init_done;
5959
#else
60-
#pragma message("define a way to call _mi_process_load/done on your platform")
60+
#pragma message("define a way to call _mi_auto_process_init/done on your platform")
6161
#endif
6262
#endif
6363

64-
// Generic allocator init/done callback
64+
// Generic allocator init/done callback
6565
#ifndef MI_PRIM_HAS_ALLOCATOR_INIT
6666
bool _mi_is_redirected(void) {
6767
return false;

src/prim/windows/prim.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ bool _mi_prim_random_buf(void* buf, size_t buf_len) {
633633
//----------------------------------------------------------------
634634

635635
#if MI_WIN_USE_FIXED_TLS==1
636-
mi_decl_cache_align size_t _mi_win_tls_offset = 0;
636+
mi_decl_cache_align size_t _mi_win_tls_offset = 0;
637637
#endif
638638

639639
//static void mi_debug_out(const char* s) {
@@ -654,25 +654,25 @@ static void mi_win_tls_init(DWORD reason) {
654654
#endif
655655
#if MI_HAS_TLS_SLOT >= 2 // we must initialize the TLS slot before any allocation
656656
if (mi_prim_get_default_heap() == NULL) {
657-
_mi_heap_set_default_direct((mi_heap_t*)&_mi_heap_empty);
657+
_mi_heap_set_default_direct((mi_heap_t*)&_mi_heap_empty);
658658
#if MI_DEBUG && MI_WIN_USE_FIXED_TLS==1
659659
void* const p = TlsGetValue((DWORD)(_mi_win_tls_offset / sizeof(void*)));
660660
mi_assert_internal(p == (void*)&_mi_heap_empty);
661-
#endif
661+
#endif
662662
}
663-
#endif
664-
}
663+
#endif
664+
}
665665
}
666666

667667
static void NTAPI mi_win_main(PVOID module, DWORD reason, LPVOID reserved) {
668668
MI_UNUSED(reserved);
669669
MI_UNUSED(module);
670670
mi_win_tls_init(reason);
671671
if (reason==DLL_PROCESS_ATTACH) {
672-
_mi_process_load();
672+
_mi_auto_process_init();
673673
}
674674
else if (reason==DLL_PROCESS_DETACH) {
675-
_mi_process_done();
675+
_mi_auto_process_done();
676676
}
677677
else if (reason==DLL_THREAD_DETACH && !_mi_is_redirected()) {
678678
_mi_thread_done(NULL);
@@ -684,7 +684,7 @@ static void NTAPI mi_win_main(PVOID module, DWORD reason, LPVOID reserved) {
684684
#define MI_PRIM_HAS_PROCESS_ATTACH 1
685685

686686
// Windows DLL: easy to hook into process_init and thread_done
687-
BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) {
687+
BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) {
688688
mi_win_main((PVOID)inst,reason,reserved);
689689
return TRUE;
690690
}
@@ -762,7 +762,7 @@ static void NTAPI mi_win_main(PVOID module, DWORD reason, LPVOID reserved) {
762762

763763
static int mi_process_attach(void) {
764764
mi_win_main(NULL,DLL_PROCESS_ATTACH,NULL);
765-
atexit(&_mi_process_done);
765+
atexit(&_mi_auto_process_done);
766766
return 0;
767767
}
768768
typedef int(*mi_crt_callback_t)(void);

0 commit comments

Comments
 (0)