mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-30 15:34:33 +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!(
|
let ptr = quote!(
|
||||||
#(#cfgs)*
|
#(#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) {
|
let ceiling = match analysis.ownerships.get(name) {
|
||||||
|
|
|
@ -47,18 +47,15 @@ pub fn codegen(
|
||||||
let mangled_name = util::static_shared_resource_ident(&name);
|
let mangled_name = util::static_shared_resource_ident(&name);
|
||||||
|
|
||||||
if !res.properties.lock_free {
|
if !res.properties.lock_free {
|
||||||
|
lt = Some(quote!('a));
|
||||||
if access.is_shared() {
|
if access.is_shared() {
|
||||||
// [&x] (shared)
|
// [&x] (shared)
|
||||||
lt = Some(quote!('a));
|
|
||||||
|
|
||||||
fields.push(quote!(
|
fields.push(quote!(
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
pub #name: &'a #ty
|
pub #name: &'a #ty
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
// Resource proxy
|
// Resource proxy
|
||||||
lt = Some(quote!('a));
|
|
||||||
|
|
||||||
fields.push(quote!(
|
fields.push(quote!(
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
pub #name: shared_resources::#name<'a>
|
pub #name: shared_resources::#name<'a>
|
||||||
|
@ -76,7 +73,7 @@ pub fn codegen(
|
||||||
// Lock-all related
|
// Lock-all related
|
||||||
fields_mut.push(quote!(
|
fields_mut.push(quote!(
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
pub #name: &'static mut #ty
|
pub #name: &#lt mut #ty
|
||||||
));
|
));
|
||||||
|
|
||||||
values_mut.push(quote!(
|
values_mut.push(quote!(
|
||||||
|
@ -159,7 +156,7 @@ pub fn codegen(
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[doc = #doc_mut]
|
#[doc = #doc_mut]
|
||||||
pub struct #ident_mut {
|
pub struct #ident_mut<#lt> {
|
||||||
#(#fields_mut,)*
|
#(#fields_mut,)*
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -176,16 +173,15 @@ pub fn codegen(
|
||||||
extra,
|
extra,
|
||||||
&vec![], // TODO: what cfg should go here?
|
&vec![], // TODO: what cfg should go here?
|
||||||
quote!(#ident),
|
quote!(#ident),
|
||||||
quote!(#ident_mut),
|
quote!(#ident_mut<#lt>),
|
||||||
max_ceiling,
|
max_ceiling,
|
||||||
quote!(self.priority()),
|
quote!(self.priority()),
|
||||||
quote!(&mut #ident_mut::new()),
|
quote!(|| { &mut #ident_mut::new() }),
|
||||||
),
|
),
|
||||||
quote!(
|
quote!(
|
||||||
// Used by the lock-all API
|
// Used by the lock-all API
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn priority(&self) -> &rtic::export::Priority {
|
pub unsafe fn priority(&self) -> &rtic::export::Priority {
|
||||||
//panic!("here {:?}", self);
|
|
||||||
self.#name.priority()
|
self.#name.priority()
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
@ -207,7 +203,7 @@ pub fn codegen(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used by the lock-all API
|
// Used by the lock-all API
|
||||||
impl #ident_mut {
|
impl<#lt> #ident_mut<#lt> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn new() -> Self {
|
pub unsafe fn new() -> Self {
|
||||||
#ident_mut {
|
#ident_mut {
|
||||||
|
|
|
@ -134,7 +134,7 @@ where
|
||||||
#[cfg(armv7m)]
|
#[cfg(armv7m)]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn lock<T, R>(
|
pub unsafe fn lock<T, R>(
|
||||||
ptr: *mut T,
|
ptr: impl Fn() -> *mut T,
|
||||||
priority: &Priority,
|
priority: &Priority,
|
||||||
ceiling: u8,
|
ceiling: u8,
|
||||||
nvic_prio_bits: u8,
|
nvic_prio_bits: u8,
|
||||||
|
@ -145,19 +145,19 @@ pub unsafe fn lock<T, R>(
|
||||||
if current < ceiling {
|
if current < ceiling {
|
||||||
if ceiling == (1 << nvic_prio_bits) {
|
if ceiling == (1 << nvic_prio_bits) {
|
||||||
priority.set(u8::max_value());
|
priority.set(u8::max_value());
|
||||||
let r = interrupt::free(|_| f(&mut *ptr));
|
let r = interrupt::free(|_| f(&mut *ptr()));
|
||||||
priority.set(current);
|
priority.set(current);
|
||||||
r
|
r
|
||||||
} else {
|
} else {
|
||||||
priority.set(ceiling);
|
priority.set(ceiling);
|
||||||
basepri::write(logical2hw(ceiling, nvic_prio_bits));
|
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));
|
basepri::write(logical2hw(current, nvic_prio_bits));
|
||||||
priority.set(current);
|
priority.set(current);
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
f(&mut *ptr)
|
f(&mut *ptr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ pub unsafe fn lock<T, R>(
|
||||||
#[cfg(not(armv7m))]
|
#[cfg(not(armv7m))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn lock<T, R>(
|
pub unsafe fn lock<T, R>(
|
||||||
ptr: *mut T,
|
ptr: impl Fn() -> *mut T,
|
||||||
priority: &Priority,
|
priority: &Priority,
|
||||||
ceiling: u8,
|
ceiling: u8,
|
||||||
_nvic_prio_bits: u8,
|
_nvic_prio_bits: u8,
|
||||||
|
@ -181,11 +181,11 @@ pub unsafe fn lock<T, R>(
|
||||||
|
|
||||||
if current < ceiling {
|
if current < ceiling {
|
||||||
priority.set(u8::max_value());
|
priority.set(u8::max_value());
|
||||||
let r = interrupt::free(|_| f(&mut *ptr));
|
let r = interrupt::free(|_| f(&mut *ptr()));
|
||||||
priority.set(current);
|
priority.set(current);
|
||||||
r
|
r
|
||||||
} else {
|
} else {
|
||||||
f(&mut *ptr)
|
f(&mut *ptr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue