WUT  0.1
Wii U Toolchain
Data Structures | Macros | Typedefs | Enumerations | Functions
Thread

Data Structures

struct  OSContext
 
struct  OSMutexQueue
 
struct  OSFastMutexQueue
 
struct  OSThread
 

Macros

#define OS_CONTEXT_TAG   0x4F53436F6E747874ull
 
#define OS_THREAD_TAG   0x74487244u
 

Typedefs

typedef struct OSContext OSContext
 
typedef struct OSFastMutex OSFastMutex
 
typedef struct OSFastMutexQueue OSFastMutexQueue
 
typedef struct OSMutex OSMutex
 
typedef struct OSMutexQueue OSMutexQueue
 
typedef struct OSThread OSThread
 
typedef uint8_t OSThreadState
 A value from enum OS_THREAD_STATE. More...
 
typedef uint32_t OSThreadRequest
 A value from enum OS_THREAD_REQUEST. More...
 
typedef uint8_t OSThreadAttributes
 A bitfield of enum OS_THREAD_ATTRIB. More...
 
typedef int(* OSThreadEntryPointFn) (int argc, const char **argv)
 
typedef void(* OSThreadCleanupCallbackFn) (OSThread *thread, void *stack)
 
typedef void(* OSThreadDeallocatorFn) (OSThread *thread, void *stack)
 

Enumerations

enum  OS_THREAD_STATE
 
enum  OS_THREAD_REQUEST
 
enum  OS_THREAD_ATTRIB
 

Functions

void OSCancelThread (OSThread *thread)
 
int32_t OSCheckActiveThreads ()
 
int32_t OSCheckThreadStackUsage (OSThread *thread)
 
void OSClearThreadStackUsage (OSThread *thread)
 
void OSContinueThread (OSThread *thread)
 
BOOL OSCreateThread (OSThread *thread, OSThreadEntryPointFn entry, int32_t argc, char *argv, void *stack, uint32_t stackSize, int32_t priority, OSThreadAttributes attributes)
 
void OSDetachThread (OSThread *thread)
 
void OSExitThread (int32_t result)
 
void OSGetActiveThreadLink (OSThread *thread, OSThreadLink *link)
 
OSThreadOSGetCurrentThread ()
 
OSThreadOSGetDefaultThread (uint32_t coreID)
 
uint32_t OSGetStackPointer ()
 
uint32_t OSGetThreadAffinity (OSThread *thread)
 
const char * OSGetThreadName (OSThread *thread)
 
int32_t OSGetThreadPriority (OSThread *thread)
 
uint32_t OSGetThreadSpecific (uint32_t id)
 
BOOL OSIsThreadSuspended (OSThread *thread)
 
BOOL OSIsThreadTerminated (OSThread *thread)
 
BOOL OSJoinThread (OSThread *thread, int *threadResult)
 
int32_t OSResumeThread (OSThread *thread)
 
BOOL OSRunThread (OSThread *thread, OSThreadEntryPointFn entry, int argc, const char **argv)
 
BOOL OSSetThreadAffinity (OSThread *thread, uint32_t affinity)
 
BOOL OSSetThreadCancelState (BOOL state)
 
OSThreadCleanupCallbackFn OSSetThreadCleanupCallback (OSThread *thread, OSThreadCleanupCallbackFn callback)
 
OSThreadDeallocatorFn OSSetThreadDeallocator (OSThread *thread, OSThreadDeallocatorFn deallocator)
 
void OSSetThreadName (OSThread *thread, const char *name)
 
BOOL OSSetThreadPriority (OSThread *thread, int32_t priority)
 
BOOL OSSetThreadRunQuantum (OSThread *thread, uint32_t quantum)
 
void OSSetThreadSpecific (uint32_t id, uint32_t value)
 
BOOL OSSetThreadStackUsage (OSThread *thread)
 
void OSSleepThread (OSThreadQueue *queue)
 
void OSSleepTicks (OSTime ticks)
 
uint32_t OSSuspendThread (OSThread *thread)
 
void OSTestThreadCancel ()
 
void OSWakeupThread (OSThreadQueue *queue)
 
void OSYieldThread ()
 

Detailed Description

The thread scheduler in the Wii U uses co-operative scheduling, this is different to the usual pre-emptive scheduling that most operating systems use (such as Windows, Linux, etc). In co-operative scheduling threads must voluntarily yield execution to other threads. In pre-emptive threads are switched by the operating system after an amount of time.

