]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-129748: Update mimalloc to use atomic store for mi_block_set_nextx (#134238)
authorDonghee Na <donghee.na@python.org>
Tue, 20 May 2025 15:39:56 +0000 (11:39 -0400)
committerGitHub <noreply@github.com>
Tue, 20 May 2025 15:39:56 +0000 (11:39 -0400)
Include/internal/mimalloc/mimalloc/internal.h
Include/internal/mimalloc/mimalloc/types.h

index d97f51b8eefbe55bf1cbfafb25a46571bfc12963..71b7ea702d6c5e8d1cb738081bfcea57baf268d3 100644 (file)
@@ -634,10 +634,10 @@ static inline mi_block_t* mi_block_nextx( const void* null, const mi_block_t* bl
   mi_track_mem_defined(block,sizeof(mi_block_t));
   mi_block_t* next;
   #ifdef MI_ENCODE_FREELIST
-  next = (mi_block_t*)mi_ptr_decode(null, block->next, keys);
+  next = (mi_block_t*)mi_ptr_decode(null, mi_atomic_load_relaxed(&block->next), keys);
   #else
   MI_UNUSED(keys); MI_UNUSED(null);
-  next = (mi_block_t*)block->next;
+  next = (mi_block_t*)mi_atomic_load_relaxed(&block->next);
   #endif
   mi_track_mem_noaccess(block,sizeof(mi_block_t));
   return next;
@@ -646,10 +646,10 @@ static inline mi_block_t* mi_block_nextx( const void* null, const mi_block_t* bl
 static inline void mi_block_set_nextx(const void* null, mi_block_t* block, const mi_block_t* next, const uintptr_t* keys) {
   mi_track_mem_undefined(block,sizeof(mi_block_t));
   #ifdef MI_ENCODE_FREELIST
-  block->next = mi_ptr_encode(null, next, keys);
+  mi_atomic_store_relaxed(&block->next, mi_ptr_encode(null, next, keys));
   #else
   MI_UNUSED(keys); MI_UNUSED(null);
-  block->next = (mi_encoded_t)next;
+  mi_atomic_store_relaxed(&block->next, (mi_encoded_t)next);
   #endif
   mi_track_mem_noaccess(block,sizeof(mi_block_t));
 }
index 354839ba955b3640422b7f94b229f9145ad621e7..4f77bd7bc525db80167e2f9f5a5c81be8dde41bb 100644 (file)
@@ -235,7 +235,7 @@ typedef size_t     mi_threadid_t;
 
 // free lists contain blocks
 typedef struct mi_block_s {
-  mi_encoded_t next;
+  _Atomic(mi_encoded_t) next;
 } mi_block_t;