aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index a4abc4c8..cd511996 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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> {}