diff options
| author | Gustav Toft <[email protected]> | 2024-04-04 15:52:44 +0200 |
|---|---|---|
| committer | Gustav Toft <[email protected]> | 2024-04-04 15:52:44 +0200 |
| commit | a373633d0dbc352de1b488bf15e383f8ef1d4a8c (patch) | |
| tree | a4590f26bd3252445e2adfa6d271a6f1cf74d54b /embassy-executor-macros/src | |
| parent | 0427c442ea531673e18da304c7402927589b8d0b (diff) | |
| parent | 067e422863674762c0ee20178f3671ce16a5986c (diff) | |
Merge branch 'main' of https://github.com/GustavToft/embassy
Diffstat (limited to 'embassy-executor-macros/src')
| -rw-r--r-- | embassy-executor-macros/src/macros/task.rs | 17 | ||||
| -rw-r--r-- | embassy-executor-macros/src/util/ctxt.rs | 1 |
2 files changed, 14 insertions, 4 deletions
diff --git a/embassy-executor-macros/src/macros/task.rs b/embassy-executor-macros/src/macros/task.rs index 1efb2788b..96c6267b2 100644 --- a/embassy-executor-macros/src/macros/task.rs +++ b/embassy-executor-macros/src/macros/task.rs | |||
| @@ -93,10 +93,21 @@ pub fn run(args: &[NestedMeta], f: syn::ItemFn) -> Result<TokenStream, TokenStre | |||
| 93 | #[cfg(feature = "nightly")] | 93 | #[cfg(feature = "nightly")] |
| 94 | let mut task_outer: ItemFn = parse_quote! { | 94 | let mut task_outer: ItemFn = parse_quote! { |
| 95 | #visibility fn #task_ident(#fargs) -> ::embassy_executor::SpawnToken<impl Sized> { | 95 | #visibility fn #task_ident(#fargs) -> ::embassy_executor::SpawnToken<impl Sized> { |
| 96 | type Fut = impl ::core::future::Future + 'static; | 96 | trait _EmbassyInternalTaskTrait { |
| 97 | type Fut: ::core::future::Future + 'static; | ||
| 98 | fn construct(#fargs) -> Self::Fut; | ||
| 99 | } | ||
| 100 | |||
| 101 | impl _EmbassyInternalTaskTrait for () { | ||
| 102 | type Fut = impl core::future::Future + 'static; | ||
| 103 | fn construct(#fargs) -> Self::Fut { | ||
| 104 | #task_inner_ident(#(#full_args,)*) | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 97 | const POOL_SIZE: usize = #pool_size; | 108 | const POOL_SIZE: usize = #pool_size; |
| 98 | static POOL: ::embassy_executor::raw::TaskPool<Fut, POOL_SIZE> = ::embassy_executor::raw::TaskPool::new(); | 109 | static POOL: ::embassy_executor::raw::TaskPool<<() as _EmbassyInternalTaskTrait>::Fut, POOL_SIZE> = ::embassy_executor::raw::TaskPool::new(); |
| 99 | unsafe { POOL._spawn_async_fn(move || #task_inner_ident(#(#full_args,)*)) } | 110 | unsafe { POOL._spawn_async_fn(move || <() as _EmbassyInternalTaskTrait>::construct(#(#full_args,)*)) } |
| 100 | } | 111 | } |
| 101 | }; | 112 | }; |
| 102 | #[cfg(not(feature = "nightly"))] | 113 | #[cfg(not(feature = "nightly"))] |
diff --git a/embassy-executor-macros/src/util/ctxt.rs b/embassy-executor-macros/src/util/ctxt.rs index 74c872c3c..9c78cda01 100644 --- a/embassy-executor-macros/src/util/ctxt.rs +++ b/embassy-executor-macros/src/util/ctxt.rs | |||
| @@ -7,7 +7,6 @@ use std::thread; | |||
| 7 | 7 | ||
| 8 | use proc_macro2::TokenStream; | 8 | use proc_macro2::TokenStream; |
| 9 | use quote::{quote, ToTokens}; | 9 | use quote::{quote, ToTokens}; |
| 10 | use syn; | ||
| 11 | 10 | ||
| 12 | /// A type to collect errors together and format them. | 11 | /// A type to collect errors together and format them. |
| 13 | /// | 12 | /// |
