Skip to content

Commit d28b114

Browse files
DdystopiaAfoHT
authored andcommitted
feat(rtic-macros): expose task waker
1 parent a3f9239 commit d28b114

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

rtic-macros/src/codegen/module.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ pub fn codegen(ctxt: Context, app: &App, analysis: &Analysis) -> TokenStream2 {
158158
};
159159

160160
let internal_spawn_ident = util::internal_task_ident(name, "spawn");
161+
let internal_waker_ident = util::internal_task_ident(name, "waker");
161162
let from_ptr_n_args = util::from_ptr_n_args_ident(spawnee.inputs.len());
162163
let (input_args, input_tupled, input_untupled, input_ty) =
163164
util::regroup_inputs(&spawnee.inputs);
@@ -184,11 +185,36 @@ pub fn codegen(ctxt: Context, app: &App, analysis: &Analysis) -> TokenStream2 {
184185
}
185186
));
186187

188+
// Waker
189+
items.push(quote!(
190+
#(#cfgs)*
191+
/// Gives waker to the task
192+
#[allow(non_snake_case)]
193+
#[doc(hidden)]
194+
pub fn #internal_waker_ident() -> ::core::task::Waker {
195+
// SAFETY: If `try_allocate` succeeds one must call `spawn`, which we do.
196+
unsafe {
197+
let exec = rtic::export::executor::AsyncTaskExecutor::#from_ptr_n_args(#name, &#exec_name);
198+
exec.waker(|| {
199+
let exec = rtic::export::executor::AsyncTaskExecutor::#from_ptr_n_args(#name, &#exec_name);
200+
exec.set_pending();
201+
#pend_interrupt
202+
})
203+
}
204+
}
205+
));
206+
187207
module_items.push(quote!(
188208
#(#cfgs)*
189209
#[doc(inline)]
190210
pub use super::#internal_spawn_ident as spawn;
191211
));
212+
213+
module_items.push(quote!(
214+
#(#cfgs)*
215+
#[doc(inline)]
216+
pub use super::#internal_waker_ident as waker;
217+
));
192218
}
193219

194220
if items.is_empty() {

0 commit comments

Comments
 (0)