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: u64Implementations§
Source§impl<const N: usize> Scheduler<N>
impl<const N: usize> Scheduler<N>
const fn new() -> Self
fn land(&mut self, ctx: *mut c_void)
Sourcefn next_resched(now: u64, next: u64)
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.
Sourcepub fn enqueue(&mut self, now: u64, uid: UId) -> Result<(), Error>
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.
fn do_wakeups(&mut self, now: u64)
Sourcefn sync_to_sched(&mut self, now: u64) -> bool
fn sync_to_sched(&mut self, now: u64) -> bool
Syncs the new state after the last do_sched call to the scheduler, and returns whether we need to immediately reschedule.
fn select_next(&mut self) -> (UId, u32)
Sourcefn do_sched(&mut self, now: u64) -> Option<(*mut c_void, &mut Task)>
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.
Sourcepub fn sleep_until(&mut self, until: u64, now: u64) -> Result<(), Error>
pub fn sleep_until(&mut self, until: u64, now: u64) -> Result<(), Error>
Puts the current thread to sleep until the specified timepoint. This will trigger a reschedule.
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.
Sourcepub fn kick(&mut self, uid: UId) -> Result<(), Error>
pub fn kick(&mut self, uid: UId) -> Result<(), Error>
If the thread is currently sleeping, this will trigger a wakeup on the next reschedule. Note this does not trigger an immediate reschedule.
Returns an error if the thread does not exist, or if the thread is not currently sleeping.
Sourcepub fn dequeue(&mut self, uid: UId) -> Result<(), Error>
pub fn dequeue(&mut self, uid: UId) -> Result<(), Error>
This will just remove the thread from the scheduler, but it will not trigger a reschedule, even if the thread is currently running.
Returns an error if the thread does not exist, or if the thread is not currently enqueued in any scheduler.
pub fn create_task(&mut self, attrs: Attributes) -> Result<UId, Error>
Sourcepub fn kill_by_task(&mut self, uid: UId) -> Result<(), Error>
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.
pub fn create_thread( &mut self, task: Option<UId>, attrs: &Attributes, ) -> Result<UId, Error>
Sourcepub fn kill_by_thread(&mut self, uid: Option<UId>) -> Result<(), Error>
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.