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: ThreadIdThread ID
process: ProcessIdParent process ID
name: StringThread name
state: AtomicU32Thread state
context: Mutex<ArchThreadContext>CPU context (registers, etc.)
user_stack: StackUser stack
kernel_stack: StackKernel stack
tls: Mutex<ThreadLocalStorage>Thread-local storage
cpu_affinity: AtomicUsizeCPU affinity mask
current_cpu: AtomicU32Current CPU (if running)
time_slice: AtomicU32Time slice remaining
cpu_time: AtomicU64Total CPU time used (microseconds)
wake_time: AtomicU64Wake up time (for sleeping threads)
exit_code: AtomicU32Exit code
priority: u8Thread priority (inherited from process)
fpu_used: AtomicU32Floating point state saved flag
task_ptr: Mutex<TaskPtr>Scheduler task pointer (if scheduled)
clear_tid: AtomicUsizeclear_tid pointer for CLONE_CHILD_CLEARTID
detached: AtomicBoolDetached flag (pthread_detach)
fs: Arc<ThreadFs>Filesystem view (cwd, umask)
Implementations§
Source§impl Thread
impl Thread
Sourcepub 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
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
Sourcepub fn get_state(&self) -> ThreadState
pub fn get_state(&self) -> ThreadState
Get thread state
Sourcepub fn set_state(&self, state: ThreadState)
pub fn set_state(&self, state: ThreadState)
Set thread state
Sourcepub fn is_runnable(&self) -> bool
pub fn is_runnable(&self) -> bool
Check if thread is runnable
Sourcepub fn set_affinity(&self, mask: usize)
pub fn set_affinity(&self, mask: usize)
Set CPU affinity
Sourcepub fn get_affinity(&self) -> usize
pub fn get_affinity(&self) -> usize
Get CPU affinity
Sourcepub fn can_run_on_cpu(&self, cpu: u8) -> bool
pub fn can_run_on_cpu(&self, cpu: u8) -> bool
Check if thread can run on CPU
Sourcepub fn mark_fpu_used(&self)
pub fn mark_fpu_used(&self)
Mark thread as using FPU
Sourcepub fn sleep_until(&self, wake_time: u64)
pub fn sleep_until(&self, wake_time: u64)
Sleep thread until specified time
Sourcepub fn check_wake(&self, current_time: u64) -> bool
pub fn check_wake(&self, current_time: u64) -> bool
Wake up thread if it’s time
Sourcepub fn add_cpu_time(&self, microseconds: u64)
pub fn add_cpu_time(&self, microseconds: u64)
Update CPU time
Sourcepub fn set_task_ptr(&self, task: Option<NonNull<Task>>)
pub fn set_task_ptr(&self, task: Option<NonNull<Task>>)
Set scheduler task pointer
Sourcepub fn get_task_ptr(&self) -> Option<NonNull<Task>>
pub fn get_task_ptr(&self) -> Option<NonNull<Task>>
Get scheduler task pointer
Sourcepub fn sync_state_with_scheduler(&self, new_state: ThreadState)
pub fn sync_state_with_scheduler(&self, new_state: ThreadState)
Synchronize state with scheduler task
Sourcepub fn set_blocked(&self, reason: Option<u64>)
pub fn set_blocked(&self, reason: Option<u64>)
Mark thread as blocked
Sourcepub fn set_running(&self, cpu: u8)
pub fn set_running(&self, cpu: u8)
Mark thread as running on CPU
Sourcepub fn set_exited(&self, exit_code: i32)
pub fn set_exited(&self, exit_code: i32)
Mark thread as exited
Sourcepub fn get_cpu_time(&self) -> u64
pub fn get_cpu_time(&self) -> u64
Get total CPU time
Sourcepub fn set_tls_value(&self, key: u64, value: u64)
pub fn set_tls_value(&self, key: u64, value: u64)
Set TLS value for this thread
Sourcepub fn get_tls_value(&self, key: u64) -> Option<u64>
pub fn get_tls_value(&self, key: u64) -> Option<u64>
Get TLS value for this thread
Sourcepub fn remove_tls_value(&self, key: u64) -> Option<u64>
pub fn remove_tls_value(&self, key: u64) -> Option<u64>
Remove TLS value for this thread
Sourcepub fn get_tls_keys(&self) -> Vec<u64>
pub fn get_tls_keys(&self) -> Vec<u64>
Get all TLS keys for this thread
Sourcepub fn set_entry_point(&mut self, entry: usize)
pub fn set_entry_point(&mut self, entry: usize)
Set thread entry point
Sourcepub fn reset_context(&mut self)
pub fn reset_context(&mut self)
Reset thread context for exec