mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-19 13:39:31 +03:00
override thread id
This commit is contained in:
parent
43ce4bd7fd
commit
84f48a2715
2 changed files with 19 additions and 0 deletions
|
@ -164,6 +164,12 @@ mi_decl_export void mi_process_info(size_t* elapsed_msecs, size_t* user_msecs, s
|
||||||
size_t* current_rss, size_t* peak_rss,
|
size_t* current_rss, size_t* peak_rss,
|
||||||
size_t* current_commit, size_t* peak_commit, size_t* page_faults) mi_attr_noexcept;
|
size_t* current_commit, size_t* peak_commit, size_t* page_faults) mi_attr_noexcept;
|
||||||
|
|
||||||
|
typedef size_t mi_threadid_t;
|
||||||
|
|
||||||
|
mi_decl_export mi_threadid_t mi_override_thread(mi_threadid_t override_id);
|
||||||
|
mi_decl_nodiscard mi_decl_export mi_threadid_t mi_thread_id(void);
|
||||||
|
mi_decl_export void mi_restore_default_thread_id(void);
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------
|
||||||
// Aligned allocation
|
// Aligned allocation
|
||||||
// Note that `alignment` always follows `size` for consistency with unaligned
|
// Note that `alignment` always follows `size` for consistency with unaligned
|
||||||
|
|
13
src/init.c
13
src/init.c
|
@ -136,10 +136,23 @@ mi_decl_cache_align static const mi_tld_t tld_empty = {
|
||||||
{ MI_STATS_NULL } // stats
|
{ MI_STATS_NULL } // stats
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mi_decl_thread mi_threadid_t _mi_override_thread_id = 0;
|
||||||
|
mi_decl_thread bool _mi_use_override_thread_id = false;
|
||||||
mi_threadid_t _mi_thread_id(void) mi_attr_noexcept {
|
mi_threadid_t _mi_thread_id(void) mi_attr_noexcept {
|
||||||
|
if (_mi_use_override_thread_id)
|
||||||
|
return _mi_override_thread_id;
|
||||||
return _mi_prim_thread_id();
|
return _mi_prim_thread_id();
|
||||||
}
|
}
|
||||||
|
mi_threadid_t mi_override_thread(mi_threadid_t override_id) {
|
||||||
|
mi_threadid_t prev_id = _mi_thread_id();
|
||||||
|
_mi_use_override_thread_id = true;
|
||||||
|
_mi_override_thread_id = override_id;
|
||||||
|
return prev_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mi_restore_default_thread_id(void) { _mi_use_override_thread_id = false; }
|
||||||
|
|
||||||
|
mi_threadid_t mi_thread_id(void) { return _mi_thread_id(); }
|
||||||
// the thread-local default heap for allocation
|
// the thread-local default heap for allocation
|
||||||
mi_decl_thread mi_heap_t* _mi_heap_default = (mi_heap_t*)&_mi_heap_empty;
|
mi_decl_thread mi_heap_t* _mi_heap_default = (mi_heap_t*)&_mi_heap_empty;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue