@@ -119,17 +119,15 @@ void _mi_prim_thread_associate_default_heap(mi_heap_t* heap);
119119
120120
121121
122+
123+
122124//-------------------------------------------------------------------
123- // Thread id: `_mi_prim_thread_id()`
124- //
125- // Getting the thread id should be performant as it is called in the
126- // fast path of `_mi_free` and we specialize for various platforms as
127- // inlined definitions. Regular code should call `init.c:_mi_thread_id()`.
128- // We only require _mi_prim_thread_id() to return a unique id
129- // for each thread (unequal to zero).
125+ // Access to TLS (thread local storage) slots.
126+ // We need fast access to both a unique thread id (in `free.c:mi_free`) and
127+ // to a thread-local heap pointer (in `alloc.c:mi_malloc`).
128+ // To achieve this we use specialized code for various platforms.
130129//-------------------------------------------------------------------
131130
132-
133131// On some libc + platform combinations we can directly access a thread-local storage (TLS) slot.
134132// The TLS layout depends on both the OS and libc implementation so we use specific tests for each main platform.
135133// If you test on another platform and it works please send a PR :-)
@@ -210,7 +208,7 @@ static inline void mi_prim_tls_slot_set(size_t slot, void* value) mi_attr_noexce
210208#elif _WIN32 && MI_WIN_USE_FIXED_TLS && !defined(MI_WIN_USE_FLS )
211209
212210// On windows we can store the thread-local heap at a fixed TLS slot to avoid
213- // thread-local initialization checks in the fast path. This use a fixed location
211+ // thread-local initialization checks in the fast path. This uses a fixed location
214212// in the TCB though (last user-reserved slot by default) which may clash with other applications.
215213
216214#define MI_HAS_TLS_SLOT 2 // 2 = we can reliable initialize the slot (saving a test on each malloc)
@@ -241,6 +239,18 @@ static inline void mi_prim_tls_slot_set(size_t slot, void* value) mi_attr_noexce
241239#endif
242240
243241
242+
243+ //-------------------------------------------------------------------
244+ // Get a fast unique thread id.
245+ //
246+ // Getting the thread id should be performant as it is called in the
247+ // fast path of `_mi_free` and we specialize for various platforms as
248+ // inlined definitions. Regular code should call `init.c:_mi_thread_id()`.
249+ // We only require _mi_prim_thread_id() to return a unique id
250+ // for each thread (unequal to zero).
251+ //-------------------------------------------------------------------
252+
253+
244254// Do we have __builtin_thread_pointer? This would be the preferred way to get a unique thread id
245255// but unfortunately, it seems we cannot test for this reliably at this time (see issue #883)
246256// Nevertheless, it seems needed on older graviton platforms (see issue #851).
@@ -311,7 +321,8 @@ static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept {
311321
312322
313323/* ----------------------------------------------------------------------------------------
314- The thread local default heap: `_mi_prim_get_default_heap()`
324+ Get the thread local default heap: `_mi_prim_get_default_heap()`
325+
315326This is inlined here as it is on the fast path for allocation functions.
316327
317328On most platforms (Windows, Linux, FreeBSD, NetBSD, etc), this just returns a
@@ -404,7 +415,4 @@ static inline mi_heap_t* mi_prim_get_default_heap(void) {
404415#endif // mi_prim_get_default_heap()
405416
406417
407-
408-
409-
410418#endif // MIMALLOC_PRIM_H
0 commit comments