From 7167a5e44d1b5610ac64478f520b8bdaa185983b Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Sun, 11 Oct 2020 23:53:00 +0100 Subject: [PATCH] Use the new stabilised fetch_min (#328) A minor simplification using the corresponding new standard library function. Bumps minimum Rust version to 1.45.0 --- .github/workflows/oxipng.yml | 2 +- src/atomicmin.rs | 16 ++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/.github/workflows/oxipng.yml b/.github/workflows/oxipng.yml index 14bef97c..9b21cf8f 100644 --- a/.github/workflows/oxipng.yml +++ b/.github/workflows/oxipng.yml @@ -19,7 +19,7 @@ jobs: - x86_64-apple-darwin toolchain: # Minimum stable - - "1.41.0" + - "1.45.0" - stable - beta - nightly 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); } }