libtransistor
A userland library for the Nintendo Switch
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Data Structures | Functions
thread.h File Reference

Threading functions. More...

#include <libtransistor/types.h>
#include <reent.h>
Include dependency graph for thread.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  trn_thread_t
 

Functions

result_t trn_thread_create (trn_thread_t *thread, void(*entry)(void *arg), void *arg, uint32_t priority, int32_t processor_id, size_t stack_size, void *stack_bottom)
 Creates a new thread. More...
 
result_t trn_thread_start (trn_thread_t *thread)
 Starts the given thread.
 
result_t trn_thread_cancel_synchronization (trn_thread_t *thread)
 Cancels synchronization on a thread. More...
 
result_t trn_thread_join (trn_thread_t *thread, int64_t timeout)
 Waits for the given thread to exit. More...
 
void trn_thread_destroy (trn_thread_t *thread)
 Destroys a thread. It is the caller's responsibility to ensure that a living thread is not destroyed.
 

Detailed Description

Threading functions.

Function Documentation

result_t trn_thread_cancel_synchronization ( trn_thread_t thread)

Cancels synchronization on a thread.

If the given thread is currently in a svcWaitSynchronization call, the svcWaitSynchronization call will return 0xec01.

Parameters
threadThread to cancel synchronization on
result_t trn_thread_create ( trn_thread_t thread,
void(*)(void *arg)  entry,
void *  arg,
uint32_t  priority,
int32_t  processor_id,
size_t  stack_size,
void *  stack_bottom 
)

Creates a new thread.

Parameters
threadStructure to initialize
entryEntry function for thread
argSecond argument to thread entry function
priorityPriority of the newly created thread. Must be between 0x00 and 0x3F. Use -1 for same as current thread.
processor_idWhich processor the newly created thread will run on. Use -2 for don't care.
stack_sizeSize of the stack.
stack_bottomBottom of a pre-allocated stack. If this is NULL, a new stack will be allocated via alloc_pages.

If stack_bottom is specified, the thread will not take ownership of the stack so as not to make any assumptions about how to free it. If it is NULL, a stack will be allocated via alloc_pages and will be owned by the thread.

result_t trn_thread_join ( trn_thread_t thread,
int64_t  timeout 
)

Waits for the given thread to exit.

Parameters
timeoutHow long to wait for the thread to exit, in nanoseconds. Use negative value for no timeout.
Returns
RESULT_OK on successful join, 0xea01 on timeout.