/* 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/. */
impl<T> StateCallback<T> { // This is used for the Condvar, which requires this kind of construction #[allow(clippy::mutex_atomic)] pubfn new(cb: Box<dyn FnOnce(T) + Send>) -> Self { Self {
callback: Arc::new(Mutex::new(Some(cb))),
observer: Arc::new(Mutex::new(None)),
condition: Arc::new((Mutex::new(true), Condvar::new())),
}
}
assert!(sc.observer.lock().unwrap().is_some()); // This is deliberate, to force an extra clone
assert!(sc.clone().observer.lock().unwrap().is_none());
}
#[test] fn test_statecallback_wait() { let sc = StateCallback::<()>::new(Box::new(move |_| {})); let barrier = Arc::new(Barrier::new(2));
{ let c = sc.clone(); let b = barrier.clone();
thread::spawn(move || {
b.wait();
c.call(());
});
}
barrier.wait();
sc.wait();
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-19)
¤
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.