improve page flags handling

This commit is contained in:
daan 2019-08-08 17:18:49 -07:00
parent de57686dac
commit 5e56b40fe6
5 changed files with 21 additions and 15 deletions

View file

@ -315,7 +315,13 @@ static inline mi_page_queue_t* mi_page_queue(const mi_heap_t* heap, size_t size)
}
static inline uintptr_t mi_page_thread_id(const mi_page_t* page) {
return (page->flags.padding << MI_PAGE_FLAGS_BITS);
return (page->flags.xthread_id << MI_PAGE_FLAGS_BITS);
}
static inline void mi_page_init_flags(mi_page_t* page, uintptr_t thread_id) {
page->flags.value = 0;
page->flags.xthread_id = (thread_id >> MI_PAGE_FLAGS_BITS);
mi_assert(page->flags.value == thread_id);
}
// -------------------------------------------------------------------

View file

@ -126,18 +126,18 @@ typedef enum mi_delayed_e {
// Use the lowest two bits of a thread id for the `in_full` and `has_aligned` flags
// This allows a single test in `mi_free` to check for unlikely cases
// (namely, non-local free, aligned free, or freeing in a full page)
#define MI_PAGE_FLAGS_BITS (2)
#define MI_PAGE_FLAGS_BITS (2)
#define MI_PAGE_FLAGS_TID_BITS (MI_INTPTR_SIZE*8 - MI_PAGE_FLAGS_BITS)
typedef union mi_page_flags_u {
uintptr_t threadidx;
uintptr_t value;
struct {
#ifdef MI_BIG_ENDIAN
uintptr_t padding : (MI_INTPTR_SIZE*8 - MI_PAGE_FLAGS_BITS);
uintptr_t xthread_id : MI_PAGE_FLAGS_TID_BITS;
#endif
uintptr_t in_full : 1;
uintptr_t has_aligned : 1;
#else
uintptr_t in_full : 1;
uintptr_t has_aligned : 1;
uintptr_t padding : (MI_INTPTR_SIZE*8 - MI_PAGE_FLAGS_BITS);
#ifndef MI_BIG_ENDIAN
uintptr_t xthread_id : MI_PAGE_FLAGS_TID_BITS;
#endif
};
} mi_page_flags_t;