diff --git a/src/runtime2/scheduler.rs b/src/runtime2/scheduler.rs index 9286998dd0f41e3ff8e36d78657323061b4a1bd4..cdc329f9892abb8c3a290a7528604c5773899328 100644 --- a/src/runtime2/scheduler.rs +++ b/src/runtime2/scheduler.rs @@ -13,14 +13,22 @@ pub(crate) struct Scheduler { pub(crate) struct SchedulerCtx<'a> { pub runtime: &'a RuntimeInner, + pub id: u32, + pub comp: u32, } impl<'a> SchedulerCtx<'a> { - pub fn new(runtime: &'a RuntimeInner) -> Self { + pub fn new(runtime: &'a RuntimeInner, id: u32) -> Self { return Self { runtime, + id, + comp: 0, } } + + pub(crate) fn log(&self, text: &str) { + println!("[s:{:02}, c:{:03}] {}", self.id, self.comp, text); + } } impl Scheduler { @@ -31,7 +39,7 @@ impl Scheduler { } pub fn run(&mut self) { - let mut scheduler_ctx = SchedulerCtx::new(&*self.runtime); + let mut scheduler_ctx = SchedulerCtx::new(&*self.runtime, self.scheduler_id); 'run_loop: loop { // Wait until we have something to do (or need to quit) @@ -42,11 +50,15 @@ impl Scheduler { let comp_key = comp_key.unwrap(); let component = self.runtime.get_component(comp_key); + scheduler_ctx.comp = comp_key.0; // Run the component until it no longer indicates that it needs to // be re-executed immediately. let mut new_scheduling = CompScheduling::Immediate; while let CompScheduling::Immediate = new_scheduling { + while let Some(message) = component.inbox.pop() { + component.code.handle_message(&mut scheduler_ctx, &mut component.ctx, message); + } new_scheduling = component.code.run(&mut scheduler_ctx, &mut component.ctx).expect("TODO: Handle error"); }