fn fetch_saturating_sub()

in atomics/src/macros/saturating_arithmetic.rs [45:78]


            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 new = previous.saturating_sub(value);
                        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;
                                }
                            }
                        }
                    }
                }
            }