2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _DOLPHIN_OSTHREAD
|
|
|
|
#define _DOLPHIN_OSTHREAD
|
2022-09-10 20:32:26 +00:00
|
|
|
|
|
|
|
#include <dolphin/os/OSContext.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define OS_THREAD_SPECIFIC_MAX 2
|
|
|
|
|
|
|
|
typedef struct OSThread OSThread;
|
|
|
|
typedef struct OSThreadQueue OSThreadQueue;
|
|
|
|
typedef struct OSThreadLink OSThreadLink;
|
|
|
|
typedef s32 OSPriority; // 0 highest, 31 lowest
|
|
|
|
|
|
|
|
typedef struct OSMutex OSMutex;
|
|
|
|
typedef struct OSMutexQueue OSMutexQueue;
|
|
|
|
typedef struct OSMutexLink OSMutexLink;
|
|
|
|
typedef struct OSCond OSCond;
|
|
|
|
|
|
|
|
typedef void (*OSIdleFunction)(void* param);
|
|
|
|
typedef void (*OSSwitchThreadCallback)(OSThread* from, OSThread* to);
|
|
|
|
|
|
|
|
struct OSThreadQueue {
|
|
|
|
OSThread* head;
|
|
|
|
OSThread* tail;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OSThreadLink {
|
|
|
|
OSThread* next;
|
|
|
|
OSThread* prev;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OSMutexQueue {
|
|
|
|
OSMutex* head;
|
|
|
|
OSMutex* tail;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OSMutexLink {
|
|
|
|
OSMutex* next;
|
|
|
|
OSMutex* prev;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OSThread {
|
|
|
|
OSContext context;
|
|
|
|
u16 state;
|
|
|
|
u16 attr;
|
|
|
|
s32 suspend;
|
|
|
|
OSPriority priority;
|
|
|
|
OSPriority base;
|
|
|
|
void* val;
|
|
|
|
OSThreadQueue* queue;
|
|
|
|
OSThreadLink link;
|
|
|
|
OSThreadQueue queueJoin;
|
|
|
|
OSMutex* mutex;
|
|
|
|
OSMutexQueue queueMutex;
|
|
|
|
OSThreadLink linkActive;
|
|
|
|
u8* stackBase;
|
|
|
|
u32* stackEnd;
|
|
|
|
s32 error;
|
|
|
|
void* specific[OS_THREAD_SPECIFIC_MAX];
|
|
|
|
};
|
|
|
|
|
2022-11-05 10:21:17 +00:00
|
|
|
enum OS_THREAD_STATE {
|
|
|
|
OS_THREAD_STATE_READY = 1,
|
|
|
|
OS_THREAD_STATE_RUNNING = 2,
|
|
|
|
OS_THREAD_STATE_WAITING = 4,
|
|
|
|
OS_THREAD_STATE_MORIBUND = 8
|
|
|
|
};
|
|
|
|
|
|
|
|
#define OS_THREAD_ATTR_DETACH 0x0001u
|
|
|
|
|
|
|
|
#define OS_THREAD_STACK_MAGIC 0xDEADBABE
|
|
|
|
|
|
|
|
#define OS_PRIORITY_MIN 0 // highest
|
|
|
|
#define OS_PRIORITY_MAX 31 // lowest
|
|
|
|
#define OS_PRIORITY_IDLE OS_PRIORITY_MAX
|
|
|
|
|
|
|
|
|
|
|
|
void OSInitThreadQueue(OSThreadQueue* queue);
|
2022-09-13 04:26:54 +00:00
|
|
|
OSThread* OSGetCurrentThread(void);
|
2022-11-05 10:21:17 +00:00
|
|
|
BOOL OSIsThreadSuspended(OSThread* thread);
|
|
|
|
BOOL OSIsThreadTerminated(OSThread* thread);
|
|
|
|
s32 OSDisableScheduler(void);
|
|
|
|
s32 OSEnableScheduler(void);
|
|
|
|
void OSYieldThread(void);
|
|
|
|
BOOL OSCreateThread(OSThread* thread, void* (*func)(void*), void* param, void* stack, u32 stackSize,
|
|
|
|
OSPriority priority, u16 attr);
|
|
|
|
void OSExitThread(void* val);
|
|
|
|
void OSCancelThread(OSThread* thread);
|
|
|
|
BOOL OSJoinThread(OSThread* thread, void** val);
|
|
|
|
void OSDetachThread(OSThread* thread);
|
|
|
|
s32 OSResumeThread(OSThread* thread);
|
|
|
|
s32 OSSuspendThread(OSThread* thread);
|
|
|
|
BOOL OSSetThreadPriority(OSThread* thread, OSPriority priority);
|
|
|
|
OSPriority OSGetThreadPriority(OSThread* thread);
|
|
|
|
void OSSleepThread(OSThreadQueue* queue);
|
|
|
|
void OSWakeupThread(OSThreadQueue* queue);
|
|
|
|
|
|
|
|
void* OSGetThreadSpecific(s32 index);
|
|
|
|
void OSSetThreadSpecific(s32 index, void* ptr);
|
|
|
|
|
|
|
|
OSThread* OSSetIdleFunction(OSIdleFunction idleFunction, void* param, void* stack, u32 stackSize);
|
|
|
|
OSThread* OSGetIdleFunction(void);
|
|
|
|
void OSClearStack(u8 val);
|
|
|
|
long OSCheckActiveThreads(void);
|
2022-09-13 04:26:54 +00:00
|
|
|
|
2022-09-10 20:32:26 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _DOLPHIN_OSTHREAD
|