Skip to content

Commit e504759

Browse files
committed
fix assertion failure
1 parent b92c116 commit e504759

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/alloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static mi_decl_forceinline mi_decl_restrict void* mi_theap_malloc_small_zero_non
133133
mi_assert(size <= MI_SMALL_SIZE_MAX);
134134
#if MI_DEBUG
135135
const uintptr_t tid = _mi_thread_id();
136-
mi_assert(theap->tld->thread_id == ~0UL || theap->tld->thread_id == tid); // theaps are thread local
136+
mi_assert(theap->tld->thread_id == 0 || theap->tld->thread_id == tid); // theaps are thread local
137137
#endif
138138
#if (MI_PADDING || MI_GUARDED)
139139
if mi_unlikely(size == 0) { size = sizeof(void*); }

src/init.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,13 @@ mi_decl_cache_align const mi_theap_t _mi_theap_empty_wrong = {
163163

164164
// Heap for the main thread
165165

166-
#define MI_THREADID_UNINIT ((mi_threadid_t)(~0))
166+
#define MI_THREADID_INVALID ((mi_threadid_t)(~0))
167167

168168
extern mi_decl_hidden mi_decl_cache_align mi_theap_t theap_main;
169169
extern mi_decl_hidden mi_decl_cache_align mi_heap_t heap_main;
170170

171171
static mi_decl_cache_align mi_tld_t tld_main = {
172-
MI_THREADID_UNINIT, // thread_id
172+
0, // thread_id
173173
0, // thread_seq
174174
0, // numa node
175175
&subproc_main, // subproc
@@ -300,7 +300,7 @@ static void mi_subproc_main_init(void) {
300300

301301
// Initialize main tld
302302
static void mi_tld_main_init(void) {
303-
if (tld_main.thread_id == MI_THREADID_UNINIT) {
303+
if (tld_main.thread_id == 0) {
304304
tld_main.thread_id = _mi_prim_thread_id();
305305
mi_lock_init(&tld_main.theaps_lock);
306306
}
@@ -383,7 +383,7 @@ static mi_tld_t* mi_tld_alloc(void) {
383383
mi_decl_noinline static void mi_tld_free(mi_tld_t* tld) {
384384
if (tld==NULL || tld==MI_TLD_INVALID) return;
385385
mi_atomic_decrement_relaxed(&tld->subproc->thread_count);
386-
tld->thread_id = 0;
386+
tld->thread_id = MI_THREADID_INVALID; // note: not 0 as that would re-initialize tld_main
387387
mi_lock_done(&tld->theaps_lock);
388388
_mi_meta_free(tld, sizeof(mi_tld_t), tld->memid); // note: safe for static tld_main
389389
}
@@ -700,7 +700,7 @@ static void mi_process_setup_auto_thread_done(void) {
700700

701701

702702
bool _mi_is_main_thread(void) {
703-
return (tld_main.thread_id==MI_THREADID_UNINIT || tld_main.thread_id == _mi_thread_id());
703+
return (tld_main.thread_id==0 || tld_main.thread_id == _mi_thread_id());
704704
}
705705

706706

0 commit comments

Comments
 (0)