Kernel

Struct Kernel 

Source
pub struct Kernel<A: Arch, S: Scheduler> { /* private fields */ }
Expand description

Main kernel handle that manages the threading system.

This struct coordinates all threading operations and provides a safe interface to the underlying scheduler and architecture abstractions.

§Type Parameters

  • A - Architecture implementation
  • S - Scheduler implementation

Implementations§

Source§

impl<A: Arch, S: Scheduler> Kernel<A, S>

Source

pub fn new(scheduler: S) -> Self

Create a new kernel instance.

§Arguments
  • scheduler - Scheduler implementation to use
§Returns

A new kernel instance ready for initialization.

Source

pub fn init(&self) -> Result<(), ()>

Initialize the kernel.

This must be called before any threading operations can be performed. It sets up architecture-specific features and prepares the scheduler.

§Returns

Ok(()) if initialization succeeds, Err(()) if already initialized.

Source

pub fn is_initialized(&self) -> bool

Check if the kernel has been initialized.

Source

pub fn next_thread_id(&self) -> ThreadId

Generate a new unique thread ID.

Thread IDs are never reused and are guaranteed to be unique for the lifetime of the kernel instance.

Source

pub fn scheduler(&self) -> &S

Get a reference to the scheduler.

Source

pub fn spawn<F>( &self, entry_point: F, priority: u8, ) -> Result<JoinHandle, SpawnError>
where F: FnOnce() + Send + 'static,

Spawn a new thread.

§Arguments
  • entry_point - Function to run in the new thread
  • priority - Thread priority (0-255, higher = more important)
§Returns

JoinHandle for the newly created thread, or an error if creation fails.

Source

pub fn yield_now(&self)

Yield the current thread, allowing other threads to run.

Source

pub unsafe fn handle_timer_interrupt(&self)

Handle a timer interrupt for preemptive scheduling.

This should be called from the architecture-specific timer interrupt handler.

§Safety

Must be called from an interrupt context.

Source

pub fn thread_stats(&self) -> (usize, usize, usize)

Get current thread statistics.

Trait Implementations§

Source§

impl<A: Arch, S: Scheduler> Send for Kernel<A, S>

Source§

impl<A: Arch, S: Scheduler> Sync for Kernel<A, S>

Auto Trait Implementations§

§

impl<A, S> !Freeze for Kernel<A, S>

§

impl<A, S> !RefUnwindSafe for Kernel<A, S>

§

impl<A, S> Unpin for Kernel<A, S>
where S: Unpin, A: Unpin,

§

impl<A, S> !UnwindSafe for Kernel<A, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.