mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-07-06 19:38:41 +03:00
merge from dev
This commit is contained in:
commit
ef6ea7e718
3 changed files with 27 additions and 5 deletions
25
src/alloc.c
25
src/alloc.c
|
@ -475,14 +475,12 @@ static inline mi_segment_t* mi_checked_ptr_segment(const void* p, const char* ms
|
|||
return segment;
|
||||
}
|
||||
|
||||
|
||||
// Free a block
|
||||
void mi_free(void* p) mi_attr_noexcept
|
||||
// Free a block with a known threadid
|
||||
static mi_decl_always_inline void _mi_free_with_threadid(void* p, mi_threadid_t tid) mi_attr_noexcept
|
||||
{
|
||||
const mi_segment_t* const segment = mi_checked_ptr_segment(p,"mi_free");
|
||||
if (mi_unlikely(segment == NULL)) return;
|
||||
|
||||
const mi_threadid_t tid = _mi_thread_id();
|
||||
mi_page_t* const page = _mi_segment_page_of(segment, p);
|
||||
|
||||
if (mi_likely(tid == mi_atomic_load_relaxed(&segment->thread_id) && page->flags.full_aligned == 0)) { // the thread id matches and it is not a full page, nor has aligned blocks
|
||||
|
@ -507,6 +505,25 @@ void mi_free(void* p) mi_attr_noexcept
|
|||
}
|
||||
}
|
||||
|
||||
// Get the current thread id
|
||||
size_t mi_get_current_threadid(void) mi_attr_noexcept {
|
||||
return _mi_thread_id();
|
||||
}
|
||||
|
||||
// Free a block passing the current thread id explicitly
|
||||
void mi_unsafe_free_with_threadid(void* p, size_t current_tid ) mi_attr_noexcept
|
||||
{
|
||||
mi_assert(current_tid == _mi_thread_id());
|
||||
_mi_free_with_threadid(p,current_tid);
|
||||
}
|
||||
|
||||
|
||||
// Free a block
|
||||
void mi_free(void* p) mi_attr_noexcept {
|
||||
_mi_free_with_threadid(p, _mi_thread_id());
|
||||
}
|
||||
|
||||
|
||||
bool _mi_free_delayed_block(mi_block_t* block) {
|
||||
// get segment and page
|
||||
const mi_segment_t* const segment = _mi_ptr_segment(block);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue