mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 20:22:51 +01:00
attempt to pass Fn closure instead of pointer
This commit is contained in:
parent
426522df6e
commit
de94306128
3 changed files with 16 additions and 18 deletions
|
@ -67,9 +67,11 @@ pub fn codegen(
|
|||
}
|
||||
));
|
||||
|
||||
// ptr is an Fn closure that return *mut T
|
||||
let ptr = quote!(
|
||||
#(#cfgs)*
|
||||
#mangled_name.get_mut() as *mut _
|
||||
|| { #mangled_name.get_mut() as *mut _ }
|
||||
// || { #mangled_name.get_mut_unchecked().as_mut_ptr() }
|
||||
);
|
||||
|
||||
let ceiling = match analysis.ownerships.get(name) {
|
||||
|
|
|
@ -47,18 +47,15 @@ pub fn codegen(
|
|||
let mangled_name = util::static_shared_resource_ident(&name);
|
||||
|
||||
if !res.properties.lock_free {
|
||||
lt = Some(quote!('a));
|
||||
if access.is_shared() {
|
||||
// [&x] (shared)
|
||||
lt = Some(quote!('a));
|
||||
|
||||
fields.push(quote!(
|
||||
#(#cfgs)*
|
||||
pub #name: &'a #ty
|
||||
));
|
||||
} else {
|
||||
// Resource proxy
|
||||
lt = Some(quote!('a));
|
||||
|
||||
fields.push(quote!(
|
||||
#(#cfgs)*
|
||||
pub #name: shared_resources::#name<'a>
|
||||
|
@ -76,7 +73,7 @@ pub fn codegen(
|
|||
// Lock-all related
|
||||
fields_mut.push(quote!(
|
||||
#(#cfgs)*
|
||||
pub #name: &'static mut #ty
|
||||
pub #name: &#lt mut #ty
|
||||
));
|
||||
|
||||
values_mut.push(quote!(
|
||||
|
@ -159,7 +156,7 @@ pub fn codegen(
|
|||
#[allow(non_snake_case)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[doc = #doc_mut]
|
||||
pub struct #ident_mut {
|
||||
pub struct #ident_mut<#lt> {
|
||||
#(#fields_mut,)*
|
||||
}
|
||||
);
|
||||
|
@ -176,16 +173,15 @@ pub fn codegen(
|
|||
extra,
|
||||
&vec![], // TODO: what cfg should go here?
|
||||
quote!(#ident),
|
||||
quote!(#ident_mut),
|
||||
quote!(#ident_mut<#lt>),
|
||||
max_ceiling,
|
||||
quote!(self.priority()),
|
||||
quote!(&mut #ident_mut::new()),
|
||||
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()
|
||||
}
|
||||
),
|
||||
|
@ -207,7 +203,7 @@ pub fn codegen(
|
|||
}
|
||||
|
||||
// Used by the lock-all API
|
||||
impl #ident_mut {
|
||||
impl<#lt> #ident_mut<#lt> {
|
||||
#[inline(always)]
|
||||
pub unsafe fn new() -> Self {
|
||||
#ident_mut {
|
||||
|
|
|
@ -134,7 +134,7 @@ where
|
|||
#[cfg(armv7m)]
|
||||
#[inline(always)]
|
||||
pub unsafe fn lock<T, R>(
|
||||
ptr: *mut T,
|
||||
ptr: impl Fn() -> *mut T,
|
||||
priority: &Priority,
|
||||
ceiling: u8,
|
||||
nvic_prio_bits: u8,
|
||||
|
@ -145,19 +145,19 @@ pub unsafe fn lock<T, R>(
|
|||
if current < ceiling {
|
||||
if ceiling == (1 << nvic_prio_bits) {
|
||||
priority.set(u8::max_value());
|
||||
let r = interrupt::free(|_| f(&mut *ptr));
|
||||
let r = interrupt::free(|_| f(&mut *ptr()));
|
||||
priority.set(current);
|
||||
r
|
||||
} else {
|
||||
priority.set(ceiling);
|
||||
basepri::write(logical2hw(ceiling, nvic_prio_bits));
|
||||
let r = f(&mut *ptr);
|
||||
let r = f(&mut *ptr()); // inside of lock
|
||||
basepri::write(logical2hw(current, nvic_prio_bits));
|
||||
priority.set(current);
|
||||
r
|
||||
}
|
||||
} else {
|
||||
f(&mut *ptr)
|
||||
f(&mut *ptr())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,7 @@ pub unsafe fn lock<T, R>(
|
|||
#[cfg(not(armv7m))]
|
||||
#[inline(always)]
|
||||
pub unsafe fn lock<T, R>(
|
||||
ptr: *mut T,
|
||||
ptr: impl Fn() -> *mut T,
|
||||
priority: &Priority,
|
||||
ceiling: u8,
|
||||
_nvic_prio_bits: u8,
|
||||
|
@ -181,11 +181,11 @@ pub unsafe fn lock<T, R>(
|
|||
|
||||
if current < ceiling {
|
||||
priority.set(u8::max_value());
|
||||
let r = interrupt::free(|_| f(&mut *ptr));
|
||||
let r = interrupt::free(|_| f(&mut *ptr()));
|
||||
priority.set(current);
|
||||
r
|
||||
} else {
|
||||
f(&mut *ptr)
|
||||
f(&mut *ptr())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue