diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-03-20 15:12:31 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-03-20 15:12:31 +0000 |
| commit | 6eb539a6a12a2c48dab694725db775f03058bf0b (patch) | |
| tree | 1cc56c8f9eaf9544649ba15fec7670fada99060c /embassy-executor-macros | |
| parent | 7c2aae88da81f4ea34a4228173f474f2c05a2f28 (diff) | |
| parent | ea89b0c4a0d752c67976aebf2ee264ddc8f77218 (diff) | |
Merge pull request #2574 from GrantM11235/atpit
Use ATPIT for task macro
Diffstat (limited to 'embassy-executor-macros')
| -rw-r--r-- | embassy-executor-macros/src/macros/task.rs | 17 |
1 files changed, 14 insertions, 3 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"))] |
