Use to the new stabilised fetch_min
A minor simplification using the corresponding new standard library function.
This commit is contained in:
parent
f5e2de6795
commit
16c7a4b9ba
1 changed files with 2 additions and 14 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
use std::sync::atomic::AtomicUsize;
|
use std::sync::atomic::AtomicUsize;
|
||||||
use std::sync::atomic::Ordering::{Relaxed, SeqCst};
|
use std::sync::atomic::Ordering::SeqCst;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct AtomicMin {
|
pub struct AtomicMin {
|
||||||
|
|
@ -28,18 +28,6 @@ impl AtomicMin {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_min(&self, new_val: usize) {
|
pub fn set_min(&self, new_val: usize) {
|
||||||
let mut current_val = self.val.load(Relaxed);
|
self.val.fetch_min(new_val, SeqCst);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue