diff options
| author | Oleksandr Babak <alexanderbabak@proton.me> | 2025-01-27 11:00:10 +0100 |
|---|---|---|
| committer | Henrik Tjäder <henrik@tjaders.com> | 2025-06-15 11:02:15 +0000 |
| commit | d28b114c0b3eff133db69768f725cf5f1744fb2e (patch) | |
| tree | 2ea30b4d5e694ea84d5ce0fb9a3d3899425b5963 /rtic-macros/src/codegen/module.rs | |
| parent | a3f9239fba2e99a9389980a0736547ff65ae4bc7 (diff) | |
feat(rtic-macros): expose task waker
Diffstat (limited to 'rtic-macros/src/codegen/module.rs')
| -rw-r--r-- | rtic-macros/src/codegen/module.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/rtic-macros/src/codegen/module.rs b/rtic-macros/src/codegen/module.rs index a8700c5..c10c123 100644 --- a/rtic-macros/src/codegen/module.rs +++ b/rtic-macros/src/codegen/module.rs @@ -158,6 +158,7 @@ pub fn codegen(ctxt: Context, app: &App, analysis: &Analysis) -> TokenStream2 { }; let internal_spawn_ident = util::internal_task_ident(name, "spawn"); + let internal_waker_ident = util::internal_task_ident(name, "waker"); let from_ptr_n_args = util::from_ptr_n_args_ident(spawnee.inputs.len()); let (input_args, input_tupled, input_untupled, input_ty) = util::regroup_inputs(&spawnee.inputs); @@ -184,11 +185,36 @@ pub fn codegen(ctxt: Context, app: &App, analysis: &Analysis) -> TokenStream2 { } )); + // Waker + items.push(quote!( + #(#cfgs)* + /// Gives waker to the task + #[allow(non_snake_case)] + #[doc(hidden)] + pub fn #internal_waker_ident() -> ::core::task::Waker { + // SAFETY: If `try_allocate` succeeds one must call `spawn`, which we do. + unsafe { + let exec = rtic::export::executor::AsyncTaskExecutor::#from_ptr_n_args(#name, &#exec_name); + exec.waker(|| { + let exec = rtic::export::executor::AsyncTaskExecutor::#from_ptr_n_args(#name, &#exec_name); + exec.set_pending(); + #pend_interrupt + }) + } + } + )); + module_items.push(quote!( #(#cfgs)* #[doc(inline)] pub use super::#internal_spawn_ident as spawn; )); + + module_items.push(quote!( + #(#cfgs)* + #[doc(inline)] + pub use super::#internal_waker_ident as waker; + )); } if items.is_empty() { |
