From 0e1c0e45f765b209ce02f3c2b04487f8c18e0cee Mon Sep 17 00:00:00 2001 From: Berkus Decker Date: Fri, 1 Jan 2021 02:08:48 +0200 Subject: [PATCH] [wip] Wrap scheduler-related calls in struct Scheduler for now, pending actual mod scope --- nucleus/src/api.rs | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/nucleus/src/api.rs b/nucleus/src/api.rs index db9efab..7b2d416 100644 --- a/nucleus/src/api.rs +++ b/nucleus/src/api.rs @@ -86,8 +86,8 @@ fn handle_syscall(syscall: SysCall) -> Result<()> { SysCall::Yield => handle_yield(), } - schedule(); - activateThread(); + Scheduler::schedule(); + Scheduler::activate_thread(); Ok(()) } @@ -287,8 +287,8 @@ fn handle_interrupt_entry() -> Result<()> { handle_spurious_irq(); } - schedule(); - activate_thread(); + Scheduler::schedule(); + Scheduler::activate_thread(); Ok(()) } @@ -354,6 +354,41 @@ impl TCB { // c_handle_syscall called directly from SWI vector entry +struct Scheduler; + +impl Scheduler { + /* Values of 0 and ~0 encode ResumeCurrentThread and ChooseNewThread + * respectively; other values encode SwitchToThread and must be valid + * tcb pointers */ + //KernelSchedulerAction + + fn schedule() { + let action = KernelSchedulerAction; + if action == !0 { // all ones.. + if KernelCurrentThread.is_runnable() { + Scheduler::enqueue(KernelCurrentThread); + } + if KernelDomainTime == 0 { + next_domain(); + } + Scheduler::choose_thread(); + KernelSchedulerAction = 0; + } else if action != 0 { + if KernelCurrentThread.is_runnable() { + Scheduler::enqueue(KernelCurrentThread); + } + Scheduler::switch_to_thread(KernelSchedulerAction); + KernelSchedulerAction = 0; + } + } + + fn activate_thread() {} + + fn dequeue(thread: &mut TCB); + fn append(thread: &mut TCB); + fn reschedule_required(); +} + struct Nucleus {} impl API for Nucleus {