Skip to main content

Scheduler

Struct Scheduler 

Source
pub struct Scheduler<const N: usize> {
    threads: BitReclaimMap<UId, Thread, N>,
    tasks: BitReclaimMap<UId, Task, N>,
    rt_scheduler: Scheduler<N>,
    rr_scheduler: Scheduler<N>,
    wakeup: RbTree<WakupTree, UId>,
    current: Option<UId>,
    last_tick: u64,
}

Fields§

§threads: BitReclaimMap<UId, Thread, N>§tasks: BitReclaimMap<UId, Task, N>§rt_scheduler: Scheduler<N>§rr_scheduler: Scheduler<N>§wakeup: RbTree<WakupTree, UId>§current: Option<UId>§last_tick: u64

Implementations§

Source§

impl<const N: usize> Scheduler<N>

Source

const fn new() -> Self

Source

fn land(&mut self, ctx: *mut c_void)

Source

fn next_resched(now: u64, next: u64)

Triggers a reschedule at latest when we hit timepoint next. Note that we may reschedule earlier than next if another thread wakes up or is enqueued, but we will never reschedule later than next.

now - The current timepoint, in ticks. next - The next timepoint to reschedule at, in ticks.

Source

pub fn enqueue(&mut self, now: u64, uid: UId) -> Result<(), Error>

Enqueues a thread into the scheduler. This will trigger a reschedule.

uid - The UID of the thread to enqueue. now - The current timepoint, in ticks. This is used for RT threads to calculate their deadlines.

Returns an error if the thread does not exist.

Source

fn do_wakeups(&mut self, now: u64)

Source

fn sync_to_sched(&mut self, now: u64)

Syncs the scheduler state at the beginning of a reschedule.

Source

fn select_next(&mut self) -> (UId, u32)

Source

fn do_sched(&mut self, now: u64) -> Option<(*mut c_void, &mut Task)>

Picks the next thread to run and returns its context and task. This should only be called by sched_enter after land.

Source

pub fn sleep_until( &mut self, uid: Option<UId>, until: u64, now: u64, ) -> Result<(), Error>

Puts a thread to sleep until the specified timepoint. This will trigger a reschedule if the thread is currently running.

uid - The UID of the thread to put to sleep, or None to put the current thread to sleep. until - The timepoint to sleep until, in ticks. This is an absolute time, not a relative time. now - The current timepoint, in ticks.

Returns an error if there is no current thread, it is not enqueued, or if the specified timepoint is in the past.

Source

pub fn kick_by_uid(&mut self, uid: usize) -> Result<(), Error>

kick lookup by raw UId::as_usize(). Synthetic tid is a placeholder.

Source

pub fn current_uid(&self) -> Option<usize>

Source

pub fn kick(&mut self, uid: UId) -> Result<(), Error>

If the thread is currently sleeping, this will trigger a wakeup on the immediately following reschedule.

Returns an error if the thread does not exist, or if the thread is not currently sleeping.

Source

pub fn dequeue(&mut self, uid: UId) -> Result<(), Error>

This will make the thread not runnable, but it will not remove it from other lists. If the thread is currently running, reschedule will be triggered.

Returns an error if the thread does not exist, or if the thread is not currently enqueued in any scheduler.

Source

pub fn create_task(&mut self, attrs: Attributes) -> Result<UId, Error>

Source

pub fn kill_by_task(&mut self, uid: UId) -> Result<(), Error>

Dequeues all threads of the task and removes the task. If the current thread belongs to the task, reschedule will be triggered.

If the task does not exist, an error will be returned.

Source

pub fn create_thread( &mut self, task: Option<UId>, attrs: &Attributes, ) -> Result<UId, Error>

Source

pub fn kill_by_thread(&mut self, uid: Option<UId>) -> Result<(), Error>

Dequeues a thread and removes it from its corresponding task. If the thread is currently running, reschedule will be triggered.

uid - The UID of the thread to kill, or None to kill the current thread.

If the thread does not exist, or if uid is None and there is no current thread, an error will be returned.

Trait Implementations§

Source§

impl<const N: usize> Send for Scheduler<N>

Source§

impl<const N: usize> Sync for Scheduler<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for Scheduler<N>

§

impl<const N: usize> RefUnwindSafe for Scheduler<N>

§

impl<const N: usize> Unpin for Scheduler<N>

§

impl<const N: usize> UnsafeUnpin for Scheduler<N>

§

impl<const N: usize> UnwindSafe for Scheduler<N>

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.
§

impl<T> ThreadArgument for T
where T: Send + 'static,