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 refcounted, 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, sync::aref::ARef};
struct State {
creator: ARef<Task>,
index: u32,
}
impl State {
fn new() -> Self {
Self {
creator: ARef::from(&**current!()),
index: 0,
}
}
}Implementations§
Source§impl Task
impl Task
Sourcepub fn current_raw() -> *mut task_struct
pub fn current_raw() -> *mut task_struct
Returns a raw pointer to the current task.
It is up to the user to use the pointer correctly.
Sourcepub unsafe fn current() -> impl Deref<Target = CurrentTask>
pub unsafe fn current() -> impl Deref<Target = CurrentTask>
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 is only used to access a CurrentTask
within the task context that was active when this function was called. For more details,
see the invariants section for CurrentTask.
Sourcepub fn signal_pending(&self) -> bool
pub fn signal_pending(&self) -> bool
Determines whether the given task has pending signals.
Sourcepub fn get_pid_ns(&self) -> Option<ARef<PidNamespace>>
pub fn get_pid_ns(&self) -> Option<ARef<PidNamespace>>
Returns task’s pid namespace with elevated reference count
Sourcepub fn tgid_nr_ns(&self, pidns: Option<&PidNamespace>) -> Pid
pub fn tgid_nr_ns(&self, pidns: Option<&PidNamespace>) -> Pid
Returns the given task’s pid in the provided pid namespace.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Task
impl !RefUnwindSafe for Task
impl !Unpin for Task
impl !UnsafeUnpin for Task
impl UnwindSafe for Task
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> PinInit<T> for T
impl<T> PinInit<T> for T
Source§unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
slot. Read more