PatchworkOS
Loading...
Searching...
No Matches
thread_t Struct Reference

Thread of execution structure. More...

#include <thread.h>

Public Member Functions

 _Atomic (thread_state_t) state
 

Data Fields

list_entry_t entry
 The entry for the scheduler and wait system.
 
process_tprocess
 The parent process that the thread executes within.
 
list_entry_t processEntry
 The entry for the parent process.
 
tid_t id
 The thread id, unique within a process_t.
 
errno_t error
 
stack_pointer_t kernelStack
 The kernel stack of the thread.
 
stack_pointer_t userStack
 The user stack of the thread.
 
sched_thread_ctx_t sched
 
wait_thread_ctx_t wait
 
simd_ctx_t simd
 
note_queue_t notes
 
syscall_ctx_t syscall
 
interrupt_frame_t frame
 

Detailed Description

Thread of execution structure.

A thread_t represents an independent thread of execution within a process_t.

Thread Stacks

The position of a thread user stack is decided based on its thread id. The user stack of the thread with id 0 is located at the top of the lower half of the address space, the user stack is CONFIG_MAX_USER_STACK_PAGES pages long, and below it is the guard page. Below that is the user stack of the thread with id 1, below that is its guard page, it then continues like that for however many threads there are.

The kernel stack works the same way, but instead starts just under the kernel code and data section, at the top of the kernel stacks region and each stack is CONFIG_MAX_KERNEL_STACK_PAGES pages long.

Definition at line 54 of file thread.h.

Member Function Documentation

◆ _Atomic()

thread_t::_Atomic ( thread_state_t  )

The current state of the thread, used to prevent race conditions and make debugging easier.

Field Documentation

◆ entry

list_entry_t thread_t::entry

The entry for the scheduler and wait system.

Definition at line 56 of file thread.h.

Referenced by sched_queues_push(), thread_init(), wait_block_finalize(), wait_timer_handler(), and wait_unblock_thread().

◆ error

errno_t thread_t::error

The last error that occurred while the thread was running, specified using errno codes.

Definition at line 67 of file thread.h.

Referenced by _errno_get(), exception_handler(), panic(), and thread_init().

◆ frame

interrupt_frame_t thread_t::frame

The threads interrupt frame is used to save the values in the CPU registers such that the scheduler can continue executing the thread later on.

Definition at line 79 of file thread.h.

Referenced by init_early(), loader_process_entry(), loader_spawn(), loader_thread_create(), sched_cpu_ctx_init(), thread_get_interrupt_frame(), thread_init(), thread_load(), thread_save(), and trampoline_c_entry().

◆ id

◆ kernelStack

stack_pointer_t thread_t::kernelStack

The kernel stack of the thread.

Definition at line 68 of file thread.h.

Referenced by init_early(), loader_spawn(), panic(), sched_cpu_ctx_init(), thread_handle_page_fault(), thread_init(), and trampoline_c_entry().

◆ notes

note_queue_t thread_t::notes

◆ process

◆ processEntry

list_entry_t thread_t::processEntry

The entry for the parent process.

Definition at line 58 of file thread.h.

Referenced by thread_free(), and thread_init().

◆ sched

◆ simd

simd_ctx_t thread_t::simd

Definition at line 72 of file thread.h.

Referenced by thread_free(), thread_init(), thread_load(), and thread_save().

◆ syscall

syscall_ctx_t thread_t::syscall

Definition at line 74 of file thread.h.

Referenced by thread_init(), and thread_load().

◆ userStack

◆ wait


The documentation for this struct was generated from the following file: