From 4665bfcb195182c40cdaf8f364d0d86fe1f19fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 3 Oct 2024 16:14:23 +0200 Subject: [PATCH] Move the parent assignation before the exchange operation --- milli/src/update/new/append_only_linked_list.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/milli/src/update/new/append_only_linked_list.rs b/milli/src/update/new/append_only_linked_list.rs index c08b9c090..697d5583f 100644 --- a/milli/src/update/new/append_only_linked_list.rs +++ b/milli/src/update/new/append_only_linked_list.rs @@ -23,15 +23,13 @@ impl AppendOnlyLinkedList { use std::sync::atomic::Ordering::{Relaxed, SeqCst}; let node = Box::leak(Box::new(Node { item, parent: AtomicPtr::default() })); - let mut head = self.head.load(SeqCst); + loop { std::hint::spin_loop(); + node.parent = AtomicPtr::new(head); match self.head.compare_exchange_weak(head, node, SeqCst, Relaxed) { - Ok(parent) => { - node.parent = AtomicPtr::new(parent); - break; - } + Ok(_) => break, Err(new) => head = new, } }