diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-04-27 03:23:54 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-04-27 04:56:41 +0200 |
| commit | 293f54d13406850d24d1226eb77989f4fa8db9f4 (patch) | |
| tree | c8831ae9d2d046549b3d64294408920b9b8a5597 /embassy-macros | |
| parent | df814f9bbd5cc03f4d60eb8cb19374d23f0a84a0 (diff) | |
executor: add raw::TaskPool.
This simplifies the macro code a bit.
Diffstat (limited to 'embassy-macros')
| -rw-r--r-- | embassy-macros/src/macros/task.rs | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/embassy-macros/src/macros/task.rs b/embassy-macros/src/macros/task.rs index 396ce18f2..c450982c9 100644 --- a/embassy-macros/src/macros/task.rs +++ b/embassy-macros/src/macros/task.rs | |||
| @@ -76,14 +76,11 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke | |||
| 76 | #visibility fn #task_ident(#fargs) -> #embassy_path::executor::SpawnToken<impl ::core::future::Future + 'static> { | 76 | #visibility fn #task_ident(#fargs) -> #embassy_path::executor::SpawnToken<impl ::core::future::Future + 'static> { |
| 77 | use ::core::future::Future; | 77 | use ::core::future::Future; |
| 78 | use #embassy_path::executor::SpawnToken; | 78 | use #embassy_path::executor::SpawnToken; |
| 79 | use #embassy_path::executor::raw::TaskStorage; | 79 | use #embassy_path::executor::raw::TaskPool; |
| 80 | 80 | ||
| 81 | type Fut = impl Future + 'static; | 81 | type Fut = impl Future + 'static; |
| 82 | 82 | ||
| 83 | #[allow(clippy::declare_interior_mutable_const)] | 83 | static POOL: TaskPool<Fut, #pool_size> = TaskPool::new(); |
| 84 | const NEW_TS: TaskStorage<Fut> = TaskStorage::new(); | ||
| 85 | |||
| 86 | static POOL: [TaskStorage<Fut>; #pool_size] = [NEW_TS; #pool_size]; | ||
| 87 | 84 | ||
| 88 | // Opaque type laundering, to obscure its origin! | 85 | // Opaque type laundering, to obscure its origin! |
| 89 | // Workaround for "opaque type's hidden type cannot be another opaque type from the same scope" | 86 | // Workaround for "opaque type's hidden type cannot be another opaque type from the same scope" |
| @@ -92,7 +89,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke | |||
| 92 | token | 89 | token |
| 93 | } | 90 | } |
| 94 | 91 | ||
| 95 | launder_tait(unsafe { TaskStorage::spawn_pool(&POOL, move || #task_inner_ident(#(#arg_names,)*)) }) | 92 | launder_tait(POOL.spawn(move || #task_inner_ident(#(#arg_names,)*))) |
| 96 | } | 93 | } |
| 97 | }; | 94 | }; |
| 98 | 95 | ||
