PS2SDK
PS2 Homebrew Libraries
thbase.h
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright (c) 2003 Marcus R. Brown <mrbrown@0xd6.org>
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
16 #ifndef __THBASE_H__
17 #define __THBASE_H__
18 
19 #include <types.h>
20 #include <irx.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 // Thread attribute definitions
27 #define TH_ASM 0x01000000
28 #define TH_C 0x02000000
29 #define TH_UMODE 0x00000008
30 #define TH_NO_FILLSTACK 0x00100000
31 #define TH_CLEAR_STACK 0x00200000
32 
33 // Thread priority definitions
34 #define HIGHEST_PRIORITY 1
35 #define USER_HIGHEST_PRIORITY 9
36 #define USER_LOWEST_PRIORITY 123
37 #define LOWEST_PRIORITY 126
38 
39 typedef struct _iop_thread
40 {
41  u32 attr;
42  u32 option;
43  void (*thread)(void *userdata);
44  u32 stacksize;
45  u32 priority;
46 } iop_thread_t;
47 
49 #define TH_SELF 0
50 
51 // Thread status definitions
52 #define THS_RUN 0x01
53 #define THS_READY 0x02
54 #define THS_WAIT 0x04
55 #define THS_SUSPEND 0x08
56 #define THS_WAITSUSPEND 0x0C
57 #define THS_DORMANT 0x10
58 
59 // Thread wait status definitions
60 #define TSW_SLEEP 1
61 #define TSW_DELAY 2
62 #define TSW_SEMA 3
63 #define TSW_EVENTFLAG 4
64 #define TSW_MBX 5
65 #define TSW_VPL 6
66 #define TSW_FPL 7
67 
68 typedef struct _iop_thread_status
69 {
70  unsigned int attr;
71  unsigned int option;
72  int status;
73  void *entry;
74  void *stack;
75  int stackSize;
76  void *gpReg;
77  int initPriority;
78  int currentPriority;
79  int waitType;
80  int waitId;
81  int wakeupCount;
83  long int *regContext; //
84  unsigned int reserved[4];
86 
87 typedef struct _iop_sys_clock
88 {
89  u32 lo, hi;
91 
92 typedef struct _iop_thread_run_status
93 {
94  int status;
95  int currentPriority;
96  int waitType;
97  int waitId;
98  int wakeupCount;
99  long int *regContext;
100  iop_sys_clock_t runClocks;
101  unsigned int intrPreemptCount;
102  unsigned int threadPreemptCount;
103  unsigned int releaseCount;
105 
106 typedef struct _iop_sys_status
107 {
108  unsigned int status;
109  int systemLowTimerWidth;
110  iop_sys_clock_t idleClocks;
111  iop_sys_clock_t kernelClocks;
112  unsigned int comesOutOfIdleCount;
113  unsigned int threadSwitchCount;
114  unsigned int reserved[8];
116 
117 extern void *GetThreadmanData(void);
118 
119 extern int CreateThread(iop_thread_t *thread);
120 extern int DeleteThread(int thid);
121 
122 extern int StartThread(int thid, void *arg);
123 extern int StartThreadArgs(int thid, int args, void *argp);
124 
125 extern int ExitThread();
126 extern int ExitDeleteThread();
127 extern int TerminateThread(int thid);
128 extern int iTerminateThread(int thid);
129 
130 extern int DisableDispatchThread(void);
131 extern int EnableDispatchThread(void);
132 
133 extern int ChangeThreadPriority(int thid, int priority);
134 extern int iChangeThreadPriority(int thid, int priority);
135 
136 extern int RotateThreadReadyQueue(int priority);
137 extern int iRotateThreadReadyQueue(int priority);
138 
139 extern int ReleaseWaitThread(int thid);
140 extern int iReleaseWaitThread(int thid);
141 
142 extern int GetThreadId(void);
143 extern int CheckThreadStack(void);
144 extern int ReferThreadStatus(int thid, iop_thread_info_t *info);
145 extern int iReferThreadStatus(int thid, iop_thread_info_t *info);
146 
147 extern int SleepThread(void);
148 extern int WakeupThread(int thid);
149 extern int iWakeupThread(int thid);
150 extern int CancelWakeupThread(int thid);
151 extern int iCancelWakeupThread(int thid);
152 
153 extern int SuspendThread(int thid);
154 extern int iSuspendThread(int thid);
155 extern int ResumeThread(int thid);
156 extern int iResumeThread(int thid);
157 
158 extern int DelayThread(int usec);
159 
160 extern int GetSystemTime(iop_sys_clock_t *sys_clock);
161 extern int SetAlarm(iop_sys_clock_t *sys_clock, unsigned int (*alarm_cb)(void *userdata), void *arg);
162 extern int iSetAlarm(iop_sys_clock_t *sys_clock, unsigned int (*alarm_cb)(void *userdata), void *arg);
163 extern int CancelAlarm(unsigned int (*alarm_cb)(void *userdata), void *arg);
164 extern int iCancelAlarm(unsigned int (*alarm_cb)(void *userdata), void *arg);
165 extern void USec2SysClock(u32 usec, iop_sys_clock_t *sys_clock);
166 extern void SysClock2USec(iop_sys_clock_t *sys_clock, u32 *sec, u32 *usec);
167 
168 extern int GetSystemStatusFlag();
169 
170 // clang-format off
171 #define thbase_IMPORTS \
172  thbase_IMPORTS_start \
173  \
174  I_GetThreadmanData \
175  \
176  I_CreateThread \
177  I_DeleteThread \
178  \
179  I_StartThread \
180  I_StartThreadArgs \
181  \
182  I_ExitThread \
183  I_ExitDeleteThread \
184  I_TerminateThread \
185  I_iTerminateThread \
186  \
187  I_DisableDispatchThread \
188  I_EnableDispatchThread \
189  \
190  I_ChangeThreadPriority \
191  I_iChangeThreadPriority \
192  \
193  I_RotateThreadReadyQueue \
194  I_iRotateThreadReadyQueue \
195  \
196  I_ReleaseWaitThread \
197  I_iReleaseWaitThread \
198  \
199  I_GetThreadId \
200  I_ReferThreadStatus \
201  I_iReferThreadStatus \
202  \
203  I_SleepThread \
204  I_WakeupThread \
205  I_iWakeupThread \
206  I_CancelWakeupThread \
207  I_iCancelWakeupThread \
208  \
209  I_SuspendThread \
210  I_iSuspendThread \
211  I_ResumeThread \
212  I_iResumeThread \
213  \
214  I_DelayThread \
215  \
216  I_GetSystemTime \
217  I_SetAlarm \
218  I_iSetAlarm \
219  I_CancelAlarm \
220  I_iCancelAlarm \
221  I_USec2SysClock \
222  I_SysClock2USec \
223  \
224  I_GetSystemStatusFlag \
225  \
226  thbase_IMPORTS_end
227 // clang-format on
228 
229 #define thbase_IMPORTS_start DECLARE_IMPORT_TABLE(thbase, 1, 1)
230 #define thbase_IMPORTS_end END_IMPORT_TABLE
231 
232 #define I_GetThreadmanData DECLARE_IMPORT(3, GetThreadmanData)
233 #define I_CreateThread DECLARE_IMPORT(4, CreateThread)
234 #define I_DeleteThread DECLARE_IMPORT(5, DeleteThread)
235 #define I_StartThread DECLARE_IMPORT(6, StartThread)
236 #define I_StartThreadArgs DECLARE_IMPORT(7, StartThreadArgs)
237 #define I_ExitThread DECLARE_IMPORT(8, ExitThread)
238 #define I_ExitDeleteThread DECLARE_IMPORT(9, ExitDeleteThread)
239 #define I_TerminateThread DECLARE_IMPORT(10, TerminateThread)
240 #define I_iTerminateThread DECLARE_IMPORT(11, iTerminateThread)
241 #define I_DisableDispatchThread DECLARE_IMPORT(12, DisableDispatchThread)
242 #define I_EnableDispatchThread DECLARE_IMPORT(13, EnableDispatchThread)
243 #define I_ChangeThreadPriority DECLARE_IMPORT(14, ChangeThreadPriority)
244 #define I_iChangeThreadPriority DECLARE_IMPORT(15, iChangeThreadPriority)
245 #define I_RotateThreadReadyQueue DECLARE_IMPORT(16, RotateThreadReadyQueue)
246 #define I_iRotateThreadReadyQueue DECLARE_IMPORT(17, iRotateThreadReadyQueue)
247 #define I_ReleaseWaitThread DECLARE_IMPORT(18, ReleaseWaitThread)
248 #define I_iReleaseWaitThread DECLARE_IMPORT(19, iReleaseWaitThread)
249 #define I_GetThreadId DECLARE_IMPORT(20, GetThreadId)
250 #define I_CheckThreadStack DECLARE_IMPORT(21, CheckThreadStack)
251 #define I_ReferThreadStatus DECLARE_IMPORT(22, ReferThreadStatus)
252 #define I_iReferThreadStatus DECLARE_IMPORT(23, iReferThreadStatus)
253 #define I_SleepThread DECLARE_IMPORT(24, SleepThread)
254 #define I_WakeupThread DECLARE_IMPORT(25, WakeupThread)
255 #define I_iWakeupThread DECLARE_IMPORT(26, iWakeupThread)
256 #define I_CancelWakeupThread DECLARE_IMPORT(27, CancelWakeupThread)
257 #define I_iCancelWakeupThread DECLARE_IMPORT(28, iCancelWakeupThread)
258 #define I_SuspendThread DECLARE_IMPORT(29, SuspendThread)
259 #define I_iSuspendThread DECLARE_IMPORT(30, iSuspendThread)
260 #define I_ResumeThread DECLARE_IMPORT(31, ResumeThread)
261 #define I_iResumeThread DECLARE_IMPORT(32, iResumeThread)
262 #define I_DelayThread DECLARE_IMPORT(33, DelayThread)
263 #define I_GetSystemTime DECLARE_IMPORT(34, GetSystemTime)
264 #define I_SetAlarm DECLARE_IMPORT(35, SetAlarm)
265 #define I_iSetAlarm DECLARE_IMPORT(36, iSetAlarm)
266 #define I_CancelAlarm DECLARE_IMPORT(37, CancelAlarm)
267 #define I_iCancelAlarm DECLARE_IMPORT(38, iCancelAlarm)
268 #define I_USec2SysClock DECLARE_IMPORT(39, USec2SysClock)
269 #define I_SysClock2USec DECLARE_IMPORT(40, SysClock2USec)
270 #define I_GetSystemStatusFlag DECLARE_IMPORT(41, GetSystemStatusFlag)
271 
272 #ifdef __cplusplus
273 }
274 #endif
275 
276 #endif /* __THBASE_H__ */
s_info
Definition: xprintf.c:78
thread
Definition: thcommon.h:143
_iop_thread_run_status
Definition: thbase.h:92
irx.h
_iop_sys_status
Definition: thbase.h:106
_iop_thread_status::regContext
long int * regContext
Definition: thbase.h:83
_iop_thread
Definition: thbase.h:39
_iop_sys_clock
Definition: thbase.h:87
_iop_thread_status
Definition: thbase.h:68