From 8050304c9d613b48f97c33dad18b6008e9d76e9f Mon Sep 17 00:00:00 2001 From: Per Lindgren Date: Wed, 20 Oct 2021 09:30:42 +0200 Subject: [PATCH] wip Priority leakage --- macros/src/codegen/shared_resources.rs | 4 +- macros/src/codegen/shared_resources_struct.rs | 45 ++++++++++++------- macros/src/codegen/util.rs | 10 +---- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/macros/src/codegen/shared_resources.rs b/macros/src/codegen/shared_resources.rs index b27c827c23..0e61b67936 100644 --- a/macros/src/codegen/shared_resources.rs +++ b/macros/src/codegen/shared_resources.rs @@ -85,10 +85,10 @@ pub fn codegen( mod_app.push(util::impl_mutex( extra, cfgs, - true, - &name, + quote!(shared_resources::#name), quote!(#ty), ceiling, + quote!(self.priority()), ptr, )); } diff --git a/macros/src/codegen/shared_resources_struct.rs b/macros/src/codegen/shared_resources_struct.rs index d4184d0bcd..f276724469 100644 --- a/macros/src/codegen/shared_resources_struct.rs +++ b/macros/src/codegen/shared_resources_struct.rs @@ -29,6 +29,7 @@ pub fn codegen( let mut fields_mut = vec![]; let mut values_mut = vec![]; let mut max_ceiling = 0; + let mut field_get_prio = None; for (name, access) in resources { let res = app.shared_resources.get(name).expect("UNREACHABLE"); @@ -63,6 +64,10 @@ pub fn codegen( pub #name: shared_resources::#name<'a> )); + field_get_prio = Some(quote!( + #name + )); + values.push(quote!( #(#cfgs)* #name: shared_resources::#name::new(priority) @@ -148,7 +153,6 @@ pub fn codegen( #[doc = #doc] pub struct #ident<#lt> { #(#fields,)* - priority: &'a rtic::export::Priority, } // Used by the lock-all API @@ -166,16 +170,29 @@ pub fn codegen( Some(quote!(priority: &#lt rtic::export::Priority)) }; - // Generate code for the lock-all API - let lock_all = util::impl_mutex( - extra, - &vec![], // TODO: what cfg should go here? - false, // resource proxy at top level (not in shared_resources) - &ident, - quote!(#ident_mut), - max_ceiling, - quote!(&mut #ident_mut::new()), - ); + let (lock_all, get_prio) = if let Some(name) = field_get_prio { + ( + util::impl_mutex( + extra, + &vec![], // TODO: what cfg should go here? + quote!(#ident), + quote!(#ident_mut), + max_ceiling, + quote!(self.priority()), + quote!(&mut #ident_mut::new()), + ), + quote!( + // Used by the lock-all API + #[inline(always)] + pub unsafe fn priority(&self) -> &rtic::export::Priority { + //panic!("here {:?}", self); + self.#name.priority() + } + ), + ) + } else { + (quote!(), quote!()) + }; let implementations = quote!( impl<#lt> #ident<#lt> { @@ -183,14 +200,10 @@ pub fn codegen( pub unsafe fn new(#arg) -> Self { #ident { #(#values,)* - priority } } - #[inline(always)] - pub unsafe fn priority(&self) -> &rtic::export::Priority { - self.priority - } + #get_prio } // Used by the lock-all API diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index d16faf33ed..9f84359c05 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -23,18 +23,12 @@ pub fn fq_ident(task: &Ident) -> Ident { pub fn impl_mutex( extra: &Extra, cfgs: &[Attribute], - resources_prefix: bool, - name: &Ident, + path: TokenStream2, ty: TokenStream2, ceiling: u8, + priority: TokenStream2, ptr: TokenStream2, ) -> TokenStream2 { - let (path, priority) = if resources_prefix { - (quote!(shared_resources::#name), quote!(self.priority())) - } else { - (quote!(#name), quote!(self.priority)) - }; - let device = &extra.device; quote!( #(#cfgs)*