AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
thread.h
Go to the documentation of this file.
1#ifndef _SYS_THREAD_H
2#define _SYS_THREAD_H
3
4#include <core/system.h>
5
6struct thread;
7
8#include <sys/proc.h>
9#include <sys/waitq.h>
10#include <ds/list.h>
11
12/* Threads (sys/thread.c). See docs/kernel/processes.md. */
13
14/* A thread's state. */
15typedef enum {
17 ISLEEP, /* sleeping, and a signal can end the sleep */
18 USLEEP, /* sleeping, whatever signals come */
20} state_t;
21
23struct thread {
26
29
31 struct proc *owner;
32
34 const char *name;
35 void (*kentry)(void *arg);
36 void *karg;
37
41 size_t stack_size;
42
46 struct waitq *waitq;
47
50
56
59
65
69
73
76
79#define THREAD_FILES_HELD 4
82
84 void *arch;
85
88
91 int urgent;
92
97
102};
103
104/* Making and ending threads (sleeping and waking up are in
105 * sys/waitq.h). */
106int thread_new(struct proc *proc, struct thread **rthread);
107int thread_create(struct thread *thread, uintptr_t stack, uintptr_t entry, uintptr_t uentry, uintptr_t arg, uintptr_t attr, struct thread **new_thread);
108int thread_kill(struct thread *thread);
109
110/* Lets go of the files a thread's system call holds (fs/file.c). */
112
113#endif /* ! _SYS_THREAD_H */
void thread_files_release(struct thread *thread)
Lets go of the open files a thread's system call held, when the call returns or the thread is killed.
Definition file.c:99
__SIZE_TYPE__ uintptr_t
Definition stddef.h:12
unsigned long long int uint64_t
Definition stddef.h:23
An open file (POSIX's "open file description", fs/file.c).
Definition vfs.h:157
A link in a list, inside the structure that is listed.
Definition list.h:31
One wait queue that one polling thread waits for.
Definition waitq.c:86
A process.
Definition proc.h:75
A thread.
Definition thread.h:23
sigset_t sig_oldmask
Definition thread.h:64
struct list_node run_link
it's on the ready list (sched.c) while it's ready to run, or on the wait queue it sleeps on (waitq); ...
Definition thread.h:45
int syscall_nr
the system call it's in (the last one it made), to restart it
Definition thread.h:49
uintptr_t stack_base
Definition thread.h:40
int files_held
Definition thread.h:81
struct list_node timer_link
it's on the timer's list while it waits with a deadline
Definition thread.h:75
int sig_oldmask_set
in sigsuspend() or pselect(): the signal mask they replaced, which the handler's frame keeps (sigretu...
Definition thread.h:63
state_t state
its state
Definition thread.h:28
void(*) kentry(void *arg)
Definition thread.h:35
int restarting
whether the call is a restart (a stop interrupted it, and no handler ran); restart_until is the deadl...
Definition thread.h:54
uint64_t sleep_until
when it waits with a deadline (sched_wait()): the deadline, in arch_rtime_ns() time
Definition thread.h:68
struct file * files[THREAD_FILES_HELD]
Definition thread.h:80
void * karg
Definition thread.h:36
tid_t tid
the thread's ID, in its process
Definition thread.h:25
int killed
it was killed (proc_threads_end()) while it ran on another CPU: it frees itself there,...
Definition thread.h:101
uintptr_t stack
its user stack
Definition thread.h:39
struct waitq * waitq
Definition thread.h:46
struct poll_reg * poll_regs
in select() or poll(): what it waits for (poll_register()), and where it sleeps meanwhile
Definition thread.h:95
uint64_t restart_until
Definition thread.h:55
int urgent
it runs before the others once woken, as soon as the interrupt that woke it returns (sched_thread_wak...
Definition thread.h:91
int spawned
whether it has run yet
Definition thread.h:87
const char * name
A kernel thread's (process 0's): its name, and what it runs.
Definition thread.h:34
struct waitq poll_wait
Definition thread.h:96
void * arch
the architecture's own data: its registers, its kernel stack
Definition thread.h:84
size_t stack_size
Definition thread.h:41
struct proc * owner
its process
Definition thread.h:31
uintptr_t fault_addr
the address of its last fault, the si_addr of the signal it raised
Definition thread.h:72
void * exit_value
what the thread exited with (thread_exit()), for thread_join()
Definition thread.h:58
int thread_kill(struct thread *thread)
Releases what a thread holds (its poll() registrations, its CPU state and kernel stack) and makes it ...
Definition thread.c:59
int thread_create(struct thread *thread, uintptr_t stack, uintptr_t entry, uintptr_t uentry, uintptr_t arg, uintptr_t attr, struct thread **new_thread)
Makes a new thread in the process of an existing one, for pthread_create().
Definition thread.c:86
int thread_new(struct proc *proc, struct thread **rthread)
Makes a new thread in a process.
Definition thread.c:27
state_t
Definition thread.h:15
@ RUNNABLE
Definition thread.h:16
@ ZOMBIE
Definition thread.h:19
@ USLEEP
Definition thread.h:18
@ ISLEEP
Definition thread.h:17
#define THREAD_FILES_HELD
the open files its system call holds (file_hold()), let go of when the call returns,...
Definition thread.h:79
pid_t tid_t
Definition types.h:9
unsigned long sigset_t
Definition types.h:27