[][src]Function sunrise_kernel::scheduler::schedule

pub fn schedule()

Performs a process switch.

Queue politics

                          checking if thread is unlocked
                          and suitable for running
  CURRENT_THREAD          ===============================>
    j--------j          j--------j j--------j j--------j
    | current|          |    X   | |        | |        |
    j--------j          j--------j j--------j j--------j    A
       | A               locked,       |                    |
       | |               skipped       |                    |
       | +-----------------------------+                    |
       +----------------------------------------------------+
  1. Tries to lock the next first process. If it fails to acquire its lock, it is ignored for now, and we move on to the next one.
  2. When a candidate is found, it is removed from the queue, and set as CURRENT_THREAD.
  3. Pushes the previous current thread at the end of the queue.
  4. Disables interrupts
  5. Performs the process switch
    • as new process * Re-enables interrupts