With the Wii U's scheduling model the thread with the highest priority which is in a non-waiting state will always be running (where 0 is the highest priority and 31 is the lowest). Execution will only switch to other threads once this thread has been forced to wait, such as when waiting to acquire a mutex, or when the thread voluntarily yields execution to other threads which have the same priority using OSYieldThread. OSYieldThread will never yield to a thread with lower priority than the current thread.

Macro Definition Documentation

#define OS_CONTEXT_TAG   0x4F53436F6E747874ull

Definition at line 95 of file thread.h.

#define OS_THREAD_TAG   0x74487244u

Definition at line 174 of file thread.h.

Typedef Documentation

typedef struct OSContext OSContext

Definition at line 30 of file thread.h.

typedef struct OSFastMutex OSFastMutex

Definition at line 31 of file thread.h.

Definition at line 32 of file thread.h.

typedef struct OSMutex OSMutex

Definition at line 33 of file thread.h.

typedef struct OSMutexQueue OSMutexQueue

Definition at line 34 of file thread.h.

typedef struct OSThread OSThread

Definition at line 35 of file thread.h.

typedef uint8_t OSThreadState

A value from enum OS_THREAD_STATE.

Definition at line 38 of file thread.h.

typedef uint32_t OSThreadRequest

A value from enum OS_THREAD_REQUEST.

Definition at line 41 of file thread.h.

typedef uint8_t OSThreadAttributes

A bitfield of enum OS_THREAD_ATTRIB.

Definition at line 44 of file thread.h.

typedef int(* OSThreadEntryPointFn) (int argc, const char **argv)

Definition at line 46 of file thread.h.

typedef void(* OSThreadCleanupCallbackFn) (OSThread *thread, void *stack)

Definition at line 47 of file thread.h.

typedef void(* OSThreadDeallocatorFn) (OSThread *thread, void *stack)

Definition at line 48 of file thread.h.

Enumeration Type Documentation

Enumerator
OS_THREAD_STATE_NONE 
OS_THREAD_STATE_READY 

Thread is ready to run.

OS_THREAD_STATE_RUNNING 

Thread is running.

OS_THREAD_STATE_WAITING 

Thread is waiting, i.e. on a mutex.

OS_THREAD_STATE_MORIBUND 

Thread is about to terminate.

Definition at line 50 of file thread.h.

Enumerator
OS_THREAD_REQUEST_NONE 
OS_THREAD_REQUEST_SUSPEND 
OS_THREAD_REQUEST_CANCEL 

Definition at line 67 of file thread.h.

Enumerator
OS_THREAD_ATTRIB_AFFINITY_CPU0 

Allow the thread to run on CPU0.

OS_THREAD_ATTRIB_AFFINITY_CPU1 

Allow the thread to run on CPU1.

OS_THREAD_ATTRIB_AFFINITY_CPU2 

Allow the thread to run on CPU2.

OS_THREAD_ATTRIB_AFFINITY_ANY 

Allow the thread to run any CPU.

OS_THREAD_ATTRIB_DETACHED 

Start the thread detached.

OS_THREAD_ATTRIB_STACK_USAGE 

Enables tracking of stack usage.

Definition at line 74 of file thread.h.

Function Documentation

void OSCancelThread ( OSThread thread)

Cancels a thread.

This sets the threads requestFlag to OS_THREAD_REQUEST_CANCEL, the thread will be terminated next time OSTestThreadCancel is called.

int32_t OSCheckActiveThreads ( )

Returns the count of active threads.

int32_t OSCheckThreadStackUsage ( OSThread thread)

Get the maximum amount of stack the thread has used.

void OSClearThreadStackUsage ( OSThread thread)

Disable tracking of thread stack usage

void OSContinueThread ( OSThread thread)

Clears a thread's suspend counter and resumes it.

BOOL OSCreateThread ( OSThread thread,
OSThreadEntryPointFn  entry,
int32_t  argc,
char *  argv,
void *  stack,
uint32_t  stackSize,
int32_t  priority,
OSThreadAttributes  attributes 
)

Create a new thread.

Parameters
threadThread to initialise.
entryThread entry point.
argcargc argument passed to entry point.
argvargv argument passed to entry point.
stackTop of stack (highest address).
stackSizeSize of stack.
priorityThread priority, 0 is highest priorty, 31 is lowest.
attributesThread attributes, see OSThreadAttributes.
void OSDetachThread ( OSThread thread)

Detach thread.

void OSExitThread ( int32_t  result)

