libnx  v4.7.0
Data Structures | Functions
thread.h File Reference

Multi-threading support. More...

#include "../types.h"
#include "../arm/thread_context.h"
#include "wait.h"

Go to the source code of this file.

Data Structures

struct  Thread
 Thread information structure. More...
 

Functions

static Waiter waiterForThread (Thread *t)
 Creates a Waiter for a Thread.
 
Result threadCreate (Thread *t, ThreadFunc entry, void *arg, void *stack_mem, size_t stack_sz, int prio, int cpuid)
 Creates a thread. More...
 
Result threadStart (Thread *t)
 Starts the execution of a thread. More...
 
void threadExit (void)
 Exits the current thread immediately.
 
Result threadWaitForExit (Thread *t)
 Waits for a thread to finish executing. More...
 
Result threadClose (Thread *t)
 Frees up resources associated with a thread. More...
 
Result threadPause (Thread *t)
 Pauses the execution of a thread. More...
 
Result threadResume (Thread *t)
 Resumes the execution of a thread, after having been paused. More...
 
Result threadDumpContext (ThreadContext *ctx, Thread *t)
 Dumps the registers of a thread paused by threadPause (register groups: all). More...
 
ThreadthreadGetSelf (void)
 Gets a pointer to the current thread structure. More...
 
Handle threadGetCurHandle (void)
 Gets the raw handle to the current thread. More...
 
s32 threadTlsAlloc (void(*destructor)(void *))
 Allocates a TLS slot. More...
 
void * threadTlsGet (s32 slot_id)
 Retrieves the value stored in a TLS slot. More...
 
void threadTlsSet (s32 slot_id, void *value)
 Stores the specified value into a TLS slot. More...
 
void threadTlsFree (s32 slot_id)
 Frees a TLS slot. More...
 

Detailed Description

Multi-threading support.

Author
plutoo

Function Documentation

◆ threadClose()

Result threadClose ( Thread t)

Frees up resources associated with a thread.

Parameters
tThread information structure.
Returns
Result code.

◆ threadCreate()

Result threadCreate ( Thread t,
ThreadFunc  entry,
void *  arg,
void *  stack_mem,
size_t  stack_sz,
int  prio,
int  cpuid 
)

Creates a thread.

Parameters
tThread information structure which will be filled in.
entryEntrypoint of the thread.
argArgument to pass to the entrypoint.
stack_memMemory to use as backing for stack/tls/reent. Must be page-aligned. NULL argument means to allocate new memory.
stack_szIf stack_mem is NULL, size to use for stack. If stack_mem is non-NULL, size to use for stack + reent + tls (must be page-aligned).
prioThread priority (0x00~0x3F); 0x2C is the usual priority of the main thread, 0x3B is a special priority on cores 0..2 that enables preemptive multithreading (0x3F on core 3).
cpuidID of the core on which to create the thread (0~3); or -2 to use the default core for the current process.
Returns
Result code.

◆ threadDumpContext()

Result threadDumpContext ( ThreadContext ctx,
Thread t 
)

Dumps the registers of a thread paused by threadPause (register groups: all).

Parameters
[out]ctxOutput thread context (register dump).
tThread information structure.
Returns
Result code.
Warning
Official kernel will not dump x0..x18 if the thread is currently executing a system call, and prior to 6.0.0 doesn't dump TPIDR_EL0.

◆ threadGetCurHandle()

Handle threadGetCurHandle ( void  )

Gets the raw handle to the current thread.

Returns
The current thread's handle.

◆ threadGetSelf()

Thread* threadGetSelf ( void  )

Gets a pointer to the current thread structure.

Returns
Thread information structure.

◆ threadPause()

Result threadPause ( Thread t)

Pauses the execution of a thread.

Parameters
tThread information structure.
Returns
Result code.

◆ threadResume()

Result threadResume ( Thread t)

Resumes the execution of a thread, after having been paused.

Parameters
tThread information structure.
Returns
Result code.

◆ threadStart()

Result threadStart ( Thread t)

Starts the execution of a thread.

Parameters
tThread information structure.
Returns
Result code.

◆ threadTlsAlloc()

s32 threadTlsAlloc ( void(*)(void *)  destructor)

Allocates a TLS slot.

Parameters
destructorFunction to run automatically when a thread exits.
Returns
TLS slot ID on success, or a negative value on failure.

◆ threadTlsFree()

void threadTlsFree ( s32  slot_id)

Frees a TLS slot.

Parameters
slot_idTLS slot ID.

◆ threadTlsGet()

void* threadTlsGet ( s32  slot_id)

Retrieves the value stored in a TLS slot.

Parameters
slot_idTLS slot ID.
Returns
Value.

◆ threadTlsSet()

void threadTlsSet ( s32  slot_id,
void *  value 
)

Stores the specified value into a TLS slot.

Parameters
slot_idTLS slot ID.
valueValue.

◆ threadWaitForExit()

Result threadWaitForExit ( Thread t)

Waits for a thread to finish executing.

Parameters
tThread information structure.
Returns
Result code.