in atomics/src/macros/float_saturating_arithmetic.rs [10:44]
fn fetch_saturating_add(&self, value: <Self as Atomic>::Primitive, ordering: Ordering) -> <Self as Atomic>::Primitive {
let load_ordering = match ordering {
Ordering::AcqRel => Ordering::Acquire,
Ordering::Release => Ordering::Relaxed,
_ => ordering,
};
let mut previous = self.load(load_ordering);
if previous == <$core>::MAX {
// already at numeric bound, return previous value.
return previous;
} else {
loop {
let sum = previous + value;
let new = if sum == <$core>::INFINITY {
<$core>::MAX
} else {
sum
};
let result = self.compare_exchange(previous, new, ordering, load_ordering);
match result {
Ok(v) => {
return v;
}
Err(v) => {
previous = v;
if previous == <$type>::max_value() {
// value concurrently updated and now at numeric bound.
// return its new value as the previous value.
return previous;
}
}
}
}
}
}