fn fetch_saturating_sub()

in atomics/src/macros/float_saturating_arithmetic.rs [47:81]


            fn fetch_saturating_sub(&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 == <$type>::min_value() {
                    // already at numeric bound, return previous value.
                    return previous;
                } else {
                    loop {
                        let diff = previous - value;
                        let new = if diff == <$core>::NEG_INFINITY {
                            <$core>::MAX                            
                        } else {
                            diff
                        };
                        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;
                                }
                            }
                        }
                    }
                }
            }