aboutsummaryrefslogtreecommitdiff
path: root/macros/src/codegen/post_init.rs
diff options
context:
space:
mode:
authorGravatar Per Lindgren <per.lindgren@ltu.se> 2021-03-10 15:37:11 +0100
committerGravatar Per Lindgren <per.lindgren@ltu.se> 2021-03-10 15:37:11 +0100
commitdb1574bf6b978bfac19efae6ad77fe01511492db (patch)
tree96b5d7892538b4f2cbf6de7c221ca4d78ac71faf /macros/src/codegen/post_init.rs
parent3c86d713a6f8fdb052de80380a17468090e42624 (diff)
downloadrtic-db1574bf6b978bfac19efae6ad77fe01511492db.tar.gz
rtic-db1574bf6b978bfac19efae6ad77fe01511492db.tar.zst
rtic-db1574bf6b978bfac19efae6ad77fe01511492db.zip
goodby static mut, welcome back to UnsafeCell
Diffstat (limited to 'macros/src/codegen/post_init.rs')
-rw-r--r--macros/src/codegen/post_init.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs
index 96c5df80..eec633ba 100644
--- a/macros/src/codegen/post_init.rs
+++ b/macros/src/codegen/post_init.rs
@@ -17,10 +17,14 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
// 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<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);
));
}
}