Struct task::Task

pub struct Task {
    pub id: usize,
    pub name: String,
    pub mmi: Arc<Mutex<MemoryManagementInfo, DisableIrq>, Global>,
    pub is_an_idle_task: bool,
    pub app_crate: Option<Arc<AppCrateRef, Global>>,
    pub namespace: Arc<CrateNamespace, Global>,
    /* private fields */
}
Expand description

A structure that contains contextual information for a thread of execution.

Implementation note

Only fields that do not permit interior mutability can safely be exposed as public because we allow foreign crates to directly access task struct fields.

Fields§

§id: usize

The unique identifier of this Task.

§name: String

The simple name of this Task.

§mmi: Arc<Mutex<MemoryManagementInfo, DisableIrq>, Global>

Memory management details: page tables, mappings, allocators, etc. This is shared among all other tasks in the same address space.

§is_an_idle_task: bool

Whether this Task is an idle task, the task that runs by default when no other task is running. There exists one idle task per core, so this is false for most tasks.

§app_crate: Option<Arc<AppCrateRef, Global>>

For application Tasks, this is effectively a reference to the [mod_mgmt::LoadedCrate] that contains the entry function for this Task.

§namespace: Arc<CrateNamespace, Global>

This Task is linked into and runs within the context of this [CrateNamespace].

Implementations§

§

impl Task

pub fn new( stack: Option<Stack>, states_to_inherit: InheritedStates<'_> ) -> Result<Task, &'static str>

Creates a new Task and initializes it to be non-Runnable.

Arguments
  • stack: the optional Stack for this new Task to use.
    • If None, a stack of the default size will be allocated and used.
  • inherited states: the set of states used to initialize this new Task.
    • Typically, a caller will pass in InheritedStates::FromTask with the enclosed task being a reference to the current task. In this way, the enclosed task acts as a sort of “parent” template for this new Task. Theseus doesn’t have a true parent-child relationship between tasks; the new Task merely inherits select states from it.
Usage Notes
  • This does not run the task, schedule it in, or switch to it.
  • If you want to create a new task, you should use the spawn crate instead.

pub fn set_env(&self, new_env: Arc<Mutex<Environment, Spin>, Global>)

Sets the Environment of this Task.

Locking / Deadlock

Obtains the lock on this Task’s inner state in order to mutate it.

pub fn get_env(&self) -> Arc<Mutex<Environment, Spin>, Global>

Gets a reference to this task’s Environment.

Locking / Deadlock

Obtains the lock on this Task’s inner state in order to access it.

pub fn is_running(&self) -> bool

Returns true if this Task is currently running.

pub fn running_on_cpu(&self) -> Option<CpuId>

Returns the ID of the CPU this Task is currently running on.

pub fn pinned_cpu(&self) -> Option<CpuId>

Returns the ID of the CPU this Task is pinned on, or None if it is not pinned.

pub fn runstate(&self) -> RunState

Returns the current RunState of this Task.

pub fn is_runnable(&self) -> bool

Returns whether this Task is runnable, i.e., able to be scheduled in.

For this to return true, this Task’s runstate must be Runnable and it must not be suspended.

Note

This does NOT mean that this Task is actually currently running, just that it is able to be run.

pub fn get_namespace(&self) -> &Arc<CrateNamespace, Global>

Returns the namespace that this Task is loaded/linked into and runs within.

pub fn with_kstack<R, F>(&self, func: F) -> Rwhere F: FnOnce(&Stack) -> R,

Exposes read-only access to this Task’s [Stack] by invoking the given func with a reference to its kernel stack.

Locking / Deadlock

Obtains the lock on this Task’s inner state for the duration of func in order to access its stack. The given func must not attempt to obtain that same inner lock.

pub fn inner_mut(&mut self) -> &mut TaskInner

Returns a mutable reference to this Task’s inner state.

Note about mutability

This function requires the caller to have a mutable reference to this Task in order to protect the inner state from foreign crates accessing it through a TaskRef auto-dereferencing into a Task. This is because you can only obtain a mutable reference to a Task before you enclose it in a TaskRef wrapper type.

Because this function requires a mutable reference to this Task, no locks must be obtained.

pub fn with_restart_info<R, F>(&self, func: F) -> Rwhere F: FnOnce(Option<&RestartInfo>) -> R,

Invokes func with immutable access to this Task’s RestartInfo.

Locking / Deadlock

Obtains the lock on this Task’s inner state for the duration of func in order to access its stack. The given func must not attempt to obtain that same inner lock.

pub fn has_exited(&self) -> bool

Returns true if this Task has been exited, i.e., if its RunState is either Exited or Reaped.

pub fn is_application(&self) -> bool

Returns true if this is an application Task.

This will also return true if this task was spawned by an application task, since a task inherits the “application crate” field from its “parent” that spawned it.

pub fn is_restartable(&self) -> bool

Returns true if this Task was spawned as a restartable task.

Locking / Deadlock

Obtains the lock on this Task’s inner state in order to access it.

pub fn block(&self) -> Result<RunState, RunState>

Blocks this Task by setting its runstate to RunState::Blocked.

Returns the previous runstate on success, and the current runstate on error. This will only succeed if the task is runnable or already blocked.

pub fn block_initing_task(&self) -> Result<RunState, RunState>

Blocks this Task if it is a newly-spawned task currently being initialized.

This is a special case only to be used when spawning a new task that should not be immediately scheduled in; it will fail for all other cases.

Returns the previous runstate (i.e. RunState::Initing) on success, or the current runstate on error.

pub fn unblock(&self) -> Result<RunState, RunState>

Unblocks this Task by setting its runstate to RunState::Runnable.

Returns the previous runstate on success, and the current runstate on error. Will only succed if the task is blocked or already runnable.

pub fn make_inited_task_runnable(&self) -> Result<RunState, RunState>

Makes this Task Runnable if it is a newly-spawned and fully initialized task.

This is a special case only to be used when spawning a new task that is ready to be scheduled in; it will fail for all other cases.

Returns the previous runstate (i.e. RunState::Initing) on success, and the current runstate on error.

pub fn suspend(&self)

Suspends this Task.

pub fn unsuspend(&self)

Unsuspends this Task.

pub fn is_suspended(&self) -> bool

Returns true if this Task is suspended.

Note that a task being suspended is independent from its RunState.

Trait Implementations§

§

impl Debug for Task

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Display for Task

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Drop for Task

§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

impl<'t> From<&'t Task> for InheritedStates<'t>

§

fn from(task: &'t Task) -> InheritedStates<'t>

Converts to this type from the input type.
§

impl Hash for Task

§

fn hash<H>(&self, h: &mut H)where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Task

§

impl Send for Task

§

impl Sync for Task

§

impl Unpin for Task

§

impl !UnwindSafe for Task

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> CallHasher for Twhere T: Hash + ?Sized,

§

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64where H: Hash + ?Sized, B: BuildHasher,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.