Struct kernel::task::Task

source ·
#[repr(transparent)]
pub struct Task(/* private fields */);
Expand description

Wraps the kernel’s struct task_struct.

Invariants

All instances are valid tasks created by the C portion of the kernel.

Instances of this type are always ref-counted, that is, a call to get_task_struct ensures that the allocation remains valid at least until the matching call to put_task_struct.

Examples

The following is an example of getting the PID of the current thread with zero additional cost when compared to the C version:

let pid = current!().pid();

Getting the PID of the current process, also zero additional cost:

let pid = current!().group_leader().pid();

Getting the current task and storing it in some struct. The reference count is automatically incremented when creating State and decremented when it is dropped:

use kernel::{task::Task, types::ARef};

struct State {
    creator: ARef<Task>,
    index: u32,
}

impl State {
    fn new() -> Self {
        Self {
            creator: current!().into(),
            index: 0,
        }
    }
}

Implementations§

source§

impl Task

source

pub unsafe fn current() -> impl Deref<Target = Task>

Returns a task reference for the currently executing task/thread.

The recommended way to get the current task/thread is to use the current macro because it is safe.

Safety

Callers must ensure that the returned object doesn’t outlive the current task/thread.

source

pub fn group_leader(&self) -> &Task

Returns the group leader of the given task.

source

pub fn pid(&self) -> pid_t

Returns the PID of the given task.

source

pub fn signal_pending(&self) -> bool

Determines whether the given task has pending signals.

source

pub fn wake_up(&self)

Wakes up the task.

Trait Implementations§

source§

impl AlwaysRefCounted for Task

source§

fn inc_ref(&self)

Increments the reference count on the object.
source§

unsafe fn dec_ref(obj: NonNull<Self>)

Decrements the reference count on the object. Read more
source§

impl Send for Task

source§

impl Sync for Task

Auto Trait Implementations§

§

impl !RefUnwindSafe 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
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, E> Init<T, E> for T

source§

unsafe fn __init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
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, E> PinInit<T, E> for T

source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. 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.