mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-18 05:45:19 +01:00
Ensure local_spawner is added as a field to Context
This commit is contained in:
parent
92137f2884
commit
e0d4627e35
1 changed files with 44 additions and 41 deletions
|
|
@ -113,6 +113,17 @@ pub fn codegen(ctxt: Context, app: &App, analysis: &Analysis) -> TokenStream2 {
|
|||
let internal_context_name = util::internal_task_ident(name, "Context");
|
||||
let exec_name = util::internal_task_ident(name, "EXEC");
|
||||
|
||||
if let Context::SoftwareTask(t) = ctxt {
|
||||
let local_spawner = util::internal_task_ident(t, "LocalSpawner");
|
||||
fields.push(quote! {
|
||||
/// Used to spawn tasks on the same executor
|
||||
///
|
||||
/// This is useful for tasks that take args which are !Send/!Sync.
|
||||
pub local_spawner: #local_spawner
|
||||
});
|
||||
values.push(quote!(local_spawner: #local_spawner { _p: core::marker::PhantomData }));
|
||||
}
|
||||
|
||||
items.push(quote!(
|
||||
#(#cfgs)*
|
||||
/// Execution context
|
||||
|
|
@ -228,14 +239,8 @@ pub fn codegen(ctxt: Context, app: &App, analysis: &Analysis) -> TokenStream2 {
|
|||
.filter(|(_, t)| t.args.priority == priority)
|
||||
.collect();
|
||||
|
||||
if !tasks_on_same_executor.is_empty() {
|
||||
|
||||
let local_spawner = util::internal_task_ident(t, "LocalSpawner");
|
||||
fields.push(quote! {
|
||||
/// Used to spawn tasks on the same executor
|
||||
///
|
||||
/// This is useful for tasks that take args which are !Send/!Sync.
|
||||
pub local_spawner: #local_spawner
|
||||
});
|
||||
let tasks = tasks_on_same_executor
|
||||
.iter()
|
||||
.map(|(ident, task)| {
|
||||
|
|
@ -262,7 +267,6 @@ pub fn codegen(ctxt: Context, app: &App, analysis: &Analysis) -> TokenStream2 {
|
|||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
values.push(quote!(local_spawner: #local_spawner { _p: core::marker::PhantomData }));
|
||||
items.push(quote! {
|
||||
struct #local_spawner {
|
||||
_p: core::marker::PhantomData<*mut ()>,
|
||||
|
|
@ -272,7 +276,6 @@ pub fn codegen(ctxt: Context, app: &App, analysis: &Analysis) -> TokenStream2 {
|
|||
#(#tasks)*
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module_items.push(quote!(
|
||||
#(#cfgs)*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue