diff options
author | 2019-05-09 18:25:34 +0200 | |
---|---|---|
committer | 2019-05-09 18:25:34 +0200 | |
commit | 36073a63426e0955aaa3e0745a3b4e29aeb076e3 (patch) | |
tree | a8b3223555f259d35337e2a4097c362a16a3d55d /macros/src/codegen.rs | |
parent | bc024f197929be1ce7dac9e6cbf6672c3980437e (diff) | |
download | rtic-36073a63426e0955aaa3e0745a3b4e29aeb076e3.tar.gz rtic-36073a63426e0955aaa3e0745a3b4e29aeb076e3.tar.zst rtic-36073a63426e0955aaa3e0745a3b4e29aeb076e3.zip |
generate resource proxies only when needed
only `static mut` resources need proxies
Diffstat (limited to '')
-rw-r--r-- | macros/src/codegen.rs | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 3fae75b7..c33ecf63 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -234,40 +234,43 @@ fn resources( )); } - if let Some(Ownership::Shared { ceiling }) = analysis.ownerships.get(name) { - let ptr = if res.expr.is_none() { - quote!(#name.as_mut_ptr()) - } else { - quote!(&mut #name) - }; - - mod_resources.push(quote!( - pub struct #name<'a> { - priority: &'a Priority, - } + // generate a resource proxy when needed + if res.mutability.is_some() { + if let Some(Ownership::Shared { ceiling }) = analysis.ownerships.get(name) { + let ptr = if res.expr.is_none() { + quote!(#name.as_mut_ptr()) + } else { + quote!(&mut #name) + }; - impl<'a> #name<'a> { - #[inline(always)] - pub unsafe fn new(priority: &'a Priority) -> Self { - #name { priority } + mod_resources.push(quote!( + pub struct #name<'a> { + priority: &'a Priority, } - #[inline(always)] - pub unsafe fn priority(&self) -> &Priority { - self.priority + impl<'a> #name<'a> { + #[inline(always)] + pub unsafe fn new(priority: &'a Priority) -> Self { + #name { priority } + } + + #[inline(always)] + pub unsafe fn priority(&self) -> &Priority { + self.priority + } } - } - )); + )); - const_app.push(impl_mutex( - app, - cfgs, - true, - name, - quote!(#ty), - *ceiling, - ptr, - )); + const_app.push(impl_mutex( + app, + cfgs, + true, + name, + quote!(#ty), + *ceiling, + ptr, + )); + } } } |