AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
thread.c File Reference

Threads: making one in a process, and ending one. More...

#include <core/system.h>
#include <core/arch.h>
#include <core/panic.h>
#include <sys/proc.h>
#include <sys/sched.h>
#include <sys/signal.h>
#include <ds/queue.h>

Go to the source code of this file.

Functions

int thread_new (struct proc *proc, struct thread **ref)
 Makes a new thread in a process.
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.
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().

Detailed Description

Threads: making one in a process, and ending one.

Running them is the scheduler's (sys/sched.c), sleeping and waking up the wait queues' (sys/waitq.c), and the CPU state the architecture's (arch_thread_create(), arch_thread_kill()).

Definition in file thread.c.

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