TimeSlice

Struct TimeSlice 

Source
pub struct TimeSlice { /* private fields */ }
Expand description

Time slice tracking for thread scheduling.

This tracks how much time a thread has used in its current time slice and determines when preemption should occur.

Implementations§

Source§

impl TimeSlice

Source

pub fn new(priority: u8) -> Self

Create a new time slice tracker.

§Arguments
  • priority - Thread priority (0-255, higher = more important)
Source

pub fn start_slice(&self, current_time: Instant)

Start a new time slice.

§Arguments
  • current_time - Current system time
Source

pub fn update_vruntime(&self, current_time: Instant) -> bool

Update virtual runtime based on actual runtime.

§Arguments
  • current_time - Current system time
§Returns

true if the time slice has expired and preemption should occur.

Source

pub fn vruntime(&self) -> u64

Get current virtual runtime.

Source

pub fn set_priority(&self, new_priority: u8)

Set priority and recalculate quantum.

§Arguments
  • new_priority - New priority level (0-255)
Source

pub fn set_custom_duration(&self, duration: Duration)

Set custom time slice duration.

§Arguments
  • duration - Custom duration for time slices
Source

pub fn priority(&self) -> u8

Get current priority.

Source

pub fn reset_vruntime(&self, new_vruntime: u64)

Reset virtual runtime (used for priority inheritance).

Source

pub fn should_preempt(&self) -> bool

Check if this time slice should be preempted.

This is a convenience method that updates virtual runtime and returns whether preemption should occur.

Auto Trait Implementations§

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.