From 549c51f2004325e30c076f2f7c3e49e473a58d20 Mon Sep 17 00:00:00 2001 From: edef Date: Sat, 19 Oct 2024 11:17:19 +0000 Subject: [PATCH] refactor(users/edef/weave): use swap rather than CAS We only care about ordering on the same variable, and we rely on the release barrier provided by rayon's thread joining. The comparison failing is always an error path, and we're indifferent about which thread it fails on. Change-Id: I592a7eaae5b6935cf424c6576a49786f39909fb6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12666 Tested-by: BuildkiteCI Reviewed-by: flokli --- users/edef/weave/src/main.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/users/edef/weave/src/main.rs b/users/edef/weave/src/main.rs index e8a1990a0..243add904 100644 --- a/users/edef/weave/src/main.rs +++ b/users/edef/weave/src/main.rs @@ -43,9 +43,11 @@ fn main() -> Result<()> { eprint!("… resolve roots\r"); ph_array.par_iter().enumerate().for_each(|(idx, h)| { if let Some(idx_slot) = roots.find(h) { - idx_slot - .compare_exchange(INDEX_NULL, idx as u32, Ordering::SeqCst, Ordering::SeqCst) - .expect("duplicate entry"); + assert_eq!( + idx_slot.swap(idx as u32, Ordering::Relaxed), + INDEX_NULL, + "duplicate entry" + ); } }); eprintln!("{DONE}");