AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
thread.h File Reference
#include <core/system.h>
#include <sys/proc.h>
#include <sys/waitq.h>
#include <ds/list.h>

Go to the source code of this file.

Data Structures

struct  thread
 A thread. More...

Macros

#define THREAD_FILES_HELD   4
 the open files its system call holds (file_hold()), let go of when the call returns, or when the thread is killed

Enumerations

enum  state_t { RUNNABLE , ISLEEP , USLEEP , ZOMBIE }

Functions

int thread_new (struct proc *proc, struct thread **rthread)
 Makes a new thread in a process.
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().
int thread_kill (struct thread *thread)
 Releases what a thread holds (its poll() registrations, its CPU state and kernel stack) and makes it a zombie.
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.

Macro Definition Documentation

◆ THREAD_FILES_HELD

#define THREAD_FILES_HELD   4

the open files its system call holds (file_hold()), let go of when the call returns, or when the thread is killed

Definition at line 79 of file thread.h.

Referenced by file_hold().

Enumeration Type Documentation

◆ state_t

enum state_t
Enumerator
RUNNABLE 
ISLEEP 
USLEEP 
ZOMBIE 

Definition at line 15 of file thread.h.

Function Documentation

◆ thread_create()

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().

The new thread is set up to start at uentry in user mode, but isn't made ready to run: the caller does that.

Parameters
threada thread of the process to add the new one to
stackthe new thread's user stack
entrywhere the new thread starts in user mode (the C library's thread start)
uentrythe function the C library's start calls
argthe argument it passes to uentry
attrnot used
new_threadif not NULL, set to the new thread
Returns
0, or a negative errno

Definition at line 86 of file thread.c.

References arch_thread_create(), kfree(), NULL, thread::owner, thread::stack, thread_create(), thread_new(), and proc::threads.

Referenced by sys_thread_create(), and thread_create().

◆ thread_files_release()

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.

Parameters
threadthe thread

Definition at line 99 of file file.c.

References file_put(), thread::files, thread::files_held, and thread_files_release().

Referenced by proc_kill(), proc_threads_end(), syscall_dispatch(), and thread_files_release().

◆ thread_kill()

int thread_kill ( struct thread * thread)

Releases what a thread holds (its poll() registrations, its CPU state and kernel stack) and makes it a zombie.

The thread's structure itself is freed by its caller, or by thread_join().

Parameters
threadthe thread, which must not be running
Returns
0, or -EINVAL if thread is NULL

Definition at line 59 of file thread.c.

References arch_thread_kill(), poll_unregister(), thread::state, thread_kill(), and ZOMBIE.

Referenced by __arch_cur_thread_kill(), proc_threads_end(), and thread_kill().

◆ thread_new()

int thread_new ( struct proc * proc,
struct thread ** ref )

Makes a new thread in a process.

The thread has an ID but no CPU state yet, and doesn't run: thread_create() and fork() set it up.

Parameters
procthe process the thread belongs to
refif not NULL, set to the new thread
Returns
0, -EINVAL if proc is NULL, or -ENOMEM if there was no memory for the thread

Definition at line 27 of file thread.c.

References kfree(), kmalloc(), M_ZERO, NULL, thread::owner, thread_new(), proc::threads, thread::tid, and proc::tid_last.

Referenced by kthread_create(), proc_new(), thread_create(), and thread_new().