Skip to content

Commit bad9f63

Browse files
[3.13] gh-129748: Update mimalloc to use atomic store for mi_block_set_nextx (GH-134238) (gh-134353)
gh-129748: Update mimalloc to use atomic store for mi_block_set_nextx (GH-134238) (cherry picked from commit 317c496) Co-authored-by: Donghee Na <[email protected]>
1 parent 61af847 commit bad9f63

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Include/internal/mimalloc/mimalloc/internal.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,10 @@ static inline mi_block_t* mi_block_nextx( const void* null, const mi_block_t* bl
634634
mi_track_mem_defined(block,sizeof(mi_block_t));
635635
mi_block_t* next;
636636
#ifdef MI_ENCODE_FREELIST
637-
next = (mi_block_t*)mi_ptr_decode(null, block->next, keys);
637+
next = (mi_block_t*)mi_ptr_decode(null, mi_atomic_load_relaxed(&block->next), keys);
638638
#else
639639
MI_UNUSED(keys); MI_UNUSED(null);
640-
next = (mi_block_t*)block->next;
640+
next = (mi_block_t*)mi_atomic_load_relaxed(&block->next);
641641
#endif
642642
mi_track_mem_noaccess(block,sizeof(mi_block_t));
643643
return next;
@@ -646,10 +646,10 @@ static inline mi_block_t* mi_block_nextx( const void* null, const mi_block_t* bl
646646
static inline void mi_block_set_nextx(const void* null, mi_block_t* block, const mi_block_t* next, const uintptr_t* keys) {
647647
mi_track_mem_undefined(block,sizeof(mi_block_t));
648648
#ifdef MI_ENCODE_FREELIST
649-
block->next = mi_ptr_encode(null, next, keys);
649+
mi_atomic_store_relaxed(&block->next, mi_ptr_encode(null, next, keys));
650650
#else
651651
MI_UNUSED(keys); MI_UNUSED(null);
652-
block->next = (mi_encoded_t)next;
652+
mi_atomic_store_relaxed(&block->next, (mi_encoded_t)next);
653653
#endif
654654
mi_track_mem_noaccess(block,sizeof(mi_block_t));
655655
}

Include/internal/mimalloc/mimalloc/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ typedef size_t mi_threadid_t;
235235

236236
// free lists contain blocks
237237
typedef struct mi_block_s {
238-
mi_encoded_t next;
238+
_Atomic(mi_encoded_t) next;
239239
} mi_block_t;
240240

241241

0 commit comments

Comments
 (0)