ScummVM API documentation
thread.h
1 #pragma once
2 #include <wiiu/types.h>
3 #include "time.h"
4 
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8 
9 typedef struct OSThread OSThread;
10 
11 typedef int (*OSThreadEntryPointFn)(int argc, const char **argv);
12 typedef void (*OSThreadCleanupCallbackFn)(OSThread *thread, void *stack);
13 typedef void (*OSThreadDeallocatorFn)(OSThread *thread, void *stack);
14 
15 enum OS_THREAD_STATE
16 {
17  OS_THREAD_STATE_NONE = 0,
18 
20  OS_THREAD_STATE_READY = 1 << 0,
21 
23  OS_THREAD_STATE_RUNNING = 1 << 1,
24 
26  OS_THREAD_STATE_WAITING = 1 << 2,
27 
29  OS_THREAD_STATE_MORIBUND = 1 << 3,
30 };
31 typedef uint8_t OSThreadState;
32 
33 enum OS_THREAD_REQUEST
34 {
35  OS_THREAD_REQUEST_NONE = 0,
36  OS_THREAD_REQUEST_SUSPEND = 1,
37  OS_THREAD_REQUEST_CANCEL = 2,
38 };
39 typedef uint32_t OSThreadRequest;
40 
41 enum OS_THREAD_ATTRIB
42 {
44  OS_THREAD_ATTRIB_AFFINITY_CPU0 = 1 << 0,
45 
47  OS_THREAD_ATTRIB_AFFINITY_CPU1 = 1 << 1,
48 
50  OS_THREAD_ATTRIB_AFFINITY_CPU2 = 1 << 2,
51 
53  OS_THREAD_ATTRIB_AFFINITY_ANY = ((1 << 0) | (1 << 1) | (1 << 2)),
54 
56  OS_THREAD_ATTRIB_DETACHED = 1 << 3,
57 
59  OS_THREAD_ATTRIB_STACK_USAGE = 1 << 5
60 };
61 typedef uint8_t OSThreadAttributes;
62 
63 #define OS_CONTEXT_TAG 0x4F53436F6E747874ull
64 
65 typedef struct OSContext
66 {
68  uint64_t tag;
69 
70  uint32_t gpr[32];
71  uint32_t cr;
72  uint32_t lr;
73  uint32_t ctr;
74  uint32_t xer;
75  uint32_t srr0;
76  uint32_t srr1;
77  uint32_t __unknown[0x5];
78  uint32_t fpscr;
79  double fpr[32];
80  uint16_t spinLockCount;
81  uint16_t state;
82  uint32_t gqr[8];
83  uint32_t __unknown0;
84  double psf[32];
85  uint64_t coretime[3];
86  uint64_t starttime;
87  uint32_t error;
88  uint32_t __unknown1;
89  uint32_t pmc1;
90  uint32_t pmc2;
91  uint32_t pmc3;
92  uint32_t pmc4;
93  uint32_t mmcr0;
94  uint32_t mmcr1;
95 } OSContext;
96 
97 typedef struct OSMutex OSMutex;
98 typedef struct OSFastMutex OSFastMutex;
99 
100 typedef struct OSMutexQueue
101 {
102  OSMutex *head;
103  OSMutex *tail;
104  void *parent;
105  uint32_t __unknown;
106 } OSMutexQueue;
107 
108 typedef struct OSFastMutexQueue
109 {
110  OSFastMutex *head;
111  OSFastMutex *tail;
113 
114 typedef struct
115 {
116  OSThread *prev;
117  OSThread *next;
118 } OSThreadLink;
119 
120 typedef struct
121 {
122  OSThread *head;
123  OSThread *tail;
124  void *parent;
125  uint32_t __unknown;
126 } OSThreadQueue;
127 
128 typedef struct
129 {
130  OSThread *head;
131  OSThread *tail;
133 
134 #define OS_THREAD_TAG 0x74487244u
135 #pragma pack(push, 1)
136 typedef struct __attribute__ ((aligned (8))) OSThread
137 {
138  OSContext context;
139 
141  uint32_t tag;
142 
144  OSThreadState state;
145 
147  OSThreadAttributes attr;
148 
150  uint16_t id;
151 
153  int32_t suspendCounter;
154 
156  int32_t priority;
157 
159  int32_t basePriority;
160 
162  int32_t exitValue;
163 
164  uint32_t unknown0[0x9];
165 
167  OSThreadQueue *queue;
168 
170  OSThreadLink link;
171 
173  OSThreadQueue joinQueue;
174 
176  OSMutex *mutex;
177 
179  OSMutexQueue mutexQueue;
180 
182  OSThreadLink activeLink;
183 
185  void *stackStart;
186 
188  void *stackEnd;
189 
191  OSThreadEntryPointFn entryPoint;
192 
193  uint32_t unknown1[0x77];
194 
196  uint32_t specific[0x10];
197 
198  uint32_t unknown2;
199 
201  const char *name;
202 
203  uint32_t unknown3;
204 
206  void *userStackPointer;
207 
209  OSThreadCleanupCallbackFn cleanupCallback;
210 
212  OSThreadDeallocatorFn deallocator;
213 
215  BOOL cancelState;
216 
218  OSThreadRequest requestFlag;
219 
221  int32_t needSuspend;
222 
224  int32_t suspendResult;
225 
227  OSThreadQueue suspendQueue;
228 
229  uint32_t unknown4[0x2B];
230 } OSThread;
231 #pragma pack(pop)
232 
233 void
234 OSCancelThread(OSThread *thread);
235 int32_t OSCheckActiveThreads();
236 int32_t OSCheckThreadStackUsage(OSThread *thread);
237 void OSClearThreadStackUsage(OSThread *thread);
238 void OSContinueThread(OSThread *thread);
239 BOOL OSCreateThread(OSThread *thread, OSThreadEntryPointFn entry, int32_t argc, char *argv,
240  void *stack, uint32_t stackSize, int32_t priority, OSThreadAttributes attributes);
241 void OSDetachThread(OSThread *thread);
242 void OSExitThread(int32_t result);
243 void OSGetActiveThreadLink(OSThread *thread, OSThreadLink *link);
244 OSThread *OSGetCurrentThread();
245 OSThread *OSGetDefaultThread(uint32_t coreID);
246 uint32_t OSGetStackPointer();
247 uint32_t OSGetThreadAffinity(OSThread *thread);
248 const char *OSGetThreadName(OSThread *thread);
249 int32_t OSGetThreadPriority(OSThread *thread);
250 uint32_t OSGetThreadSpecific(uint32_t id);
251 BOOL OSIsThreadSuspended(OSThread *thread);
252 BOOL OSIsThreadTerminated(OSThread *thread);
253 BOOL OSJoinThread(OSThread *thread, int *threadResult);
254 int32_t OSResumeThread(OSThread *thread);
255 BOOL OSRunThread(OSThread *thread, OSThreadEntryPointFn entry, int argc, const char **argv);
256 BOOL OSSetThreadAffinity(OSThread *thread, uint32_t affinity);
257 BOOL OSSetThreadCancelState(BOOL state);
258 OSThreadCleanupCallbackFn OSSetThreadCleanupCallback(OSThread *thread,
259  OSThreadCleanupCallbackFn callback);
260 OSThreadDeallocatorFn OSSetThreadDeallocator(OSThread *thread, OSThreadDeallocatorFn deallocator);
261 void OSSetThreadName(OSThread *thread, const char *name);
262 BOOL OSSetThreadPriority(OSThread *thread, int32_t priority);
263 BOOL OSSetThreadRunQuantum(OSThread *thread, uint32_t quantum);
264 void OSSetThreadSpecific(uint32_t id, uint32_t value);
265 BOOL OSSetThreadStackUsage(OSThread *thread);
266 void OSSleepThread(OSThreadQueue *queue);
267 void OSSleepTicks(OSTime ticks);
268 uint32_t OSSuspendThread(OSThread *thread);
269 void OSTestThreadCancel();
270 void OSWakeupThread(OSThreadQueue *queue);
271 void OSYieldThread();
272 void OSInitThreadQueue(OSThreadQueue *queue);
273 void OSInitThreadQueueEx(OSThreadQueue *queue, void *parent);
274 
275 #ifdef __cplusplus
276 }
277 #endif
Definition: thread.h:65
uint64_t tag
Definition: thread.h:68
Definition: thread.h:100
Definition: thread.h:108
Definition: thread.h:120
Definition: thread.h:128