⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

Thread

Struct Thread 

Source
pub struct Thread {
Show 20 fields pub tid: ThreadId, pub process: ProcessId, pub name: String, pub state: AtomicU32, pub context: Mutex<ArchThreadContext>, pub user_stack: Stack, pub kernel_stack: Stack, pub tls: Mutex<ThreadLocalStorage>, pub cpu_affinity: AtomicUsize, pub current_cpu: AtomicU32, pub time_slice: AtomicU32, pub cpu_time: AtomicU64, pub wake_time: AtomicU64, pub exit_code: AtomicU32, pub priority: u8, pub fpu_used: AtomicU32, pub task_ptr: Mutex<TaskPtr>, pub clear_tid: AtomicUsize, pub detached: AtomicBool, pub fs: Arc<ThreadFs>,
}
Expand description

Thread control block

Fields§

§tid: ThreadId

Thread ID

§process: ProcessId

Parent process ID

§name: String

Thread name

§state: AtomicU32

Thread state

§context: Mutex<ArchThreadContext>

CPU context (registers, etc.)

§user_stack: Stack

User stack

§kernel_stack: Stack

Kernel stack

§tls: Mutex<ThreadLocalStorage>

Thread-local storage

§cpu_affinity: AtomicUsize

CPU affinity mask

§current_cpu: AtomicU32

Current CPU (if running)

§time_slice: AtomicU32

Time slice remaining

§cpu_time: AtomicU64

Total CPU time used (microseconds)

§wake_time: AtomicU64

Wake up time (for sleeping threads)

§exit_code: AtomicU32

Exit code

§priority: u8

Thread priority (inherited from process)

§fpu_used: AtomicU32

Floating point state saved flag

§task_ptr: Mutex<TaskPtr>

Scheduler task pointer (if scheduled)

§clear_tid: AtomicUsize

clear_tid pointer for CLONE_CHILD_CLEARTID

§detached: AtomicBool

Detached flag (pthread_detach)

§fs: Arc<ThreadFs>

Filesystem view (cwd, umask)

Implementations§

Source§

impl Thread

Source

pub fn new( tid: ThreadId, process: ProcessId, name: String, entry_point: usize, user_stack_base: usize, user_stack_size: usize, kernel_stack_base: usize, kernel_stack_size: usize, fs: Arc<ThreadFs>, ) -> Self

Create a new thread

Source

pub fn get_state(&self) -> ThreadState

Get thread state

Source

pub fn set_state(&self, state: ThreadState)

Set thread state

Source

pub fn is_runnable(&self) -> bool

Check if thread is runnable

Source

pub fn set_affinity(&self, mask: usize)

Set CPU affinity

Source

pub fn get_affinity(&self) -> usize

Get CPU affinity

Source

pub fn can_run_on_cpu(&self, cpu: u8) -> bool

Check if thread can run on CPU

Source

pub fn mark_fpu_used(&self)

Mark thread as using FPU

Source

pub fn uses_fpu(&self) -> bool

Check if thread uses FPU

Source

pub fn sleep_until(&self, wake_time: u64)

Sleep thread until specified time

Source

pub fn check_wake(&self, current_time: u64) -> bool

Wake up thread if it’s time

Source

pub fn add_cpu_time(&self, microseconds: u64)

Update CPU time

Source

pub fn set_task_ptr(&self, task: Option<NonNull<Task>>)

Set scheduler task pointer

Source

pub fn get_task_ptr(&self) -> Option<NonNull<Task>>

Get scheduler task pointer

Source

pub fn sync_state_with_scheduler(&self, new_state: ThreadState)

Synchronize state with scheduler task

Source

pub fn set_ready(&self)

Mark thread as ready to run

Source

pub fn set_blocked(&self, reason: Option<u64>)

Mark thread as blocked

Source

pub fn set_running(&self, cpu: u8)

Mark thread as running on CPU

Source

pub fn set_exited(&self, exit_code: i32)

Mark thread as exited

Source

pub fn get_cpu_time(&self) -> u64

Get total CPU time

Source

pub fn set_tls_value(&self, key: u64, value: u64)

Set TLS value for this thread

Source

pub fn get_tls_value(&self, key: u64) -> Option<u64>

Get TLS value for this thread

Source

pub fn remove_tls_value(&self, key: u64) -> Option<u64>

Remove TLS value for this thread

Source

pub fn get_tls_keys(&self) -> Vec<u64>

Get all TLS keys for this thread

Source

pub fn set_entry_point(&mut self, entry: usize)

Set thread entry point

Source

pub fn reset_context(&mut self)

Reset thread context for exec

Source

pub fn fs(&self) -> Arc<ThreadFs>

Get filesystem view (cwd/umask)

Auto Trait Implementations§

§

impl !Freeze for Thread

§

impl !RefUnwindSafe for Thread

§

impl Send for Thread

§

impl Sync for Thread

§

impl Unpin for Thread

§

impl !UnwindSafe for Thread

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.