mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-16 21:05:35 +01:00
feat(rtic-macros): expose task waker
This commit is contained in:
parent
a3f9239fba
commit
d28b114c0b
1 changed files with 26 additions and 0 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue