mirror of
https://github.com/wiiu-env/wut.git
synced 2025-01-06 13:58:18 +01:00
More documentation.
This commit is contained in:
parent
786a36efbd
commit
33247b5034
@ -4,6 +4,8 @@
|
||||
/**
|
||||
* \defgroup coreinit_cache Cache
|
||||
* \ingroup coreinit
|
||||
*
|
||||
* Cache synchronisation functions.
|
||||
* @{
|
||||
*/
|
||||
|
||||
@ -11,34 +13,67 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Equivalent to dcbi instruction.
|
||||
*/
|
||||
void
|
||||
DCInvalidateRange(void *addr,
|
||||
uint32_t size);
|
||||
|
||||
|
||||
/**
|
||||
* Equivalent to dcbf, sync, eieio.
|
||||
*/
|
||||
void
|
||||
DCFlushRange(void *addr,
|
||||
uint32_t size);
|
||||
|
||||
|
||||
/**
|
||||
* Equivalent to dcbst, sync, eieio.
|
||||
*/
|
||||
void
|
||||
DCStoreRange(void *addr,
|
||||
uint32_t size);
|
||||
|
||||
|
||||
/**
|
||||
* Equivalent to dcbf.
|
||||
*
|
||||
* Does not perform sync, eieio like DCFlushRange.
|
||||
*/
|
||||
void
|
||||
DCFlushRangeNoSync(void *addr,
|
||||
uint32_t size);
|
||||
|
||||
|
||||
/**
|
||||
* Equivalent to dcbst.
|
||||
*
|
||||
* Does not perform sync, eieio like DCStoreRange.
|
||||
*/
|
||||
void
|
||||
DCStoreRangeNoSync(void *addr,
|
||||
uint32_t size);
|
||||
|
||||
|
||||
/**
|
||||
* Equivalent to dcbz instruction.
|
||||
*/
|
||||
void
|
||||
DCZeroRange(void *addr,
|
||||
uint32_t size);
|
||||
|
||||
|
||||
/**
|
||||
* Equivalent to dcbt instruction.
|
||||
*/
|
||||
void
|
||||
DCTouchRange(void *addr,
|
||||
uint32_t size);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -5,6 +5,10 @@
|
||||
/**
|
||||
* \defgroup coreinit_cond Condition Variable
|
||||
* \ingroup coreinit
|
||||
*
|
||||
* Standard condition variable implementation.
|
||||
*
|
||||
* Similar to <a href="http://en.cppreference.com/w/cpp/thread/condition_variable">std::condition_variable</a>.
|
||||
* @{
|
||||
*/
|
||||
|
||||
@ -35,20 +39,44 @@ CHECK_OFFSET(OSCondition, 0x04, name);
|
||||
CHECK_OFFSET(OSCondition, 0x0c, queue);
|
||||
CHECK_SIZE(OSCondition, 0x1c);
|
||||
|
||||
|
||||
/**
|
||||
* Initialise a condition variable structure.
|
||||
*/
|
||||
void
|
||||
OSInitCond(OSCondition *condition);
|
||||
|
||||
|
||||
/**
|
||||
* Initialise a condition variable structure with a name.
|
||||
*/
|
||||
void
|
||||
OSInitCondEx(OSCondition *condition,
|
||||
const char *name);
|
||||
|
||||
|
||||
/**
|
||||
* Sleep the current thread until the condition variable has been signalled.
|
||||
*
|
||||
* The mutex must be locked when entering this function.
|
||||
* Will unlock the mutex and then sleep, reacquiring the mutex when woken.
|
||||
*
|
||||
* Similar to <a href="http://en.cppreference.com/w/cpp/thread/condition_variable/wait">std::condition_variable::wait</a>.
|
||||
*/
|
||||
void
|
||||
OSWaitCond(OSCondition *condition,
|
||||
OSMutex *mutex);
|
||||
|
||||
|
||||
/**
|
||||
* Will wake up any threads waiting on the condition with OSWaitCond.
|
||||
*
|
||||
* Similar to <a href="http://en.cppreference.com/w/cpp/thread/condition_variable/notify_all">std::condition_variable::notify_all</a>.
|
||||
*/
|
||||
void
|
||||
OSSignalCond(OSCondition *condition);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -6,6 +6,10 @@
|
||||
/**
|
||||
* \defgroup coreinit_event Event Object
|
||||
* \ingroup coreinit
|
||||
*
|
||||
* Standard event object implementation. There are two supported event object modes, check OSEventMode.
|
||||
*
|
||||
* Similar to Windows <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms682655(v=vs.85).aspx">Event Objects</a>.
|
||||
* @{
|
||||
*/
|
||||
|
||||
@ -18,7 +22,10 @@ typedef uint32_t OSEventMode;
|
||||
|
||||
enum OSEventMode
|
||||
{
|
||||
//! A manual event will only reset when OSResetEvent is called.
|
||||
OS_EVENT_MODE_MANUAL = 0,
|
||||
|
||||
//! An auto event will reset everytime a thread is woken.
|
||||
OS_EVENT_MODE_AUTO = 1,
|
||||
};
|
||||
|
||||
@ -26,11 +33,21 @@ enum OSEventMode
|
||||
|
||||
struct OSEvent
|
||||
{
|
||||
//! Should always be set to the value OS_EVENT_TAG.
|
||||
uint32_t tag;
|
||||
|
||||
//! Name set by OSInitEventEx.
|
||||
const char *name;
|
||||
|
||||
UNKNOWN(4);
|
||||
|
||||
//! The current value of the event object.
|
||||
BOOL value;
|
||||
|
||||
//! The threads currently waiting on this event object with OSWaitEvent.
|
||||
OSThreadQueue queue;
|
||||
|
||||
//! The mode of the event object, set by OSInitEvent.
|
||||
OSEventMode mode;
|
||||
};
|
||||
CHECK_OFFSET(OSEvent, 0x0, tag);
|
||||
@ -42,29 +59,85 @@ CHECK_SIZE(OSEvent, 0x24);
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
/**
|
||||
* Initialise an event object with value and mode.
|
||||
*/
|
||||
void
|
||||
OSInitEvent(OSEvent *event,
|
||||
BOOL value,
|
||||
OSEventMode mode);
|
||||
|
||||
|
||||
/**
|
||||
* Initialise an event object with value, mode and name.
|
||||
*/
|
||||
void
|
||||
OSInitEventEx(OSEvent *event,
|
||||
BOOL value,
|
||||
OSEventMode mode,
|
||||
char *name);
|
||||
|
||||
|
||||
/**
|
||||
* Signals the event.
|
||||
*
|
||||
* If no threads are waiting the event value is set.
|
||||
*
|
||||
* If the event mode is OS_EVENT_MODE_MANUAL this will wake all waiting threads
|
||||
* and the event will remain set until OSResetEvent is called.
|
||||
*
|
||||
* If the event mode is OS_EVENT_MODE_AUTO this will wake only one thread
|
||||
* and the event will be reset immediately.
|
||||
*
|
||||
* Similar to <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms686211(v=vs.85).aspx">SetEvent</a>.
|
||||
*/
|
||||
void
|
||||
OSSignalEvent(OSEvent *event);
|
||||
|
||||
/**
|
||||
* Signals all threads waiting on an event.
|
||||
*
|
||||
* If no threads are waiting the event value is set.
|
||||
*
|
||||
* If the event mode is OS_EVENT_MODE_MANUAL this will wake all waiting threads
|
||||
* and the event will remain set until OSResetEvent is called.
|
||||
*
|
||||
* If the event mode is OS_EVENT_MODE_AUTO this will wake all waiting threads
|
||||
* and the event will be reset.
|
||||
*/
|
||||
void
|
||||
OSSignalEventAll(OSEvent *event);
|
||||
|
||||
|
||||
/**
|
||||
* Wait until an event is signalled.
|
||||
*
|
||||
* If the event is already set, this returns immediately.
|
||||
*
|
||||
* If the event mode is OS_EVENT_MODE_AUTO the event will be reset before
|
||||
* returning from this method.
|
||||
*
|
||||
* Similar to <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms687032(v=vs.85).aspx">WaitForSingleObject</a>.
|
||||
*/
|
||||
void
|
||||
OSWaitEvent(OSEvent *event);
|
||||
|
||||
|
||||
/**
|
||||
* Resets the event object.
|
||||
*
|
||||
* Similar to <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms685081(v=vs.85).aspx">ResetEvent</a>.
|
||||
*/
|
||||
void
|
||||
OSResetEvent(OSEvent *event);
|
||||
|
||||
|
||||
/**
|
||||
* Wait until an event is signalled or a timeout has occurred.
|
||||
*
|
||||
* Similar to <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms687032(v=vs.85).aspx">WaitForSingleObject</a>.
|
||||
*/
|
||||
BOOL
|
||||
OSWaitEventWithTimeout(OSEvent *event,
|
||||
OSTime timeout);
|
||||
|
@ -5,6 +5,9 @@
|
||||
/**
|
||||
* \defgroup coreinit_fastmutex Fast Mutex
|
||||
* \ingroup coreinit
|
||||
*
|
||||
* Similar to OSMutex but tries to acquire the mutex without using the global
|
||||
* scheduler lock, and does not test for thread cancel.
|
||||
* @{
|
||||
*/
|
||||
|
||||
@ -43,7 +46,8 @@ CHECK_OFFSET(OSFastMutex, 0x14, link);
|
||||
CHECK_SIZE(OSFastMutex, 0x2c);
|
||||
|
||||
void
|
||||
OSFastMutex_Init(OSFastMutex *mutex, const char *name);
|
||||
OSFastMutex_Init(OSFastMutex *mutex,
|
||||
const char *name);
|
||||
|
||||
void
|
||||
OSFastMutex_Lock(OSFastMutex *mutex);
|
||||
|
@ -5,6 +5,10 @@
|
||||
/**
|
||||
* \defgroup coreinit_mutex Mutex
|
||||
* \ingroup coreinit
|
||||
*
|
||||
* Standard mutex object, supports recursive locking.
|
||||
*
|
||||
* Similar to <a href="http://en.cppreference.com/w/cpp/thread/recursive_mutex">std::recursive_mutex</a>.
|
||||
* @{
|
||||
*/
|
||||
|
||||
@ -31,23 +35,24 @@ CHECK_SIZE(OSMutexLink, 0x8);
|
||||
|
||||
struct OSMutex
|
||||
{
|
||||
// OSMutex::Tag
|
||||
//! Should always be set to the value OS_MUTEX_TAG.
|
||||
uint32_t tag;
|
||||
|
||||
// Name set by OSInitMutexEx(mutex, name)
|
||||
//! Name set by OSInitMutexEx.
|
||||
const char *name;
|
||||
|
||||
UNKNOWN(4);
|
||||
|
||||
// Queue of threads waiting for this mutex to unlock
|
||||
//! Queue of threads waiting for this mutex to unlock.
|
||||
OSThreadQueue queue;
|
||||
|
||||
// Current owner of mutex
|
||||
//! Current owner of mutex.
|
||||
OSThread *owner;
|
||||
|
||||
// Current recursion lock count of mutex
|
||||
//! Current recursion lock count of mutex.
|
||||
int32_t count;
|
||||
|
||||
// Link used inside OSThread's mutex queue
|
||||
//! Link used inside OSThread's mutex queue.
|
||||
OSMutexLink link;
|
||||
};
|
||||
CHECK_OFFSET(OSMutex, 0x00, tag);
|
||||
@ -58,21 +63,68 @@ CHECK_OFFSET(OSMutex, 0x20, count);
|
||||
CHECK_OFFSET(OSMutex, 0x24, link);
|
||||
CHECK_SIZE(OSMutex, 0x2c);
|
||||
|
||||
|
||||
/**
|
||||
* Initialise a mutex structure.
|
||||
*/
|
||||
void
|
||||
OSInitMutex(OSMutex *mutex);
|
||||
|
||||
|
||||
/**
|
||||
* Initialise a mutex structure with a name.
|
||||
*/
|
||||
void
|
||||
OSInitMutexEx(OSMutex *mutex,
|
||||
const char *name);
|
||||
|
||||
|
||||
/**
|
||||
* Lock the mutex.
|
||||
*
|
||||
* If no one owns the mutex, set current thread as owner.
|
||||
*
|
||||
* If the lock is owned by the current thread, increase the recursion count.
|
||||
*
|
||||
* If the lock is owned by another thread, the current thread will sleep until
|
||||
* the owner has unlocked this mutex.
|
||||
*
|
||||
* Similar to <a href="http://en.cppreference.com/w/cpp/thread/recursive_mutex/lock">std::recursive_mutex::lock</a>.
|
||||
*/
|
||||
void
|
||||
OSLockMutex(OSMutex *mutex);
|
||||
|
||||
|
||||
/**
|
||||
* Try to lock a mutex.
|
||||
*
|
||||
* If no one owns the mutex, set current thread as owner.
|
||||
*
|
||||
* If the lock is owned by the current thread, increase the recursion count.
|
||||
*
|
||||
* If the lock is owned by another thread, do not block, return FALSE.
|
||||
*
|
||||
* \return TRUE if the mutex is locked, FALSE if the mutex is owned by another thread.
|
||||
*
|
||||
* Similar to <a href="http://en.cppreference.com/w/cpp/thread/recursive_mutex/try_lock">std::recursive_mutex::try_lock</a>.
|
||||
*/
|
||||
BOOL
|
||||
OSTryLockMutex(OSMutex *mutex);
|
||||
|
||||
|
||||
/**
|
||||
* Unlocks the mutex.
|
||||
*
|
||||
* Will decrease the recursion count, will only unlock the mutex when the
|
||||
* recursion count reaches 0.
|
||||
*
|
||||
* If any other threads are waiting to lock the mutex they will be woken.
|
||||
*
|
||||
* Similar to <a href="http://en.cppreference.com/w/cpp/thread/recursive_mutex/unlock">std::recursive_mutex::unlock</a>.
|
||||
*/
|
||||
void
|
||||
OSUnlockMutex(OSMutex *mutex);
|
||||
|
||||
BOOL
|
||||
OSTryLockMutex(OSMutex *mutex);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -5,6 +5,8 @@
|
||||
/**
|
||||
* \defgroup coreinit_semaphore Semaphore
|
||||
* \ingroup coreinit
|
||||
*
|
||||
* Similar to Windows <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms685129(v=vs.85).aspx">Semaphore Objects</a>.
|
||||
* @{
|
||||
*/
|
||||
|
||||
@ -18,10 +20,18 @@ typedef struct OSSemaphore OSSemaphore;
|
||||
|
||||
struct OSSemaphore
|
||||
{
|
||||
//! Should always be set to the value OS_SEMAPHORE_TAG.
|
||||
uint32_t tag;
|
||||
|
||||
//! Name set by OSInitMutexEx.
|
||||
const char *name;
|
||||
|
||||
UNKNOWN(4);
|
||||
|
||||
//! Current count of semaphore
|
||||
int32_t count;
|
||||
|
||||
//! Queue of threads waiting on semaphore object with OSWaitSemaphore
|
||||
OSThreadQueue queue;
|
||||
};
|
||||
CHECK_OFFSET(OSSemaphore, 0x00, tag);
|
||||
@ -30,27 +40,63 @@ CHECK_OFFSET(OSSemaphore, 0x0C, count);
|
||||
CHECK_OFFSET(OSSemaphore, 0x10, queue);
|
||||
CHECK_SIZE(OSSemaphore, 0x20);
|
||||
|
||||
|
||||
/**
|
||||
* Initialise semaphore object with count.
|
||||
*/
|
||||
void
|
||||
OSInitSemaphore(OSSemaphore *semaphore,
|
||||
int32_t count);
|
||||
|
||||
|
||||
/**
|
||||
* Initialise semaphore object with count and name.
|
||||
*/
|
||||
void
|
||||
OSInitSemaphoreEx(OSSemaphore *semaphore,
|
||||
int32_t count,
|
||||
const char *name);
|
||||
|
||||
|
||||
/**
|
||||
* Get the current semaphore count.
|
||||
*/
|
||||
int32_t
|
||||
OSGetSemaphoreCount(OSSemaphore *semaphore);
|
||||
|
||||
|
||||
/**
|
||||
* Increase the semaphore value.
|
||||
*
|
||||
* If any threads are waiting for semaphore, they are woken.
|
||||
*/
|
||||
int32_t
|
||||
OSSignalSemaphore(OSSemaphore *semaphore);
|
||||
|
||||
|
||||
/**
|
||||
* Decrease the semaphore value.
|
||||
*
|
||||
* If the value is less than or equal to zero the current thread will be put to
|
||||
* sleep until the count is above zero and it can decrement it safely.
|
||||
*/
|
||||
int32_t
|
||||
OSWaitSemaphore(OSSemaphore *semaphore);
|
||||
|
||||
|
||||
/**
|
||||
* Try to decrease the semaphore value.
|
||||
*
|
||||
* If the value is greater than zero then it will be decremented, else the function
|
||||
* will return immediately with a value <= 0 indicating a failure.
|
||||
*
|
||||
* \return Returns previous semaphore count, before the decrement in this function.
|
||||
* If the value is >0 then it means the call was succesful.
|
||||
*/
|
||||
int32_t
|
||||
OSTryWaitSemaphore(OSSemaphore *semaphore);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -6,6 +6,20 @@
|
||||
/**
|
||||
* \defgroup coreinit_thread Thread
|
||||
* \ingroup coreinit
|
||||
*
|
||||
* 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.
|
||||
* @{
|
||||
*/
|
||||
|
||||
@ -31,9 +45,17 @@ typedef void (*OSThreadDeallocatorFn)(OSThread *thread, void *stack);
|
||||
enum OSThreadState
|
||||
{
|
||||
OS_THREAD_STATE_NONE = 0,
|
||||
|
||||
//! Thread is ready to run
|
||||
OS_THREAD_STATE_READY = 1 << 0,
|
||||
|
||||
//! Thread is running
|
||||
OS_THREAD_STATE_RUNNING = 1 << 1,
|
||||
|
||||
//! Thread is waiting, i.e. on a mutex
|
||||
OS_THREAD_STATE_WAITING = 1 << 2,
|
||||
|
||||
//! Thread is about to terminate
|
||||
OS_THREAD_STATE_MORIBUND = 1 << 3,
|
||||
};
|
||||
|
||||
@ -46,18 +68,32 @@ enum OSThreadRequest
|
||||
|
||||
enum OSThreadAttributes
|
||||
{
|
||||
//! Allow the thread to run on CPU0.
|
||||
OS_THREAD_ATTRIB_AFFINITY_CPU0 = 1 << 0,
|
||||
|
||||
//! Allow the thread to run on CPU1.
|
||||
OS_THREAD_ATTRIB_AFFINITY_CPU1 = 1 << 1,
|
||||
|
||||
//! Allow the thread to run on CPU2.
|
||||
OS_THREAD_ATTRIB_AFFINITY_CPU2 = 1 << 2,
|
||||
OS_THREAD_ATTRIB_AFFINITY_ANY = 1 << 3,
|
||||
OS_THREAD_ATTRIB_DETACHED = 1 << 4
|
||||
|
||||
//! Allow the thread to run any CPU.
|
||||
OS_THREAD_ATTRIB_AFFINITY_ANY = ((1 << 0) | (1 << 1) | (1 << 2)),
|
||||
|
||||
//! Start the thread detached.
|
||||
OS_THREAD_ATTRIB_DETACHED = 1 << 3,
|
||||
|
||||
//! Enables tracking of stack usage.
|
||||
OS_THREAD_ATTRIB_STACK_USAGE = 1 << 5
|
||||
};
|
||||
|
||||
#define OS_CONTEXT_TAG 0x4F53436F6E747874ull
|
||||
|
||||
struct OSContext
|
||||
{
|
||||
//! Should always be set to the value OS_CONTEXT_TAG.
|
||||
uint64_t tag;
|
||||
|
||||
uint32_t gpr[32];
|
||||
uint32_t cr;
|
||||
uint32_t lr;
|
||||
@ -132,7 +168,6 @@ CHECK_SIZE(OSFastMutexQueue, 0x08);
|
||||
|
||||
#define OS_THREAD_TAG 0x74487244u
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct OSThread
|
||||
{
|
||||
OSContext context;
|
||||
@ -140,36 +175,85 @@ struct OSThread
|
||||
OSThreadState state;
|
||||
OSThreadAttributes attr;
|
||||
uint16_t id;
|
||||
|
||||
//! Suspend count (increased by OSSuspendThread).
|
||||
int32_t suspendCounter;
|
||||
int32_t priority; // Actual priority of thread
|
||||
int32_t basePriority; // Base priority of thread
|
||||
int32_t exitValue; // Value from OSExitThread
|
||||
|
||||
//! Actual priority of thread.
|
||||
int32_t priority;
|
||||
|
||||
//! Base priority of thread, 0 is highest priority, 31 is lowest priority.
|
||||
int32_t basePriority;
|
||||
|
||||
//! Exit value
|
||||
int32_t exitValue;
|
||||
|
||||
UNKNOWN(0x35C - 0x338);
|
||||
OSThreadQueue *queue; // Queue the thread is on
|
||||
OSThreadLink link; // Thread queue link
|
||||
OSThreadQueue joinQueue; // Queue of threads waiting to join this
|
||||
OSMutex *mutex; // Mutex we are waiting to lock
|
||||
OSMutexQueue mutexQueue; // Mutexes owned by this thread
|
||||
OSThreadLink activeLink; // Link on active thread queue
|
||||
void *stackStart; // Stack starting value (top, highest address)
|
||||
void *stackEnd; // Stack end value (bottom, lowest address)
|
||||
OSThreadEntryPointFn entryPoint; // Entry point from OSCreateThread
|
||||
|
||||
//! Queue the thread is currently waiting on
|
||||
OSThreadQueue *queue;
|
||||
|
||||
//! Link used for thread queue
|
||||
OSThreadLink link;
|
||||
|
||||
//! Queue of threads waiting to join this thread
|
||||
OSThreadQueue joinQueue;
|
||||
|
||||
//! Mutex this thread is waiting to lock
|
||||
OSMutex *mutex;
|
||||
|
||||
//! Queue of mutexes this thread owns
|
||||
OSMutexQueue mutexQueue;
|
||||
|
||||
//! Link for global active thread queue
|
||||
OSThreadLink activeLink;
|
||||
|
||||
//! Stack start (top, highest address)
|
||||
void *stackStart;
|
||||
|
||||
//! Stack end (bottom, lowest address)
|
||||
void *stackEnd;
|
||||
|
||||
//! Thread entry point
|
||||
OSThreadEntryPointFn entryPoint;
|
||||
|
||||
UNKNOWN(0x57c - 0x3a0);
|
||||
uint32_t specific[0x10]; // OSSetThreadSpecific / OSGetThreadSpecific
|
||||
|
||||
//! Thread specific values, accessed with OSSetThreadSpecific and OSGetThreadSpecific.
|
||||
uint32_t specific[0x10];
|
||||
|
||||
UNKNOWN(0x5c0 - 0x5bc);
|
||||
const char *name; // Thread name
|
||||
|
||||
//! Thread name, accessed with OSSetThreadName and OSGetThreadName.
|
||||
const char *name;
|
||||
|
||||
UNKNOWN(0x4);
|
||||
void *userStackPointer; // The stack specified in OSCreateThread
|
||||
OSThreadCleanupCallbackFn cleanupCallback; // Set with OSSetThreadCleanupCallback
|
||||
OSThreadDeallocatorFn deallocator; // Set with OSSetThreadDeallocator
|
||||
uint32_t cancelState; // Is listening to requestFlag enabled
|
||||
OSThreadRequest requestFlag; // Request flag for cancel or suspend
|
||||
int32_t needSuspend; // How many pending suspends we have
|
||||
int32_t suspendResult; // Result of suspend
|
||||
OSThreadQueue suspendQueue; // Queue of threads waiting for suspend to finish
|
||||
|
||||
//! The stack pointer passed in OSCreateThread.
|
||||
void *userStackPointer;
|
||||
|
||||
//! Called just before thread is terminated, set with OSSetThreadCleanupCallback
|
||||
OSThreadCleanupCallbackFn cleanupCallback;
|
||||
|
||||
//! Called just after a thread is terminated, set with OSSetThreadDeallocator
|
||||
OSThreadDeallocatorFn deallocator;
|
||||
|
||||
//! If TRUE then a thread can be cancelled or suspended, set with OSSetThreadCancelState
|
||||
BOOL cancelState;
|
||||
|
||||
//! Current thread request, used for cancelleing and suspending the thread.
|
||||
OSThreadRequest requestFlag;
|
||||
|
||||
//! Pending suspend request count
|
||||
int32_t needSuspend;
|
||||
|
||||
//! Result of thread suspend
|
||||
int32_t suspendResult;
|
||||
|
||||
//! Queue of threads waiting for a thread to be suspended.
|
||||
OSThreadQueue suspendQueue;
|
||||
UNKNOWN(0x69c - 0x5f4);
|
||||
};
|
||||
#pragma pack(pop)
|
||||
CHECK_OFFSET(OSThread, 0x320, tag);
|
||||
CHECK_OFFSET(OSThread, 0x324, state);
|
||||
CHECK_OFFSET(OSThread, 0x325, attr);
|
||||
@ -199,21 +283,57 @@ CHECK_OFFSET(OSThread, 0x5e0, suspendResult);
|
||||
CHECK_OFFSET(OSThread, 0x5e4, suspendQueue);
|
||||
CHECK_SIZE(OSThread, 0x69c);
|
||||
|
||||
|
||||
/**
|
||||
* Cancels a thread.
|
||||
*
|
||||
* This sets the threads requestFlag to OS_THREAD_REQUEST_CANCEL, the thread will
|
||||
* be terminated next time OSTestThreadCancel is called.
|
||||
*/
|
||||
void
|
||||
OSCancelThread(OSThread *thread);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the count of active threads.
|
||||
*/
|
||||
int32_t
|
||||
OSCheckActiveThreads();
|
||||
|
||||
|
||||
/**
|
||||
* Get the maximum amount of stack the thread has used.
|
||||
*/
|
||||
int32_t
|
||||
OSCheckThreadStackUsage(OSThread *thread);
|
||||
|
||||
|
||||
/**
|
||||
* Disable tracking of thread stack usage
|
||||
*/
|
||||
void
|
||||
OSClearThreadStackUsage(OSThread *thread);
|
||||
|
||||
|
||||
/**
|
||||
* Clears a thread's suspend counter and resumes it.
|
||||
*/
|
||||
void
|
||||
OSContinueThread(OSThread *thread);
|
||||
|
||||
|
||||
/**
|
||||
* Create a new thread.
|
||||
*
|
||||
* \param thread Thread to initialise.
|
||||
* \param entry Thread entry point.
|
||||
* \param argc argc argument passed to entry point.
|
||||
* \param argv argv argument passed to entry point.
|
||||
* \param stack Top of stack (highest address).
|
||||
* \param stackSize Size of stack.
|
||||
* \param priority Thread priority, 0 is highest priorty, 31 is lowest.
|
||||
* \param attributes Thread attributes, see OSThreadAttributes.
|
||||
*/
|
||||
BOOL
|
||||
OSCreateThread(OSThread *thread,
|
||||
OSThreadEntryPointFn entry,
|
||||
@ -224,111 +344,277 @@ OSCreateThread(OSThread *thread,
|
||||
int32_t priority,
|
||||
OSThreadAttributes attributes);
|
||||
|
||||
|
||||
/**
|
||||
* Detach thread.
|
||||
*/
|
||||
void
|
||||
OSDetachThread(OSThread *thread);
|
||||
|
||||
|
||||
/**
|
||||
* Exit the current thread with a exit code.
|
||||
*
|
||||
* This function is implicitly called when the thread entry point returns.
|
||||
*/
|
||||
void
|
||||
OSExitThread(int32_t result);
|
||||
|
||||
|
||||
/**
|
||||
* Get the next and previous thread in the thread's active queue.
|
||||
*/
|
||||
void
|
||||
OSGetActiveThreadLink(OSThread *thread,
|
||||
OSThreadLink *link);
|
||||
|
||||
|
||||
/**
|
||||
* Return pointer to OSThread object for the current thread.
|
||||
*/
|
||||
OSThread *
|
||||
OSGetCurrentThread();
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
OSThread *
|
||||
OSGetDefaultThread(uint32_t coreID);
|
||||
|
||||
|
||||
/**
|
||||
* Return current stack pointer, value of r1 register.
|
||||
*/
|
||||
uint32_t
|
||||
OSGetStackPointer();
|
||||
|
||||
|
||||
/**
|
||||
* Get a thread's affinity.
|
||||
*/
|
||||
uint32_t
|
||||
OSGetThreadAffinity(OSThread *thread);
|
||||
|
||||
|
||||
/**
|
||||
* Get a thread's name.
|
||||
*/
|
||||
const char *
|
||||
OSGetThreadName(OSThread *thread);
|
||||
|
||||
|
||||
/**
|
||||
* Get a thread's base priority.
|
||||
*/
|
||||
int32_t
|
||||
OSGetThreadPriority(OSThread *thread);
|
||||
|
||||
|
||||
/**
|
||||
* Get a thread's specific value set by OSSetThreadSpecific.
|
||||
*/
|
||||
uint32_t
|
||||
OSGetThreadSpecific(uint32_t id);
|
||||
|
||||
|
||||
/**
|
||||
* Returns TRUE if a thread is suspended.
|
||||
*/
|
||||
BOOL
|
||||
OSIsThreadSuspended(OSThread *thread);
|
||||
|
||||
|
||||
/**
|
||||
* Returns TRUE if a thread is terminated.
|
||||
*/
|
||||
BOOL
|
||||
OSIsThreadTerminated(OSThread *thread);
|
||||
|
||||
|
||||
/**
|
||||
* Wait until thread is terminated.
|
||||
*
|
||||
* If the target thread is detached, returns FALSE.
|
||||
*
|
||||
* \param thread Thread to wait for
|
||||
* \param threadResult Pointer to store thread exit value in.
|
||||
* \returns Returns TRUE if thread has terminated, FALSE if thread is detached.
|
||||
*/
|
||||
BOOL
|
||||
OSJoinThread(OSThread *thread,
|
||||
int *threadResult);
|
||||
|
||||
void
|
||||
OSPrintCurrentThreadState();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
int32_t
|
||||
OSResumeThread(OSThread *thread);
|
||||
|
||||
|
||||
/**
|
||||
* Run a function on an already created thread.
|
||||
*
|
||||
* Can only be used on idle threads.
|
||||
*/
|
||||
BOOL
|
||||
OSRunThread(OSThread *thread,
|
||||
OSThreadEntryPointFn entry,
|
||||
int argc,
|
||||
const char **argv);
|
||||
|
||||
|
||||
/**
|
||||
* Set a thread's affinity.
|
||||
*/
|
||||
BOOL
|
||||
OSSetThreadAffinity(OSThread *thread,
|
||||
uint32_t affinity);
|
||||
|
||||
|
||||
/**
|
||||
* Set a thread's cancellation state.
|
||||
*
|
||||
* If the state is TRUE then the thread can be suspended or cancelled when
|
||||
* OSTestThreadCancel is called.
|
||||
*/
|
||||
BOOL
|
||||
OSSetThreadCancelState(BOOL state);
|
||||
|
||||
|
||||
/**
|
||||
* Set the callback to be called just before a thread is terminated.
|
||||
*/
|
||||
OSThreadCleanupCallbackFn
|
||||
OSSetThreadCleanupCallback(OSThread *thread,
|
||||
OSThreadCleanupCallbackFn callback);
|
||||
|
||||
|
||||
/**
|
||||
* Set the callback to be called just after a thread is terminated.
|
||||
*/
|
||||
OSThreadDeallocatorFn
|
||||
OSSetThreadDeallocator(OSThread *thread,
|
||||
OSThreadDeallocatorFn deallocator);
|
||||
|
||||
|
||||
/**
|
||||
* Set a thread's name.
|
||||
*/
|
||||
void
|
||||
OSSetThreadName(OSThread *thread,
|
||||
const char *name);
|
||||
|
||||
|
||||
/**
|
||||
* Set a thread's priority.
|
||||
*/
|
||||
BOOL
|
||||
OSSetThreadPriority(OSThread *thread,
|
||||
int32_t priority);
|
||||
|
||||
|
||||
/**
|
||||
* Set a thread's run quantum.
|
||||
*
|
||||
* This is the maximum amount of time the thread can run for before being forced
|
||||
* to yield.
|
||||
*/
|
||||
BOOL
|
||||
OSSetThreadRunQuantum(OSThread *thread,
|
||||
uint32_t quantum);
|
||||
|
||||
/**
|
||||
* Set a thread specific value.
|
||||
*
|
||||
* Can be read with OSGetThreadSpecific.
|
||||
*/
|
||||
void
|
||||
OSSetThreadSpecific(uint32_t id,
|
||||
uint32_t value);
|
||||
|
||||
|
||||
/**
|
||||
* Set thread stack usage tracking.
|
||||
*/
|
||||
BOOL
|
||||
OSSetThreadStackUsage(OSThread *thread);
|
||||
|
||||
|
||||
/**
|
||||
* Sleep the current thread and add it to a thread queue.
|
||||
*
|
||||
* Will sleep until the thread queue is woken with OSWakeupThread.
|
||||
*/
|
||||
void
|
||||
OSSleepThread(OSThreadQueue *queue);
|
||||
|
||||
|
||||
/**
|
||||
* Sleep the current thread for a period of time.
|
||||
*/
|
||||
void
|
||||
OSSleepTicks(OSTime ticks);
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
uint32_t
|
||||
OSSuspendThread(OSThread *thread);
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
OSTestThreadCancel();
|
||||
|
||||
|
||||
/**
|
||||
* Wake up all threads in queue.
|
||||
*
|
||||
* Clears the thread queue.
|
||||
*/
|
||||
void
|
||||
OSWakeupThread(OSThreadQueue *queue);
|
||||
|
||||
|
||||
/**
|
||||
* Yield execution to waiting threads with same priority.
|
||||
*
|
||||
* This will never switch to a thread with a lower priority than the current
|
||||
* thread.
|
||||
*/
|
||||
void
|
||||
OSYieldThread();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -218,7 +218,6 @@ EXPORT(OSGetThreadSpecific);
|
||||
EXPORT(OSIsThreadSuspended);
|
||||
EXPORT(OSIsThreadTerminated);
|
||||
EXPORT(OSJoinThread);
|
||||
EXPORT(OSPrintCurrentThreadState);
|
||||
EXPORT(OSResumeThread);
|
||||
EXPORT(OSRunThread);
|
||||
EXPORT(OSSetThreadAffinity);
|
||||
|
Loading…
Reference in New Issue
Block a user