pub mod helper { use core::hint; use rusturnate::editor::Editor; #[inline(always)] pub fn prevent_optimization(t: &T) { // do not optimize editor: hint::black_box(t); } #[inline(always)] pub fn intentionally_panic_while_holding(editor: Editor) -> ! { prevent_optimization(&editor); // intentionally panic and poison editor: panic!("test panic; test whether panic is received correctly"); } } #[cfg(feature = "std")] pub mod std_helper { use std::thread::JoinHandle; use tokio::task; #[inline(always)] pub fn await_completion(handle: JoinHandle) { let _: Option = handle.join().ok(); } #[inline] pub async fn await_completion_non_blocking(handle: JoinHandle) { let _: () = task::spawn_blocking(move || await_completion(handle)) .await .unwrap(); } } pub mod affinity_helper { use core_affinity::{self, CoreId}; #[inline] pub fn get_two_different_core_ids() -> Option<(CoreId, CoreId)> { let core_ids: Vec = core_affinity::get_core_ids()?; let two_core_ids: &[CoreId] = core_ids.get(0..=1)?; let [core_id1, core_id2]: [_; 2] = two_core_ids.try_into().ok()?; assert_ne!(core_id1, core_id2, "gotten two equal core ids"); Some((core_id1, core_id2)) } #[inline] pub fn set_core_affinity(core_id: CoreId) -> bool { let changed_affinity: bool = core_affinity::set_for_current(core_id); if !changed_affinity { eprintln!("unable to set core affinity to {core_id:?}") } changed_affinity } #[inline] pub fn if_provided_set_core_affinity(core_id: Option) { let _: bool = core_id.map_or(false, set_core_affinity); } #[inline] pub fn prepare_on_fixed_core() -> Option { let (core_id1, core_id2) = get_two_different_core_ids()?; set_core_affinity(core_id1).then_some(())?; Some(core_id2) } }