aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-macros/src/macros/task.rs30
-rw-r--r--rust-toolchain.toml2
2 files changed, 23 insertions, 9 deletions
diff --git a/embassy-macros/src/macros/task.rs b/embassy-macros/src/macros/task.rs
index f0c78c596..0cf6b423b 100644
--- a/embassy-macros/src/macros/task.rs
+++ b/embassy-macros/src/macros/task.rs
@@ -61,10 +61,14 @@ pub fn run(args: syn::AttributeArgs, mut f: syn::ItemFn) -> Result<TokenStream,
61 61
62 ctxt.check()?; 62 ctxt.check()?;
63 63
64 let name = f.sig.ident.clone(); 64 let task_ident = f.sig.ident.clone();
65 let task_inner_ident = format_ident!("__{}_task", task_ident);
66 let future_ident = format_ident!("__{}_Future", task_ident);
67 let pool_ident = format_ident!("__{}_POOL", task_ident);
68 let new_ts_ident = format_ident!("__{}_NEW_TASKSTORAGE", task_ident);
65 69
66 let visibility = &f.vis; 70 let visibility = &f.vis;
67 f.sig.ident = format_ident!("task"); 71 f.sig.ident = task_inner_ident.clone();
68 let impl_ty = if args.send { 72 let impl_ty = if args.send {
69 quote!(impl ::core::future::Future + Send + 'static) 73 quote!(impl ::core::future::Future + Send + 'static)
70 } else { 74 } else {
@@ -73,16 +77,26 @@ pub fn run(args: syn::AttributeArgs, mut f: syn::ItemFn) -> Result<TokenStream,
73 77
74 let attrs = &f.attrs; 78 let attrs = &f.attrs;
75 79
80 let spawn_token = quote!(#embassy_path::executor::SpawnToken);
81 let task_storage = quote!(#embassy_path::executor::raw::TaskStorage);
82
76 let result = quote! { 83 let result = quote! {
84
85 #[allow(non_camel_case_types)]
86 type #future_ident = #impl_ty;
87
77 #(#attrs)* 88 #(#attrs)*
78 #visibility fn #name(#fargs) -> #embassy_path::executor::SpawnToken<#impl_ty> { 89 #visibility fn #task_ident(#fargs) -> #spawn_token<#future_ident> {
79 use #embassy_path::executor::raw::TaskStorage;
80 #f 90 #f
81 type F = #impl_ty; 91
92 #[allow(non_upper_case_globals)]
82 #[allow(clippy::declare_interior_mutable_const)] 93 #[allow(clippy::declare_interior_mutable_const)]
83 const NEW_TASK: TaskStorage<F> = TaskStorage::new(); 94 const #new_ts_ident: #task_storage<#future_ident> = #task_storage::new();
84 static POOL: [TaskStorage<F>; #pool_size] = [NEW_TASK; #pool_size]; 95
85 unsafe { TaskStorage::spawn_pool(&POOL, move || task(#arg_names)) } 96 #[allow(non_upper_case_globals)]
97 static #pool_ident: [#task_storage<#future_ident>; #pool_size] = [#new_ts_ident; #pool_size];
98
99 unsafe { #task_storage::spawn_pool(&#pool_ident, move || #task_inner_ident(#arg_names)) }
86 } 100 }
87 }; 101 };
88 102
diff --git a/rust-toolchain.toml b/rust-toolchain.toml
index 72a832460..e73ef7e90 100644
--- a/rust-toolchain.toml
+++ b/rust-toolchain.toml
@@ -1,6 +1,6 @@
1# Before upgrading check that everything is available on all tier1 targets here: 1# Before upgrading check that everything is available on all tier1 targets here:
2# https://rust-lang.github.io/rustup-components-history 2# https://rust-lang.github.io/rustup-components-history
3[toolchain] 3[toolchain]
4channel = "nightly-2022-03-10" 4channel = "nightly-2022-04-24"
5components = [ "rust-src", "rustfmt" ] 5components = [ "rust-src", "rustfmt" ]
6targets = [ "thumbv7em-none-eabi", "thumbv7m-none-eabi", "thumbv6m-none-eabi", "thumbv7em-none-eabihf", "thumbv8m.main-none-eabihf", "wasm32-unknown-unknown" ] 6targets = [ "thumbv7em-none-eabi", "thumbv7m-none-eabi", "thumbv6m-none-eabi", "thumbv7em-none-eabihf", "thumbv8m.main-none-eabihf", "wasm32-unknown-unknown" ]