From 56e3de3c6298e29608afe2fa45aa3aae789b5bf7 Mon Sep 17 00:00:00 2001 From: Corwin Date: Sun, 22 Sep 2024 16:19:00 +0100 Subject: [PATCH] add SyncUnsafeCell implementation --- agb/src/lib.rs | 1 + agb/src/util.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 agb/src/util.rs diff --git a/agb/src/lib.rs b/agb/src/lib.rs index 9c66f36d..3b4af52f 100644 --- a/agb/src/lib.rs +++ b/agb/src/lib.rs @@ -190,6 +190,7 @@ mod sync; pub mod syscall; /// Interactions with the internal timers pub mod timer; +pub(crate) mod util; mod no_game; diff --git a/agb/src/util.rs b/agb/src/util.rs new file mode 100644 index 00000000..657031c8 --- /dev/null +++ b/agb/src/util.rs @@ -0,0 +1,16 @@ +use core::cell::UnsafeCell; + +pub struct SyncUnsafeCell(UnsafeCell); + +unsafe impl Sync for SyncUnsafeCell {} +unsafe impl Send for SyncUnsafeCell {} + +impl SyncUnsafeCell { + pub const fn new(t: T) -> Self { + Self(UnsafeCell::new(t)) + } + + pub unsafe fn get(&self) -> *mut T { + self.0.get() + } +}