add SyncUnsafeCell implementation

This commit is contained in:
Corwin 2024-09-22 16:19:00 +01:00
parent 18572658cb
commit 56e3de3c62
No known key found for this signature in database
2 changed files with 17 additions and 0 deletions

View file

@ -190,6 +190,7 @@ mod sync;
pub mod syscall;
/// Interactions with the internal timers
pub mod timer;
pub(crate) mod util;
mod no_game;

16
agb/src/util.rs Normal file
View file

@ -0,0 +1,16 @@
use core::cell::UnsafeCell;
pub struct SyncUnsafeCell<T>(UnsafeCell<T>);
unsafe impl<T> Sync for SyncUnsafeCell<T> {}
unsafe impl<T> Send for SyncUnsafeCell<T> {}
impl<T> SyncUnsafeCell<T> {
pub const fn new(t: T) -> Self {
Self(UnsafeCell::new(t))
}
pub unsafe fn get(&self) -> *mut T {
self.0.get()
}
}