Goodbye static mut

This commit is contained in:
Emil Fresk 2021-04-08 18:25:09 +02:00
parent 43c5ad79c2
commit 6aa0fb450f
11 changed files with 145 additions and 59 deletions

View file

@ -125,7 +125,7 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
rtic::export::interrupt::free(|_| { rtic::export::interrupt::free(|_| {
use rtic::Monotonic as _; use rtic::Monotonic as _;
use rtic::time::Clock as _; use rtic::time::Clock as _;
if let Some(m) = unsafe{ #app_path::#ident.as_ref() } { if let Some(m) = unsafe{ #app_path::#ident.get_mut_unchecked() } {
if let Ok(v) = m.try_now() { if let Ok(v) = m.try_now() {
v v
} else { } else {

View file

@ -59,7 +59,7 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea
// ); // );
items.push(quote!( items.push(quote!(
#[doc(hidden)] #[doc(hidden)]
static mut #rq: #rq_ty = #rq_expr; static #rq: rtic::RacyCell<#rq_ty> = rtic::RacyCell::new(#rq_expr);
)); ));
let arms = channel let arms = channel
@ -86,8 +86,12 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea
#(#cfgs)* #(#cfgs)*
#t::#name => { #t::#name => {
let #tupled = let #tupled =
#inputs.get_unchecked(usize::from(index)).as_ptr().read(); #inputs
#fq.split().0.enqueue_unchecked(index); .get_unchecked()
.get_unchecked(usize::from(index))
.as_ptr()
.read();
#fq.get_mut_unchecked().split().0.enqueue_unchecked(index);
let priority = &rtic::export::Priority::new(PRIORITY); let priority = &rtic::export::Priority::new(PRIORITY);
#app_path::#name( #app_path::#name(
#locals_new #locals_new
@ -100,7 +104,7 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea
.collect::<Vec<_>>(); .collect::<Vec<_>>();
stmts.push(quote!( stmts.push(quote!(
while let Some((task, index)) = #rq.split().1.dequeue() { while let Some((task, index)) = #rq.get_mut_unchecked().split().1.dequeue() {
match task { match task {
#(#arms)* #(#arms)*
} }

View file

@ -50,11 +50,11 @@ pub fn codegen(
items.push(quote!( items.push(quote!(
#(#cfgs)* #(#cfgs)*
#[doc(hidden)] #[doc(hidden)]
static mut #name: #ty = #expr static #name: rtic::RacyCell<#ty> = rtic::RacyCell::new(#expr)
)); ));
values.push(quote!( values.push(quote!(
#(#cfgs)* #(#cfgs)*
#name: &mut #name #name: #name.get_mut_unchecked()
)); ));
names.push(name); names.push(name);
pats.push(quote!( pats.push(quote!(
@ -64,7 +64,7 @@ pub fn codegen(
} }
if lt.is_some() && has_cfgs { if lt.is_some() && has_cfgs {
fields.push(quote!(__marker__: core::marker::PhantomData<&'a mut ()>)); fields.push(quote!(__marker__: core::marker::PhantomData<&'a ()>));
values.push(quote!(__marker__: core::marker::PhantomData)); values.push(quote!(__marker__: core::marker::PhantomData));
} }

View file

@ -245,14 +245,15 @@ pub fn codegen(
let input = #tupled; let input = #tupled;
unsafe { unsafe {
if let Some(index) = rtic::export::interrupt::free(|_| #app_path::#fq.dequeue()) { if let Some(index) = rtic::export::interrupt::free(|_| #app_path::#fq.get_mut_unchecked().dequeue()) {
#app_path::#inputs #app_path::#inputs
.get_mut_unchecked()
.get_unchecked_mut(usize::from(index)) .get_unchecked_mut(usize::from(index))
.as_mut_ptr() .as_mut_ptr()
.write(input); .write(input);
rtic::export::interrupt::free(|_| { rtic::export::interrupt::free(|_| {
#app_path::#rq.enqueue_unchecked((#app_path::#t::#name, index)); #app_path::#rq.get_mut_unchecked().enqueue_unchecked((#app_path::#t::#name, index));
}); });
rtic::pend(#device::#enum_::#interrupt); rtic::pend(#device::#enum_::#interrupt);
@ -304,6 +305,9 @@ pub fn codegen(
let user_imports = &app.user_imports; let user_imports = &app.user_imports;
let tq_marker = util::mark_internal_ident(&util::timer_queue_marker_ident()); let tq_marker = util::mark_internal_ident(&util::timer_queue_marker_ident());
// let doc = format!(" RTIC internal: {}:{}", file!(), line!());
// items.push(quote!(#[doc = #doc]));
items.push(quote!( items.push(quote!(
/// Holds methods related to this monotonic /// Holds methods related to this monotonic
pub mod #m { pub mod #m {
@ -325,12 +329,16 @@ pub fn codegen(
impl SpawnHandle { impl SpawnHandle {
pub fn cancel(self) -> Result<#ty, ()> { pub fn cancel(self) -> Result<#ty, ()> {
rtic::export::interrupt::free(|_| unsafe { rtic::export::interrupt::free(|_| unsafe {
let tq = &mut *#app_path::#tq.as_mut_ptr(); let tq = &mut *#app_path::#tq.get_mut_unchecked().as_mut_ptr();
if let Some((_task, index)) = tq.cancel_marker(self.marker) { if let Some((_task, index)) = tq.cancel_marker(self.marker) {
// Get the message // Get the message
let msg = #app_path::#inputs.get_unchecked(usize::from(index)).as_ptr().read(); let msg = #app_path::#inputs
.get_unchecked()
.get_unchecked(usize::from(index))
.as_ptr()
.read();
// Return the index to the free queue // Return the index to the free queue
#app_path::#fq.split().0.enqueue_unchecked(index); #app_path::#fq.get_mut_unchecked().split().0.enqueue_unchecked(index);
Ok(msg) Ok(msg)
} else { } else {
@ -350,10 +358,10 @@ pub fn codegen(
pub fn reschedule_at(self, instant: rtic::time::Instant<#app_path::#mono_type>) -> Result<Self, ()> pub fn reschedule_at(self, instant: rtic::time::Instant<#app_path::#mono_type>) -> Result<Self, ()>
{ {
rtic::export::interrupt::free(|_| unsafe { rtic::export::interrupt::free(|_| unsafe {
let marker = #tq_marker; let marker = *#tq_marker.get_mut_unchecked();
#tq_marker = #tq_marker.wrapping_add(1); *#tq_marker.get_mut_unchecked() = #tq_marker.get_mut_unchecked().wrapping_add(1);
let tq = &mut *#app_path::#tq.as_mut_ptr(); let tq = &mut *#app_path::#tq.get_mut_unchecked().as_mut_ptr();
tq.update_marker(self.marker, marker, instant, || #pend).map(|_| SpawnHandle { marker }) tq.update_marker(self.marker, marker, instant, || #pend).map(|_| SpawnHandle { marker })
}) })
@ -373,7 +381,7 @@ pub fn codegen(
D::T: Into<<#app_path::#mono_type as rtic::time::Clock>::T>, D::T: Into<<#app_path::#mono_type as rtic::time::Clock>::T>,
{ {
let instant = if rtic::export::interrupt::free(|_| unsafe { #app_path::#m_ident.is_none() }) { let instant = if rtic::export::interrupt::free(|_| unsafe { #app_path::#m_ident.get_mut_unchecked().is_none() }) {
rtic::time::Instant::new(0) rtic::time::Instant::new(0)
} else { } else {
#app_path::monotonics::#m::now() #app_path::monotonics::#m::now()
@ -390,19 +398,21 @@ pub fn codegen(
) -> Result<SpawnHandle, #ty> { ) -> Result<SpawnHandle, #ty> {
unsafe { unsafe {
let input = #tupled; let input = #tupled;
if let Some(index) = rtic::export::interrupt::free(|_| #app_path::#fq.dequeue()) { if let Some(index) = rtic::export::interrupt::free(|_| #app_path::#fq.get_mut_unchecked().dequeue()) {
#app_path::#inputs #app_path::#inputs
.get_mut_unchecked()
.get_unchecked_mut(usize::from(index)) .get_unchecked_mut(usize::from(index))
.as_mut_ptr() .as_mut_ptr()
.write(input); .write(input);
#app_path::#instants #app_path::#instants
.get_mut_unchecked()
.get_unchecked_mut(usize::from(index)) .get_unchecked_mut(usize::from(index))
.as_mut_ptr() .as_mut_ptr()
.write(instant); .write(instant);
rtic::export::interrupt::free(|_| { rtic::export::interrupt::free(|_| {
let marker = #tq_marker; let marker = *#tq_marker.get_mut_unchecked();
let nr = rtic::export::NotReady { let nr = rtic::export::NotReady {
instant, instant,
index, index,
@ -410,15 +420,15 @@ pub fn codegen(
marker, marker,
}; };
#tq_marker = #tq_marker.wrapping_add(1); *#tq_marker.get_mut_unchecked() = #tq_marker.get_mut_unchecked().wrapping_add(1);
let tq = unsafe { &mut *#app_path::#tq.as_mut_ptr() }; let tq = &mut *#app_path::#tq.get_mut_unchecked().as_mut_ptr();
tq.enqueue_unchecked( tq.enqueue_unchecked(
nr, nr,
|| #enable_interrupt, || #enable_interrupt,
|| #pend, || #pend,
#app_path::#m_ident.as_mut()); #app_path::#m_ident.get_mut_unchecked().as_mut());
Ok(SpawnHandle { marker }) Ok(SpawnHandle { marker })
}) })

View file

@ -17,16 +17,23 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
// If it's live // If it's live
let cfgs = app.late_resources[name].cfgs.clone(); let cfgs = app.late_resources[name].cfgs.clone();
if analysis.locations.get(name).is_some() { if analysis.locations.get(name).is_some() {
// Need to also include the cfgs
stmts.push(quote!( stmts.push(quote!(
// We include the cfgs
#(#cfgs)* #(#cfgs)*
#mangled_name.as_mut_ptr().write(late.#name); // Late resource is a RacyCell<MaybeUninit<T>>
// - `get_mut_unchecked` to obtain `MaybeUninit<T>`
// - `as_mut_ptr` to obtain a raw pointer to `MaybeUninit<T>`
// - `write` the defined value for the late resource T
#mangled_name.get_mut_unchecked().as_mut_ptr().write(late.#name);
)); ));
} }
} }
} }
for (i, (monotonic, _)) in app.monotonics.iter().enumerate() { for (i, (monotonic, _)) in app.monotonics.iter().enumerate() {
// let doc = format!(" RTIC internal: {}:{}", file!(), line!());
// stmts.push(quote!(#[doc = #doc]));
let idx = Index { let idx = Index {
index: i as u32, index: i as u32,
span: Span::call_site(), span: Span::call_site(),
@ -36,7 +43,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
// Store the monotonic // Store the monotonic
let name = util::monotonic_ident(&monotonic.to_string()); let name = util::monotonic_ident(&monotonic.to_string());
let name = util::mark_internal_ident(&name); let name = util::mark_internal_ident(&name);
stmts.push(quote!(#name = Some(monotonics.#idx);)); stmts.push(quote!(*#name.get_mut_unchecked() = Some(monotonics.#idx);));
} }
// Enable the interrupts -- this completes the `init`-ialization phase // Enable the interrupts -- this completes the `init`-ialization phase

View file

@ -20,7 +20,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
let fq_ident = util::mark_internal_ident(&fq_ident); let fq_ident = util::mark_internal_ident(&fq_ident);
stmts.push(quote!( stmts.push(quote!(
(0..#cap).for_each(|i| #fq_ident.enqueue_unchecked(i)); (0..#cap).for_each(|i| #fq_ident.get_mut_unchecked().enqueue_unchecked(i));
)); ));
} }
@ -86,7 +86,9 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
let tq = util::mark_internal_ident(&tq); let tq = util::mark_internal_ident(&tq);
// Initialize timer queues // Initialize timer queues
stmts.push(quote!(#tq.as_mut_ptr().write(rtic::export::TimerQueue::new());)); stmts.push(
quote!(#tq.get_mut_unchecked().as_mut_ptr().write(rtic::export::TimerQueue::new());),
);
// Compile time assert that this priority is supported by the device // Compile time assert that this priority is supported by the device
stmts.push(quote!(let _ = [(); ((1 << #nvic_prio_bits) - #priority as usize)];)); stmts.push(quote!(let _ = [(); ((1 << #nvic_prio_bits) - #priority as usize)];));

View file

@ -4,13 +4,20 @@ use rtic_syntax::{analyze::Ownership, ast::App};
use crate::{analyze::Analysis, check::Extra, codegen::util}; use crate::{analyze::Analysis, check::Extra, codegen::util};
/// Generates `static [mut]` variables and resource proxies /// Generates `static` variables and resource proxies
/// Early resources are stored in `RacyCell<T>`
/// Late resource are stored in `RacyCell<MaybeUninit<T>>`
///
/// Safety:
/// - RacyCell<T> access is `unsafe`.
/// - RacyCell<MaybeUninit> is always written to before user access, thus
// the generated code for user access can safely `assume_init`.
pub fn codegen( pub fn codegen(
app: &App, app: &App,
analysis: &Analysis, analysis: &Analysis,
extra: &Extra, extra: &Extra,
) -> ( ) -> (
// mod_app -- the `static [mut]` variables behind the proxies // mod_app -- the `static` variables behind the proxies
Vec<TokenStream2>, Vec<TokenStream2>,
// mod_resources -- the `resources` module // mod_resources -- the `resources` module
TokenStream2, TokenStream2,
@ -24,35 +31,50 @@ pub fn codegen(
let mangled_name = util::mark_internal_ident(&name); let mangled_name = util::mark_internal_ident(&name);
{ {
// TODO: do we really need this in the single core case
// late resources in `util::link_section_uninit`
let section = if expr.is_none() { let section = if expr.is_none() {
util::link_section_uninit(true) util::link_section_uninit(true)
} else { } else {
None None
}; };
// resource type and assigned value
let (ty, expr) = if let Some(expr) = expr { let (ty, expr) = if let Some(expr) = expr {
(quote!(#ty), quote!(#expr)) // early resource
} else {
( (
quote!(core::mem::MaybeUninit<#ty>), quote!(rtic::RacyCell<#ty>),
quote!(core::mem::MaybeUninit::uninit()), quote!(rtic::RacyCell::new(#expr)),
)
} else {
// late resource
(
quote!(rtic::RacyCell<core::mem::MaybeUninit<#ty>>),
quote!(rtic::RacyCell::new(core::mem::MaybeUninit::uninit())),
) )
}; };
let attrs = &res.attrs; let attrs = &res.attrs;
// let doc = format!(" RTIC internal: {}:{}", file!(), line!());
mod_app.push(quote!( mod_app.push(quote!(
#[allow(non_upper_case_globals)] #[allow(non_upper_case_globals)]
// #[doc = #doc]
#[doc(hidden)] #[doc(hidden)]
#(#attrs)* #(#attrs)*
#(#cfgs)* #(#cfgs)*
#section #section
static mut #mangled_name: #ty = #expr; static #mangled_name: #ty = #expr;
)); ));
} }
let r_prop = &res.properties; let r_prop = &res.properties;
// let doc = format!(" RTIC internal: {}:{}", file!(), line!());
if !r_prop.task_local && !r_prop.lock_free { if !r_prop.task_local && !r_prop.lock_free {
mod_resources.push(quote!( mod_resources.push(quote!(
// #[doc = #doc]
#[doc(hidden)]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
#(#cfgs)* #(#cfgs)*
pub struct #name<'a> { pub struct #name<'a> {
@ -73,15 +95,23 @@ pub fn codegen(
} }
)); ));
let ptr = if expr.is_none() { let (ptr, _doc) = if expr.is_none() {
// late resource
(
quote!( quote!(
#(#cfgs)* #(#cfgs)*
#mangled_name.as_mut_ptr() #mangled_name.get_mut_unchecked().as_mut_ptr()
),
"late",
) )
} else { } else {
// early resource
(
quote!( quote!(
#(#cfgs)* #(#cfgs)*
&mut #mangled_name #mangled_name.get_mut_unchecked()
),
"early",
) )
}; };
@ -92,6 +122,8 @@ pub fn codegen(
None => 0, None => 0,
}; };
// let doc = format!(" RTIC internal ({} resource): {}:{}", doc, file!(), line!());
mod_app.push(util::impl_mutex( mod_app.push(util::impl_mutex(
extra, extra,
cfgs, cfgs,

View file

@ -79,9 +79,9 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
let is_late = expr.is_none(); let is_late = expr.is_none();
if is_late { if is_late {
let expr = if access.is_exclusive() { let expr = if access.is_exclusive() {
quote!(&mut *#mangled_name.as_mut_ptr()) quote!(&mut *#mangled_name.get_mut_unchecked().as_mut_ptr())
} else { } else {
quote!(&*#mangled_name.as_ptr()) quote!(&*#mangled_name.get_unchecked().as_ptr())
}; };
values.push(quote!( values.push(quote!(
@ -91,7 +91,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
} else { } else {
values.push(quote!( values.push(quote!(
#(#cfgs)* #(#cfgs)*
#name: &#mut_ #mangled_name #name: #mangled_name.get_mut_unchecked()
)); ));
} }
} }

View file

@ -52,7 +52,7 @@ pub fn codegen(
// /// Queue version of a free-list that keeps track of empty slots in // /// Queue version of a free-list that keeps track of empty slots in
// /// the following buffers // /// the following buffers
#[doc(hidden)] #[doc(hidden)]
static mut #fq: #fq_ty = #fq_expr; static #fq: rtic::RacyCell<#fq_ty> = rtic::RacyCell::new(#fq_expr);
)); ));
let elems = &(0..cap) let elems = &(0..cap)
@ -65,13 +65,15 @@ pub fn codegen(
let mono_type = &monotonic.ty; let mono_type = &monotonic.ty;
let uninit = mk_uninit(); let uninit = mk_uninit();
// let doc = format!(" RTIC internal: {}:{}", file!(), line!());
mod_app.push(quote!( mod_app.push(quote!(
#uninit #uninit
// /// Buffer that holds the instants associated to the inputs of a task // /// Buffer that holds the instants associated to the inputs of a task
// #[doc = #doc]
#[doc(hidden)] #[doc(hidden)]
static mut #instants: static #instants:
[core::mem::MaybeUninit<rtic::time::Instant<#mono_type>>; #cap_lit] = rtic::RacyCell<[core::mem::MaybeUninit<rtic::time::Instant<#mono_type>>; #cap_lit]> =
[#(#elems,)*]; rtic::RacyCell::new([#(#elems,)*]);
)); ));
} }
@ -82,8 +84,8 @@ pub fn codegen(
#uninit #uninit
// /// Buffer that holds the inputs of a task // /// Buffer that holds the inputs of a task
#[doc(hidden)] #[doc(hidden)]
static mut #inputs_ident: [core::mem::MaybeUninit<#input_ty>; #cap_lit] = static #inputs_ident: rtic::RacyCell<[core::mem::MaybeUninit<#input_ty>; #cap_lit]> =
[#(#elems,)*]; rtic::RacyCell::new([#(#elems,)*]);
)); ));
// `${task}Resources` // `${task}Resources`

View file

@ -15,7 +15,7 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea
// #[doc = #doc] // #[doc = #doc]
#[doc(hidden)] #[doc(hidden)]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
static mut #tq_marker: u32 = 0; static #tq_marker: rtic::RacyCell<u32> = rtic::RacyCell::new(0);
)); ));
let t = util::schedule_t_ident(); let t = util::schedule_t_ident();
@ -71,9 +71,11 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea
let tq_ty = let tq_ty =
quote!(core::mem::MaybeUninit<rtic::export::TimerQueue<#mono_type, #t, #n>>); quote!(core::mem::MaybeUninit<rtic::export::TimerQueue<#mono_type, #t, #n>>);
// let doc = format!(" RTIC internal: {}:{}", file!(), line!());
items.push(quote!( items.push(quote!(
#[doc(hidden)] #[doc(hidden)]
static mut #tq: #tq_ty = core::mem::MaybeUninit::uninit(); static #tq: rtic::RacyCell<#tq_ty> =
rtic::RacyCell::new(core::mem::MaybeUninit::uninit());
)); ));
let mono = util::monotonic_ident(&monotonic_name); let mono = util::monotonic_ident(&monotonic_name);
@ -82,7 +84,7 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea
items.push(quote!( items.push(quote!(
#[doc(hidden)] #[doc(hidden)]
static mut #mono: Option<#mono_type> = None; static #mono: rtic::RacyCell<Option<#mono_type>> = rtic::RacyCell::new(None);
)); ));
} }
@ -113,7 +115,7 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea
quote!( quote!(
#(#cfgs)* #(#cfgs)*
#t::#name => { #t::#name => {
rtic::export::interrupt::free(|_| #rq.split().0.enqueue_unchecked((#rqt::#name, index))); rtic::export::interrupt::free(|_| #rq.get_mut_unchecked().split().0.enqueue_unchecked((#rqt::#name, index)));
#pend #pend
} }
@ -132,10 +134,9 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea
#[no_mangle] #[no_mangle]
#[allow(non_snake_case)] #[allow(non_snake_case)]
unsafe fn #bound_interrupt() { unsafe fn #bound_interrupt() {
while let Some((task, index)) = rtic::export::interrupt::free(|_| while let Some((task, index)) = rtic::export::interrupt::free(|_|
if let Some(mono) = #app_path::#m_ident.as_mut() { if let Some(mono) = #app_path::#m_ident.get_mut_unchecked().as_mut() {
(&mut *#tq.as_mut_ptr()).dequeue(|| #disable_isr, mono) (&mut *#tq.get_mut_unchecked().as_mut_ptr()).dequeue(|| #disable_isr, mono)
} else { } else {
// We can only use the timer queue if `init` has returned, and it // We can only use the timer queue if `init` has returned, and it
// writes the `Some(monotonic)` we are accessing here. // writes the `Some(monotonic)` we are accessing here.
@ -147,7 +148,7 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea
} }
} }
rtic::export::interrupt::free(|_| if let Some(mono) = #app_path::#m_ident.as_mut() { rtic::export::interrupt::free(|_| if let Some(mono) = #app_path::#m_ident.get_mut_unchecked().as_mut() {
mono.on_interrupt(); mono.on_interrupt();
}); });
} }

View file

@ -57,3 +57,31 @@ where
{ {
NVIC::pend(interrupt) 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> {}