/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::collections::{HashMap, HashSet}; use std::sync::atomic::{AtomicU32, Ordering};
/// Finds the maximum of the current value and the argument `val`, and sets the /// new value to the result. /// /// Note: `AtomicFoo::fetch_max` is unstable, and can't really be implemented as /// a single atomic operation from outside the stdlib ;-; pub(crate) fn atomic_update_max(v: &AtomicU32, new: u32) { // For loads (and the compare_exchange_weak second ordering argument) this // is too strong, we could probably get away with Acquire (or maybe Relaxed // because we don't need the result?). In either case, this fn isn't called // from a hot spot so whatever. letmut cur = v.load(Ordering::SeqCst); while cur < new { // we're already handling the failure case so there's no reason not to // use _weak here. match v.compare_exchange_weak(cur, new, Ordering::SeqCst, Ordering::SeqCst) {
Ok(_) => { // Success. break;
}
Err(new_cur) => { // Interrupted, keep trying.
cur = new_cur
}
}
}
}
// Slight wrappers around the builtin methods for doing this. pub(crate) fn set_union(a: &HashSet<String>, b: &HashSet<String>) -> HashSet<String> {
a.union(b).cloned().collect()
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.