mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-27 14:04:56 +01:00
api test (all but lock automated)
This commit is contained in:
parent
4cefde75e8
commit
05586401c7
3 changed files with 61 additions and 35 deletions
|
@ -108,34 +108,6 @@ pub fn codegen(
|
||||||
|
|
||||||
let to_gen = quote! {
|
let to_gen = quote! {
|
||||||
|
|
||||||
pub struct __rtic_internal_fooShared {
|
|
||||||
a: &'static mut u32,
|
|
||||||
b: &'static mut i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl __rtic_internal_fooShared {
|
|
||||||
#[inline(always)]
|
|
||||||
pub unsafe fn new() -> Self {
|
|
||||||
__rtic_internal_fooShared {
|
|
||||||
a: &mut *__rtic_internal_shared_resource_a
|
|
||||||
.get_mut_unchecked()
|
|
||||||
.as_mut_ptr(),
|
|
||||||
b: &mut *__rtic_internal_shared_resource_b
|
|
||||||
.get_mut_unchecked()
|
|
||||||
.as_mut_ptr(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// #[doc = #manual]
|
|
||||||
// impl<'a> __rtic_internal_fooSharedResources<'a> {
|
|
||||||
// #[inline(always)]
|
|
||||||
// pub unsafe fn priority(&self) -> &rtic::export::Priority {
|
|
||||||
// self.priority
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
#[doc = #manual]
|
#[doc = #manual]
|
||||||
impl<'a> rtic::Mutex for __rtic_internal_fooSharedResources<'a> {
|
impl<'a> rtic::Mutex for __rtic_internal_fooSharedResources<'a> {
|
||||||
type T = __rtic_internal_fooShared;
|
type T = __rtic_internal_fooShared;
|
||||||
|
|
|
@ -19,6 +19,10 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
|
||||||
let mut values = vec![];
|
let mut values = vec![];
|
||||||
let mut has_cfgs = false;
|
let mut has_cfgs = false;
|
||||||
|
|
||||||
|
// Lock-all api related
|
||||||
|
let mut fields_mut = vec![];
|
||||||
|
let mut values_mut = vec![];
|
||||||
|
|
||||||
for (name, access) in resources {
|
for (name, access) in resources {
|
||||||
let res = app.shared_resources.get(name).expect("UNREACHABLE");
|
let res = app.shared_resources.get(name).expect("UNREACHABLE");
|
||||||
|
|
||||||
|
@ -36,6 +40,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
|
||||||
|
|
||||||
if !res.properties.lock_free {
|
if !res.properties.lock_free {
|
||||||
if access.is_shared() {
|
if access.is_shared() {
|
||||||
|
// [&x] (shared)
|
||||||
lt = Some(quote!('a));
|
lt = Some(quote!('a));
|
||||||
|
|
||||||
fields.push(quote!(
|
fields.push(quote!(
|
||||||
|
@ -57,6 +62,18 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
|
||||||
|
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// Lock-all related
|
||||||
|
fields_mut.push(quote!(
|
||||||
|
#(#cfgs)*
|
||||||
|
pub #name: &'static mut #ty
|
||||||
|
));
|
||||||
|
|
||||||
|
values_mut.push(quote!(
|
||||||
|
#(#cfgs)*
|
||||||
|
#name: &mut *#mangled_name.get_mut_unchecked().as_mut_ptr()
|
||||||
|
|
||||||
|
));
|
||||||
|
|
||||||
// continue as the value has been filled,
|
// continue as the value has been filled,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -102,6 +119,14 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
|
||||||
|
|
||||||
let doc = format!("Shared resources `{}` has access to", ctxt.ident(app));
|
let doc = format!("Shared resources `{}` has access to", ctxt.ident(app));
|
||||||
let ident = util::shared_resources_ident(ctxt, app);
|
let ident = util::shared_resources_ident(ctxt, app);
|
||||||
|
|
||||||
|
// Lock-all related
|
||||||
|
let doc_mut = format!(
|
||||||
|
"Shared resources `{}` has lock all access to",
|
||||||
|
ctxt.ident(app)
|
||||||
|
);
|
||||||
|
let ident_mut = util::shared_resources_ident_mut(ctxt, app);
|
||||||
|
|
||||||
let item = quote!(
|
let item = quote!(
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
|
@ -111,11 +136,12 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
|
||||||
priority: &'a rtic::export::Priority,
|
priority: &'a rtic::export::Priority,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<#lt>#ident<#lt> {
|
// Used by the lock-all API
|
||||||
#[inline(always)]
|
#[allow(non_snake_case)]
|
||||||
pub unsafe fn priority(&self) -> &rtic::export::Priority {
|
#[allow(non_camel_case_types)]
|
||||||
self.priority
|
#[doc = #doc_mut]
|
||||||
}
|
pub struct #ident_mut {
|
||||||
|
#(#fields_mut,)*
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -124,7 +150,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
|
||||||
} else {
|
} else {
|
||||||
Some(quote!(priority: &#lt rtic::export::Priority))
|
Some(quote!(priority: &#lt rtic::export::Priority))
|
||||||
};
|
};
|
||||||
let constructor = quote!(
|
let implementations = quote!(
|
||||||
impl<#lt> #ident<#lt> {
|
impl<#lt> #ident<#lt> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn new(#arg) -> Self {
|
pub unsafe fn new(#arg) -> Self {
|
||||||
|
@ -133,8 +159,23 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
|
||||||
priority
|
priority
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn priority(&self) -> &rtic::export::Priority {
|
||||||
|
self.priority
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Used by the lock-all API
|
||||||
|
impl #ident_mut {
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn new() -> Self {
|
||||||
|
#ident_mut {
|
||||||
|
#(#values_mut,)*
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
(item, constructor)
|
(item, implementations)
|
||||||
}
|
}
|
||||||
|
|
|
@ -202,6 +202,19 @@ pub fn shared_resources_ident(ctxt: Context, app: &App) -> Ident {
|
||||||
mark_internal_name(&s)
|
mark_internal_name(&s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generates a pre-reexport identifier for the "shared resources" struct
|
||||||
|
pub fn shared_resources_ident_mut(ctxt: Context, app: &App) -> Ident {
|
||||||
|
let mut s = match ctxt {
|
||||||
|
Context::Init => app.init.name.to_string(),
|
||||||
|
Context::Idle => app.idle.as_ref().unwrap().name.to_string(),
|
||||||
|
Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
s.push_str("Shared");
|
||||||
|
|
||||||
|
mark_internal_name(&s)
|
||||||
|
}
|
||||||
|
|
||||||
/// Generates a pre-reexport identifier for the "local resources" struct
|
/// Generates a pre-reexport identifier for the "local resources" struct
|
||||||
pub fn local_resources_ident(ctxt: Context, app: &App) -> Ident {
|
pub fn local_resources_ident(ctxt: Context, app: &App) -> Ident {
|
||||||
let mut s = match ctxt {
|
let mut s = match ctxt {
|
||||||
|
|
Loading…
Reference in a new issue