Exit the current thread with a exit code.

This function is implicitly called when the thread entry point returns.

void OSGetActiveThreadLink ( OSThread thread,
OSThreadLink link 
)

Get the next and previous thread in the thread's active queue.

OSThread* OSGetCurrentThread ( )

Return pointer to OSThread object for the current thread.

OSThread* OSGetDefaultThread ( uint32_t  coreID)

Returns the default thread for a specific core.

Each core has 1 default thread created before the game boots. The default thread for core 1 calls the RPX entry point, the default threads for core 0 and 2 are suspended and can be used with OSRunThread.

uint32_t OSGetStackPointer ( )

Return current stack pointer, value of r1 register.

uint32_t OSGetThreadAffinity ( OSThread thread)

Get a thread's affinity.

const char* OSGetThreadName ( OSThread thread)

Get a thread's name.

int32_t OSGetThreadPriority ( OSThread thread)

Get a thread's base priority.

uint32_t OSGetThreadSpecific ( uint32_t  id)

Get a thread's specific value set by OSSetThreadSpecific.

BOOL OSIsThreadSuspended ( OSThread thread)

Returns TRUE if a thread is suspended.

BOOL OSIsThreadTerminated ( OSThread thread)

Returns TRUE if a thread is terminated.

BOOL OSJoinThread ( OSThread thread,
int *  threadResult 
)

Wait until thread is terminated.

If the target thread is detached, returns FALSE.

Parameters
threadThread to wait for
threadResultPointer to store thread exit value in.
Returns
Returns TRUE if thread has terminated, FALSE if thread is detached.
int32_t OSResumeThread ( OSThread thread)

Resumes a thread.

Decrements the thread's suspend counter, if the counter reaches 0 the thread is resumed.

Returns
Returns the previous value of the suspend counter.
BOOL OSRunThread ( OSThread thread,
OSThreadEntryPointFn  entry,
int  argc,
const char **  argv 
)

Run a function on an already created thread.

Can only be used on idle threads.

BOOL OSSetThreadAffinity ( OSThread thread,
uint32_t  affinity 
)

Set a thread's affinity.

BOOL OSSetThreadCancelState ( BOOL  state)

Set a thread's cancellation state.

If the state is TRUE then the thread can be suspended or cancelled when OSTestThreadCancel is called.

OSThreadCleanupCallbackFn OSSetThreadCleanupCallback ( OSThread thread,
OSThreadCleanupCallbackFn  callback 
)

Set the callback to be called just before a thread is terminated.

OSThreadDeallocatorFn OSSetThreadDeallocator ( OSThread thread,
OSThreadDeallocatorFn  deallocator 
)

Set the callback to be called just after a thread is terminated.

void OSSetThreadName ( OSThread thread,
const char *  name 
)

Set a thread's name.

BOOL OSSetThreadPriority ( OSThread thread,
int32_t  priority 
)

Set a thread's priority.

BOOL OSSetThreadRunQuantum ( OSThread thread,
uint32_t  quantum 
)

Set a thread's run quantum.

This is the maximum amount of time the thread can run for before being forced to yield.

void OSSetThreadSpecific ( uint32_t  id,
uint32_t  value 
)

Set a thread specific value.

Can be read with OSGetThreadSpecific.

BOOL OSSetThreadStackUsage ( OSThread thread)

Set thread stack usage tracking.

void OSSleepThread ( OSThreadQueue queue)

Sleep the current thread and add it to a thread queue.

Will sleep until the thread queue is woken with OSWakeupThread.

void OSSleepTicks ( OSTime  ticks)

Sleep the current thread for a period of time.

uint32_t OSSuspendThread ( OSThread thread)

Suspend a thread.

Increases a thread's suspend counter, if the counter is >0 then the thread is suspended.

Returns
Returns the thread's previous suspend counter value
void OSTestThreadCancel ( )

Check to see if the current thread should be cancelled or suspended.

This is implicitly called in:

  • OSLockMutex
  • OSTryLockMutex
  • OSUnlockMutex
  • OSAcquireSpinLock
  • OSTryAcquireSpinLock
  • OSTryAcquireSpinLockWithTimeout
  • OSReleaseSpinLock
  • OSCancelThread
void OSWakeupThread ( OSThreadQueue queue)

Wake up all threads in queue.

Clears the thread queue.

void OSYieldThread ( )

Yield execution to waiting threads with same priority.

This will never switch to a thread with a lower priority than the current thread.