summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDaan <daanl@outlook.com>2022-01-10 11:40:36 -0800
committerDaan <daanl@outlook.com>2022-01-10 11:40:36 -0800
commit4b63c76861647332f0d18e9af360917cbc166182 (patch)
tree2ee89b9fcb2db84c8ba98b8c98780e58bb4b1372 /include
parent43e5cd2671585023d425f247b5c39cfa1207866a (diff)
avoid conditional load on macos
Diffstat (limited to 'include')
-rw-r--r--include/mimalloc-internal.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/include/mimalloc-internal.h b/include/mimalloc-internal.h
index 5f01664..3da9a0c 100644
--- a/include/mimalloc-internal.h
+++ b/include/mimalloc-internal.h
@@ -154,8 +154,8 @@ bool _mi_page_is_valid(mi_page_t* page);
// ------------------------------------------------------
#if defined(__GNUC__) || defined(__clang__)
-#define mi_unlikely(x) __builtin_expect((x),0)
-#define mi_likely(x) __builtin_expect((x),1)
+#define mi_unlikely(x) __builtin_expect(!!(x),false)
+#define mi_likely(x) __builtin_expect(!!(x),true)
#else
#define mi_unlikely(x) (x)
#define mi_likely(x) (x)
@@ -346,11 +346,15 @@ extern pthread_key_t _mi_heap_default_key;
// However, on the Apple M1 we do use the address of this variable as the unique thread-id (issue #356).
extern mi_decl_thread mi_heap_t* _mi_heap_default; // default heap to allocate from
-
static inline mi_heap_t* mi_get_default_heap(void) {
#if defined(MI_TLS_SLOT)
mi_heap_t* heap = (mi_heap_t*)mi_tls_slot(MI_TLS_SLOT);
- if (mi_unlikely(heap == NULL)) { heap = (mi_heap_t*)&_mi_heap_empty; } //_mi_heap_empty_get(); }
+ if (mi_unlikely(heap == NULL)) {
+ #ifdef __GNUC__
+ __asm(""); // prevent conditional load of the address of _mi_heap_empty
+ #endif
+ heap = (mi_heap_t*)&_mi_heap_empty;
+ }
return heap;
#elif defined(MI_TLS_PTHREAD_SLOT_OFS)
mi_heap_t* heap = *mi_tls_pthread_heap_slot();