From 6aa0fb450f417ce899b43f4539eb226b391a0f2e Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Thu, 8 Apr 2021 18:25:09 +0200 Subject: Goodbye static mut --- macros/src/codegen/post_init.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'macros/src/codegen/post_init.rs') diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs index 96c5df8..7dd1590 100644 --- a/macros/src/codegen/post_init.rs +++ b/macros/src/codegen/post_init.rs @@ -17,16 +17,23 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec { // If it's live let cfgs = app.late_resources[name].cfgs.clone(); if analysis.locations.get(name).is_some() { - // Need to also include the cfgs stmts.push(quote!( - #(#cfgs)* - #mangled_name.as_mut_ptr().write(late.#name); + // We include the cfgs + #(#cfgs)* + // Late resource is a RacyCell> + // - `get_mut_unchecked` to obtain `MaybeUninit` + // - `as_mut_ptr` to obtain a raw pointer to `MaybeUninit` + // - `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() { + // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); + // stmts.push(quote!(#[doc = #doc])); + let idx = Index { index: i as u32, span: Span::call_site(), @@ -36,7 +43,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec { // Store the monotonic let name = util::monotonic_ident(&monotonic.to_string()); 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 -- cgit v1.2.3 From 50f26e78eda57cb1f9f815aa93b357c2cd1a0205 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Thu, 22 Apr 2021 18:38:42 +0200 Subject: Keep comments --- macros/src/codegen/post_init.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'macros/src/codegen/post_init.rs') diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs index 7dd1590..78548bc 100644 --- a/macros/src/codegen/post_init.rs +++ b/macros/src/codegen/post_init.rs @@ -31,6 +31,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec { } for (i, (monotonic, _)) in app.monotonics.iter().enumerate() { + // For future use // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); // stmts.push(quote!(#[doc = #doc])); -- cgit v1.2.3