diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -57,3 +57,31 @@ where { NVIC::pend(interrupt) } + +use core::cell::UnsafeCell; + +/// Internal replacement for `static mut T` +#[repr(transparent)] +pub struct RacyCell<T>(UnsafeCell<T>); + +impl<T> RacyCell<T> { + /// Create a RacyCell + #[inline(always)] + pub const fn new(value: T) -> Self { + RacyCell(UnsafeCell::new(value)) + } + + /// Get `&mut T` + #[inline(always)] + pub unsafe fn get_mut_unchecked(&self) -> &mut T { + &mut *self.0.get() + } + + /// Get `&T` + #[inline(always)] + pub unsafe fn get_unchecked(&self) -> &T { + &*self.0.get() + } +} + +unsafe impl<T> Sync for RacyCell<T> {} |