From 7d834864bb59c31f8ced90d27530d51f5e05ae64 Mon Sep 17 00:00:00 2001 From: Daan Date: Thu, 16 Mar 2023 11:35:11 -0700 Subject: [PATCH] fix macOSX compilation --- src/init.c | 2 +- src/prim/prim-unix.c | 2 +- src/prim/prim.h | 18 +++++++++++------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/init.c b/src/init.c index 31ec87cb..d73c1e1e 100644 --- a/src/init.c +++ b/src/init.c @@ -399,7 +399,7 @@ void _mi_thread_done(mi_heap_t* heap) void _mi_heap_set_default_direct(mi_heap_t* heap) { mi_assert_internal(heap != NULL); #if defined(MI_TLS_SLOT) - mi_tls_slot_set(MI_TLS_SLOT,heap); + mi_prim_tls_slot_set(MI_TLS_SLOT,heap); #elif defined(MI_TLS_PTHREAD_SLOT_OFS) *mi_tls_pthread_heap_slot() = heap; #elif defined(MI_TLS_PTHREAD) diff --git a/src/prim/prim-unix.c b/src/prim/prim-unix.c index 9270e088..997c0356 100644 --- a/src/prim/prim-unix.c +++ b/src/prim/prim-unix.c @@ -796,4 +796,4 @@ void _mi_prim_thread_associate_default_heap(mi_heap_t* heap) { MI_UNUSED(heap); } -#endif \ No newline at end of file +#endif diff --git a/src/prim/prim.h b/src/prim/prim.h index 5a58a79f..967c6698 100644 --- a/src/prim/prim.h +++ b/src/prim/prim.h @@ -252,16 +252,20 @@ static inline mi_heap_t* mi_prim_get_default_heap(void) { #elif defined(MI_TLS_PTHREAD_SLOT_OFS) -static inline mi_heap_t* mi_prim_get_default_heap(void) { - mi_heap_t* heap; +static inline mi_heap_t** mi_prim_tls_pthread_heap_slot(void) { pthread_t self = pthread_self(); #if defined(__DragonFly__) - if (self==NULL) { heap = _mi_heap_main_get(); } else + if (self==NULL) return NULL; #endif - { - heap = *((mi_heap_t**)((uint8_t*)self + MI_TLS_PTHREAD_SLOT_OFS)); - } - return (mi_unlikely(heap == NULL) ? (mi_heap_t*)&_mi_heap_empty : heap); + return (mi_heap_t**)((uint8_t*)self + MI_TLS_PTHREAD_SLOT_OFS); +} + +static inline mi_heap_t* mi_prim_get_default_heap(void) { + mi_heap_t** pheap = mi_prim_tls_pthread_heap_slot(); + if mi_unlikely(pheap == NULL) return _mi_heap_main_get(); + mi_heap_t* heap = *pheap; + if mi_unlikely(heap == NULL) return (mi_heap_t*)&_mi_heap_empty; + return heap; } #elif defined(MI_TLS_PTHREAD)