mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-18 05:45:19 +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_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 from_ptr_n_args = util::from_ptr_n_args_ident(spawnee.inputs.len());
|
||||||
let (input_args, input_tupled, input_untupled, input_ty) =
|
let (input_args, input_tupled, input_untupled, input_ty) =
|
||||||
util::regroup_inputs(&spawnee.inputs);
|
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!(
|
module_items.push(quote!(
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use super::#internal_spawn_ident as spawn;
|
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() {
|
if items.is_empty() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue