libnx
thread.h
Go to the documentation of this file.
1 /**
2  * @file thread.h
3  * @brief Multi-threading support
4  * @author plutoo
5  * @copyright libnx Authors
6  */
7 #pragma once
8 #include "../types.h"
9 
10 /// Thread information structure.
11 typedef struct {
12  Handle handle; ///< Thread handle.
13  void* stack_mem; ///< Pointer to stack memory.
14  void* stack_mirror; ///< Pointer to stack memory mirror.
15  size_t stack_sz; ///< Stack size.
16 } Thread;
17 
18 /**
19  * @brief Creates a thread.
20  * @param t Thread information structure which will be filled in.
21  * @param entry Entrypoint of the thread.
22  * @param arg Argument to pass to the entrypoint.
23  * @param stack_sz Stack size (rounded up to page alignment).
24  * @param prio Thread priority (0x00~0x3F); 0x2C is the usual priority of the main thread.
25  * @param cpuid ID of the core on which to create the thread (0~3); or -2 to use the default core for the current process.
26  * @return Result code.
27  */
29  Thread* t, ThreadFunc entry, void* arg, size_t stack_sz, int prio,
30  int cpuid);
31 
32 /**
33  * @brief Starts the execution of a thread.
34  * @param t Thread information structure.
35  * @return Result code.
36  */
38 
39 /**
40  * @brief Waits for a thread to finish executing.
41  * @param t Thread information structure.
42  * @return Result code.
43  */
45 
46 /**
47  * @brief Frees up resources associated with a thread.
48  * @param t Thread information structure.
49  * @return Result code.
50  */
52 
53 /**
54  * @brief Pauses the execution of a thread.
55  * @param t Thread information structure.
56  * @return Result code.
57  * @warning This is a privileged operation; in normal circumstances applications cannot use this function.
58  */
60 
61 /**
62  * @brief Resumes the execution of a thread, after having been paused.
63  * @param t Thread information structure.
64  * @return Result code.
65  * @warning This is a privileged operation; in normal circumstances applications cannot use this function.
66  */
void(* ThreadFunc)(void *)
Thread entrypoint function.
Definition: types.h:47
Handle handle
Thread handle.
Definition: thread.h:12
Result threadStart(Thread *t)
Starts the execution of a thread.
u32 Handle
Kernel object handle.
Definition: types.h:45
u32 Result
Function error code result type.
Definition: types.h:46
Result threadResume(Thread *t)
Resumes the execution of a thread, after having been paused.
size_t stack_sz
Stack size.
Definition: thread.h:15
Result threadCreate(Thread *t, ThreadFunc entry, void *arg, size_t stack_sz, int prio, int cpuid)
Creates a thread.
Result threadClose(Thread *t)
Frees up resources associated with a thread.
Result threadWaitForExit(Thread *t)
Waits for a thread to finish executing.
void * stack_mem
Pointer to stack memory.
Definition: thread.h:13
void * stack_mirror
Pointer to stack memory mirror.
Definition: thread.h:14
Result threadPause(Thread *t)
Pauses the execution of a thread.
Thread information structure.
Definition: thread.h:11