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§
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§
Sourceunsafe 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,
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 globalSchedulerState- 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 fromnew_thread_state: The thread we’re moving to; must matchcurrent_threadand the container for thisThreadState
Returns:
sched_state: A guard for the globalSchedulerStateswitched:trueif a context switch happened,falseotherwise.
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.
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)
Sourcefn early_init(self)
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.
Sourcefn init(self)
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 beforeinit()scheduler::tick()must not be called by architecture code beforeinit()is invoked- Once
init()is invoked, timer interrupts may safely callscheduler::tick(). This includes interrupts that fire beforeinit()returns. At this point, only the bootstrap thread exists in the system and any context switch requests will early exit, making this safe.
fn panic() -> !
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".