mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-18 22:05:37 +01:00
Goodbye static mut
This commit is contained in:
parent
43c5ad79c2
commit
6aa0fb450f
11 changed files with 145 additions and 59 deletions
28
src/lib.rs
28
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> {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue