Skip to main content Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. Rust
  4. pw_kernel
  5. kernel
  6. Arch

Arch

Trait Arch 

Source
pub trait Arch:
    'static
    + Copy
    + ThreadArg {
    type ThreadState: ThreadState;
    type BareSpinLock: BareSpinLock;
    type Clock: Clock;
    type AtomicBool: AtomicBool;
    type AtomicUsize: AtomicUsize;
    type SyscallArgs<'a>: SyscallArgs<'a>;
    type InterruptController: InterruptController;

    // Required methods
    unsafe fn context_switch(
        self,
        sched_state: SpinLockGuard<'_, Self, SchedulerState<Self>>,
        old_thread_state: *mut Self::ThreadState,
        new_thread_state: *mut Self::ThreadState,
    ) -> (SpinLockGuard<'_, Self, SchedulerState<Self>>, bool)
       where Self: Kernel;
    fn thread_local_state(self) -> &'static ThreadLocalState<Self>;
    fn now(self) -> Instant<Self::Clock>;

    // Provided methods
    fn get_interrupt_controller(
        self,
    ) -> &'static SpinLock<Self, Self::InterruptController>
       where Self: Kernel { ... }
    fn idle(self) { ... }
    fn early_init(self) { ... }
    fn init(self) { ... }
    fn panic() -> ! { ... }
}

Required Associated Types§

Required Methods§

Source

unsafe fn context_switch( self, sched_state: SpinLockGuard<'_, Self, SchedulerState<Self>>, old_thread_state: *mut Self::ThreadState, new_thread_state: *mut Self::ThreadState, ) -> (SpinLockGuard<'_, Self, SchedulerState<Self>>, bool)
where Self: Kernel,

Switches to a new thread.

  • sched_state: A guard for the global SchedulerState
    • This may be dropped and re-acquired across this function; the returned guard is either still held or newly re-acquired
  • old_thread_state: The thread we’re moving away from
  • new_thread_state: The thread we’re moving to; must match current_thread and the container for this ThreadState

Returns:

  • sched_state: A guard for the global SchedulerState
  • switched: true if a context switch happened, false otherwise.

If switched is false, the implementation guarantees that forward progress will be made. For example, a context switch may be deferred to an interrupt handler (like PendSV) which is pending. The caller does not need to retry or take further action to ensure the switch occurs.

Source

fn thread_local_state(self) -> &'static ThreadLocalState<Self>

Source

fn now(self) -> Instant<Self::Clock>

Provided Methods§

Source

fn get_interrupt_controller( self, ) -> &'static SpinLock<Self, Self::InterruptController>
where Self: Kernel,

Source

fn idle(self)

Source

fn early_init(self)

Early architecture initialization, called before the scheduler is bootstrapped.

This is invoked during kernel startup before any threads exist and before the scheduler is operational. Architecture code must not call scheduler::tick() or any other scheduler functions during this phase.

Use this for hardware initialization that must happen before the scheduler starts, such as setting up the interrupt controller or memory protection.

Source

fn init(self)

Architecture initialization, called after the scheduler is bootstrapped.

This is invoked after the scheduler is fully operational and threads can be scheduled. It is safe to call scheduler::tick() once init() is invoked.

Use this for initialization that depends on the scheduler being ready, such as starting timer interrupts that will drive scheduler::tick().

§Contract
  • early_init() is always called before init()
  • scheduler::tick() must not be called by architecture code before init() is invoked
  • Once init() is invoked, timer interrupts may safely call scheduler::tick(). This includes interrupts that fire before init() returns. At this point, only the bootstrap thread exists in the system and any context switch requests will early exit, making this safe.
Source

fn panic() -> !

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§