#719 is failing tests due to requiring a newer version of rust than we currently specify. This PR updates to 1.85.1 and sets the edition to 2024. I've also updated dependencies and runner images, using the ubuntu arm runner which removes the need for qemu and other hacks. Closes #719.
25 lines
621 B
Rust
25 lines
621 B
Rust
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
|
|
|
|
#[derive(Debug)]
|
|
pub struct AtomicMin {
|
|
val: AtomicUsize,
|
|
}
|
|
|
|
impl AtomicMin {
|
|
#[must_use]
|
|
pub fn new(init: Option<usize>) -> Self {
|
|
Self {
|
|
val: AtomicUsize::new(init.unwrap_or(usize::MAX)),
|
|
}
|
|
}
|
|
|
|
pub fn get(&self) -> Option<usize> {
|
|
let val = self.val.load(SeqCst);
|
|
if val == usize::MAX { None } else { Some(val) }
|
|
}
|
|
|
|
/// Try a new value, returning true if it is the new minimum
|
|
pub fn set_min(&self, new_val: usize) -> bool {
|
|
new_val < self.val.fetch_min(new_val, SeqCst)
|
|
}
|
|
}
|