Skip to content

Commit f288249

Browse files
committed
Use compare_exchange instead of CAS for global collector
1 parent d2ab662 commit f288249

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

libs/simple/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,10 +515,10 @@ unsafe impl zerogc_context::collector::SingletonCollector for RawSimpleCollector
515515
*
516516
* Exchange with marker pointer while we're initializing.
517517
*/
518-
assert!(GLOBAL_COLLECTOR.compare_and_swap(
518+
assert_eq!(GLOBAL_COLLECTOR.compare_exchange(
519519
std::ptr::null_mut(), marker_ptr,
520-
Ordering::SeqCst
521-
).is_null(), "Collector already exists");
520+
Ordering::SeqCst, Ordering::SeqCst
521+
), Ok(std::ptr::null_mut()), "Collector already exists");
522522
let mut raw = Box::new(
523523
unsafe { RawSimpleCollector::with_logger(logger) }
524524
);
@@ -527,11 +527,11 @@ unsafe impl zerogc_context::collector::SingletonCollector for RawSimpleCollector
527527
// It shall reign forever!
528528
let raw = Box::leak(raw);
529529
assert_eq!(
530-
GLOBAL_COLLECTOR.compare_and_swap(
530+
GLOBAL_COLLECTOR.compare_exchange(
531531
marker_ptr, raw as *mut RawSimpleCollector,
532-
Ordering::SeqCst
532+
Ordering::SeqCst, Ordering::SeqCst
533533
),
534-
marker_ptr, "Unexpected modification"
534+
Ok(marker_ptr), "Unexpected modification"
535535
);
536536
}
537537
}

0 commit comments

Comments
 (0)