From 16c7a4b9ba53c96a7af07eff548238406cc1cf2e Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Wed, 7 Oct 2020 16:03:07 +0100 Subject: [PATCH] Use to the new stabilised fetch_min A minor simplification using the corresponding new standard library function. --- src/atomicmin.rs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/atomicmin.rs b/src/atomicmin.rs index 0d867fc3..af2287a9 100644 --- a/src/atomicmin.rs +++ b/src/atomicmin.rs @@ -1,5 +1,5 @@ use std::sync::atomic::AtomicUsize; -use std::sync::atomic::Ordering::{Relaxed, SeqCst}; +use std::sync::atomic::Ordering::SeqCst; #[derive(Debug)] pub struct AtomicMin { @@ -28,18 +28,6 @@ impl AtomicMin { } pub fn set_min(&self, new_val: usize) { - let mut current_val = self.val.load(Relaxed); - loop { - if new_val < current_val { - if let Err(v) = self - .val - .compare_exchange(current_val, new_val, SeqCst, Relaxed) - { - current_val = v; - continue; - } - } - break; - } + self.val.fetch_min(new_val, SeqCst); } }