From fb247aa8f2f5497b663f2690c3082cfeb52bd740 Mon Sep 17 00:00:00 2001 From: Corwin Date: Sat, 17 Feb 2024 16:38:22 +0000 Subject: [PATCH] move single file module out of directory --- agb/src/{sync/mod.rs => sync.rs} | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) rename agb/src/{sync/mod.rs => sync.rs} (87%) diff --git a/agb/src/sync/mod.rs b/agb/src/sync.rs similarity index 87% rename from agb/src/sync/mod.rs rename to agb/src/sync.rs index 769a6500..d614662f 100644 --- a/agb/src/sync/mod.rs +++ b/agb/src/sync.rs @@ -142,3 +142,28 @@ impl<'a, T> DerefMut for LockGuard<'a, T> { #[no_mangle] #[inline(always)] pub unsafe extern "C" fn __sync_synchronize() {} + +#[cfg(test)] +mod tests { + use once_cell::sync::OnceCell; + + #[derive(Default)] + #[allow(dead_code)] + struct Storage([u32; 16 / 4]); + + #[test_case] + fn check_init_once(_: &mut crate::Gba) { + static CELL: OnceCell = OnceCell::new(); + + core::hint::black_box(CELL.get_or_init(Default::default)); + } + + #[test_case] + fn check_init_once_many(_: &mut crate::Gba) { + static CELL: OnceCell = OnceCell::new(); + + for _ in 0..1000 { + core::hint::black_box(CELL.get_or_init(Default::default)); + } + } +}