From 57abd7064dcf04029e814f3e769b0ad0b2111118 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sat, 31 Oct 2020 16:36:09 +0100 Subject: [PATCH] task codegen: use local items instead of non-locals with prefixed names. --- embassy-macros/src/lib.rs | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs index 1745311b..db4afcb9 100644 --- a/embassy-macros/src/lib.rs +++ b/embassy-macros/src/lib.rs @@ -85,29 +85,15 @@ pub fn task(args: TokenStream, item: TokenStream) -> TokenStream { let name = task_fn.sig.ident.clone(); - let type_name = format_ident!("__embassy_executor_type_{}", name); - let pool_name = format_ident!("__embassy_executor_pool_{}", name); - let task_fn_name = format_ident!("__embassy_executor_task_{}", name); - let create_fn_name = format_ident!("__embassy_executor_create_{}", name); - let visibility = &task_fn.vis; - - task_fn.sig.ident = task_fn_name.clone(); + task_fn.sig.ident = format_ident!("task"); let result = quote! { - #task_fn - #[allow(non_camel_case_types)] - type #type_name = impl ::core::future::Future + 'static; - - fn #create_fn_name(#args) -> #type_name { - #task_fn_name(#arg_names) - } - - #[allow(non_upper_case_globals)] - static #pool_name: [::embassy::executor::Task<#type_name>; #pool_size] = [::embassy::executor::Task::new(); #pool_size]; - #visibility fn #name(#args) -> ::embassy::executor::SpawnToken { - unsafe { ::embassy::executor::Task::spawn(&#pool_name, || #create_fn_name(#arg_names)) } + #task_fn + type F = impl ::core::future::Future + 'static; + static POOL: [::embassy::executor::Task; #pool_size] = [::embassy::executor::Task::new(); #pool_size]; + unsafe { ::embassy::executor::Task::spawn(&POOL, || task(#arg_names)) } } }; result.into()