pspthreadman.h

Go to the documentation of this file.
00001 /*
00002  * PSP Software Development Kit - http://www.pspdev.org
00003  * -----------------------------------------------------------------------
00004  * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
00005  *
00006  * pspthreadman.h - Library imports for the kernel threading library.
00007  *
00008  * Copyright (c) 2005 Marcus R. Brown <mrbrown@ocgnet.org>
00009  * Copyright (c) 2005 James Forshaw <tyranid@gmail.com>
00010  * Copyright (c) 2005 John Kelley <ps2dev@kelley.ca>
00011  * Copyright (c) 2005 Florin Sasu
00012  *
00013  * $Id: pspthreadman.h 2166 2007-02-04 10:52:49Z tyranid $
00014  */
00015 #ifndef __THREADMAN_H__
00016 #define __THREADMAN_H__
00017 
00018 #include <psptypes.h>
00019 #include <pspkerneltypes.h>
00020 /* Include for profile register definitions */
00021 #include <pspdebug.h>
00022 
00023 /* Note: Some of the structures, types, and definitions in this file were
00024    extrapolated from symbolic debugging information found in the Japanese
00025    version of Puzzle Bobble. */
00026 
00031 #ifdef __cplusplus
00032 extern "C" {
00033 #endif
00034 
00038 
00040 typedef struct SceKernelSysClock {
00041         SceUInt32   low;
00042         SceUInt32   hi;
00043 } SceKernelSysClock;
00044 
00046 enum PspThreadAttributes
00047 {
00049         PSP_THREAD_ATTR_VFPU = 0x00004000,
00052         PSP_THREAD_ATTR_USER = 0x80000000,
00054         PSP_THREAD_ATTR_USBWLAN = 0xa0000000,
00056         PSP_THREAD_ATTR_VSH = 0xc0000000,
00058         PSP_THREAD_ATTR_SCRATCH_SRAM = 0x00008000,
00060         PSP_THREAD_ATTR_NO_FILLSTACK = 0x00100000,
00062         PSP_THREAD_ATTR_CLEAR_STACK = 0x00200000,
00063 };
00064 
00065 /* Maintained for compatibility with older versions of PSPSDK. */
00066 #define THREAD_ATTR_VFPU PSP_THREAD_ATTR_VFPU
00067 #define THREAD_ATTR_USER PSP_THREAD_ATTR_USER
00068 
00069 
00070 /* Threads. */
00071 
00072 typedef int (*SceKernelThreadEntry)(SceSize args, void *argp);
00073 
00075 typedef struct SceKernelThreadOptParam {
00077         SceSize         size;
00079         SceUID          stackMpid;
00080 } SceKernelThreadOptParam;
00081 
00085 typedef struct SceKernelThreadInfo {
00087         SceSize     size;
00089         char            name[32];
00091         SceUInt     attr;
00093         int             status;
00095         SceKernelThreadEntry    entry;
00097         void *          stack;
00099         int             stackSize;
00101         void *          gpReg;
00103         int             initPriority;
00105         int             currentPriority;
00107         int             waitType;
00109         SceUID          waitId;
00111         int             wakeupCount;
00113         int             exitStatus;
00115         SceKernelSysClock   runClocks;
00117         SceUInt     intrPreemptCount;
00119         SceUInt     threadPreemptCount;
00121         SceUInt     releaseCount;
00122 } SceKernelThreadInfo;
00123 
00127 typedef struct SceKernelThreadRunStatus {
00128         SceSize         size;
00129         int             status;
00130         int             currentPriority;
00131         int             waitType;
00132         int             waitId;
00133         int             wakeupCount;
00134         SceKernelSysClock runClocks;
00135         SceUInt         intrPreemptCount;
00136         SceUInt         threadPreemptCount;
00137         SceUInt         releaseCount;
00138 } SceKernelThreadRunStatus;
00139 
00140 /* Sure there must be more than this, but haven't seen them */
00141 enum PspThreadStatus
00142 {
00143         PSP_THREAD_RUNNING = 1,
00144         PSP_THREAD_READY   = 2,
00145         PSP_THREAD_WAITING = 4,
00146         PSP_THREAD_SUSPEND = 8,
00147         PSP_THREAD_STOPPED = 16,
00148         PSP_THREAD_KILLED  = 32, /* Thread manager has killed the thread (stack overflow) */
00149 };
00150 
00169 SceUID sceKernelCreateThread(const char *name, SceKernelThreadEntry entry, int initPriority,
00170                              int stackSize, SceUInt attr, SceKernelThreadOptParam *option);
00171 
00179 int sceKernelDeleteThread(SceUID thid);
00180 
00188 int sceKernelStartThread(SceUID thid, SceSize arglen, void *argp);
00189 
00195 int sceKernelExitThread(int status);
00196 
00202 int sceKernelExitDeleteThread(int status);
00203 
00211 int sceKernelTerminateThread(SceUID thid);
00212 
00220 int sceKernelTerminateDeleteThread(SceUID thid);
00221 
00227 int sceKernelSuspendDispatchThread(void);
00228 
00237 int sceKernelResumeDispatchThread(int state);
00238 
00244 int sceKernelSleepThread(void);
00245 
00255 int sceKernelSleepThreadCB(void);
00256 
00264 int sceKernelWakeupThread(SceUID thid);
00265 
00273 int sceKernelCancelWakeupThread(SceUID thid);
00274 
00282 int sceKernelSuspendThread(SceUID thid);
00283 
00291 int sceKernelResumeThread(SceUID thid);
00292 
00301 int sceKernelWaitThreadEnd(SceUID thid, SceUInt *timeout);
00302 
00311 int sceKernelWaitThreadEndCB(SceUID thid, SceUInt *timeout);
00312 
00323 int sceKernelDelayThread(SceUInt delay);
00324 
00335 int sceKernelDelayThreadCB(SceUInt delay);
00336 
00344 int sceKernelDelaySysClockThread(SceKernelSysClock *delay);
00345 
00354 int sceKernelDelaySysClockThreadCB(SceKernelSysClock *delay);
00355 
00364 int sceKernelChangeCurrentThreadAttr(int unknown, SceUInt attr);
00365 
00381 int sceKernelChangeThreadPriority(SceUID thid, int priority);
00382 
00390 int sceKernelRotateThreadReadyQueue(int priority);
00391 
00399 int sceKernelReleaseWaitThread(SceUID thid);
00400 
00406 int sceKernelGetThreadId(void);
00407 
00413 int sceKernelGetThreadCurrentPriority(void);
00414 
00422 int sceKernelGetThreadExitStatus(SceUID thid);
00423 
00429 int sceKernelCheckThreadStack(void);
00430 
00439 int sceKernelGetThreadStackFreeSize(SceUID thid);
00440 
00458 int sceKernelReferThreadStatus(SceUID thid, SceKernelThreadInfo *info);
00459 
00468 int sceKernelReferThreadRunStatus(SceUID thid, SceKernelThreadRunStatus *status);
00469 
00470 
00471 /* Semaphores. */
00472 
00474 typedef struct SceKernelSemaOptParam {
00476         SceSize         size;
00477 } SceKernelSemaOptParam;
00478 
00482 typedef struct SceKernelSemaInfo {
00484         SceSize         size;
00486         char            name[32];
00488         SceUInt         attr;
00490         int             initCount;
00492         int             currentCount;
00494         int             maxCount;
00496         int             numWaitThreads;
00497 } SceKernelSemaInfo;
00498 
00515 SceUID sceKernelCreateSema(const char *name, SceUInt attr, int initVal, int maxVal, SceKernelSemaOptParam *option);
00516 
00523 int sceKernelDeleteSema(SceUID semaid);
00524 
00539 int sceKernelSignalSema(SceUID semaid, int signal);
00540 
00555 int sceKernelWaitSema(SceUID semaid, int signal, SceUInt *timeout);
00556 
00571 int sceKernelWaitSemaCB(SceUID semaid, int signal, SceUInt *timeout);
00572 
00581 int sceKernelPollSema(SceUID semaid, int signal);
00582 
00591 int sceKernelReferSemaStatus(SceUID semaid, SceKernelSemaInfo *info);
00592 
00593 
00594 /* Event flags. */
00595 
00597 typedef struct SceKernelEventFlagInfo {
00598         SceSize         size;
00599         char            name[32];
00600         SceUInt         attr;
00601         SceUInt         initPattern;
00602         SceUInt         currentPattern;
00603         int             numWaitThreads;
00604 } SceKernelEventFlagInfo;
00605 
00606 struct SceKernelEventFlagOptParam {
00607         SceSize         size;
00608 };
00609 
00610 typedef struct SceKernelEventFlagOptParam SceKernelEventFlagOptParam;
00611 
00613 enum PspEventFlagAttributes
00614 {
00616         PSP_EVENT_WAITMULTIPLE = 0x200
00617 };
00618 
00620 enum PspEventFlagWaitTypes
00621 {
00623         PSP_EVENT_WAITAND = 0,
00625         PSP_EVENT_WAITOR  = 1,
00627         PSP_EVENT_WAITCLEAR = 0x20
00628 };
00629 
00645 SceUID sceKernelCreateEventFlag(const char *name, int attr, int bits, SceKernelEventFlagOptParam *opt);
00646 
00655 int sceKernelSetEventFlag(SceUID evid, u32 bits);
00656 
00665 int sceKernelClearEventFlag(SceUID evid, u32 bits);
00666 
00676 int sceKernelPollEventFlag(int evid, u32 bits, u32 wait, u32 *outBits);
00677 
00688 int sceKernelWaitEventFlag(int evid, u32 bits, u32 wait, u32 *outBits, SceUInt *timeout);
00689 
00700 int sceKernelWaitEventFlagCB(int evid, u32 bits, u32 wait, u32 *outBits, SceUInt *timeout);
00701 
00709 int sceKernelDeleteEventFlag(int evid);
00710 
00719 int sceKernelReferEventFlagStatus(SceUID event, SceKernelEventFlagInfo *status);
00720 
00721 
00722 /* Message boxes. */
00723 
00725 typedef struct SceKernelMbxOptParam {
00727         SceSize         size;
00728 } SceKernelMbxOptParam;
00729 
00733 typedef struct SceKernelMbxInfo {
00735         SceSize         size;
00737         char            name[32];
00739         SceUInt         attr;
00741         int             numWaitThreads;
00743         int             numMessages;
00745         void            *firstMessage;
00746 } SceKernelMbxInfo;
00747 
00751 typedef struct SceKernelMsgPacket {
00753         struct SceKernelMsgPacket *next;
00755         SceUChar    msgPriority;
00756         SceUChar    dummy[3];
00758 } SceKernelMsgPacket;
00759 
00774 SceUID sceKernelCreateMbx(const char *name, SceUInt attr, SceKernelMbxOptParam *option);
00775 
00782 int sceKernelDeleteMbx(SceUID mbxid);
00783 
00806 int sceKernelSendMbx(SceUID mbxid, void *message);
00807 
00824 int sceKernelReceiveMbx(SceUID mbxid, void **pmessage, SceUInt *timeout);
00825 
00842 int sceKernelReceiveMbxCB(SceUID mbxid, void **pmessage, SceUInt *timeout);
00843 
00859 int sceKernelPollMbx(SceUID mbxid, void **pmessage);
00860 
00876 int sceKernelCancelReceiveMbx(SceUID mbxid, int *pnum);
00877 
00886 int sceKernelReferMbxStatus(SceUID mbxid, SceKernelMbxInfo *info);
00887 
00888 
00889 /* Alarms. */
00890 
00892 typedef SceUInt (*SceKernelAlarmHandler)(void *common);
00893 
00895 typedef struct SceKernelAlarmInfo {
00898         SceSize         size;
00899         /* The current schedule */
00900         SceKernelSysClock schedule;
00902         SceKernelAlarmHandler handler;
00904         void *          common;
00905 } SceKernelAlarmInfo;
00906 
00915 SceUID sceKernelSetAlarm(SceUInt clock, SceKernelAlarmHandler handler, void *common);
00916 
00926 SceUID sceKernelSetSysClockAlarm(SceKernelSysClock *clock, SceKernelAlarmHandler handler, void *common);
00927 
00935 int sceKernelCancelAlarm(SceUID alarmid);
00936 
00945 int sceKernelReferAlarmStatus(SceUID alarmid, SceKernelAlarmInfo *info);
00946 
00947 /* Callbacks. */
00948 
00950 typedef int (*SceKernelCallbackFunction)(int arg1, int arg2, void *arg);
00951 
00953 typedef struct SceKernelCallbackInfo {
00955         SceSize         size;
00957         char    name[32];
00959         SceUID  threadId;
00961         SceKernelCallbackFunction       callback;
00963         void *  common;
00965         int     notifyCount;
00967         int     notifyArg;
00968 } SceKernelCallbackInfo;
00969 
00985 int sceKernelCreateCallback(const char *name, SceKernelCallbackFunction func, void *arg);
00986 
00996 int sceKernelReferCallbackStatus(SceUID cb, SceKernelCallbackInfo *status);
00997 
01005 int sceKernelDeleteCallback(SceUID cb);
01006 
01015 int sceKernelNotifyCallback(SceUID cb, int arg2);
01016 
01024 int sceKernelCancelCallback(SceUID cb);
01025 
01033 int sceKernelGetCallbackCount(SceUID cb);
01034 
01040 int sceKernelCheckCallback(void);
01041 
01042 /* Misc. */
01043 
01045 enum SceKernelIdListType
01046 {
01047         SCE_KERNEL_TMID_Thread = 1,
01048         SCE_KERNEL_TMID_Semaphore = 2,
01049         SCE_KERNEL_TMID_EventFlag = 3,
01050         SCE_KERNEL_TMID_Mbox = 4,
01051         SCE_KERNEL_TMID_Vpl = 5,
01052         SCE_KERNEL_TMID_Fpl = 6,
01053         SCE_KERNEL_TMID_Mpipe = 7,
01054         SCE_KERNEL_TMID_Callback = 8,
01055         SCE_KERNEL_TMID_ThreadEventHandler = 9,
01056         SCE_KERNEL_TMID_Alarm = 10,
01057         SCE_KERNEL_TMID_VTimer = 11,
01058         SCE_KERNEL_TMID_SleepThread = 64,
01059         SCE_KERNEL_TMID_DelayThread = 65,
01060         SCE_KERNEL_TMID_SuspendThread = 66,
01061         SCE_KERNEL_TMID_DormantThread = 67,
01062 };
01063 
01075 int sceKernelGetThreadmanIdList(enum SceKernelIdListType type, SceUID *readbuf, int readbufsize, int *idcount);
01076 
01078 typedef struct SceKernelSystemStatus {
01080         SceSize         size;
01082         SceUInt         status;
01084         SceKernelSysClock       idleClocks;
01086         SceUInt         comesOutOfIdleCount;
01088         SceUInt         threadSwitchCount;
01090         SceUInt         vfpuSwitchCount;
01091 } SceKernelSystemStatus;
01092 
01100 int sceKernelReferSystemStatus(SceKernelSystemStatus *status);
01101 
01102 
01114 SceUID sceKernelCreateMsgPipe(const char *name, int part, int attr, void *unk1, void *opt);
01115 
01123 int sceKernelDeleteMsgPipe(SceUID uid);
01124 
01137 int sceKernelSendMsgPipe(SceUID uid, void *message, unsigned int size, int unk1, void *unk2, unsigned int *timeout);
01138 
01151 int sceKernelSendMsgPipeCB(SceUID uid, void *message, unsigned int size, int unk1, void *unk2, unsigned int *timeout);
01152 
01164 int sceKernelTrySendMsgPipe(SceUID uid, void *message, unsigned int size, int unk1, void *unk2);
01165 
01178 int sceKernelReceiveMsgPipe(SceUID uid, void *message, unsigned int size, int unk1, void *unk2, unsigned int *timeout);
01179 
01192 int sceKernelReceiveMsgPipeCB(SceUID uid, void *message, unsigned int size, int unk1, void *unk2, unsigned int *timeout);
01193 
01205 int sceKernelTryReceiveMsgPipe(SceUID uid, void *message, unsigned int size, int unk1, void *unk2);
01206 
01216 int sceKernelCancelMsgPipe(SceUID uid, int *psend, int *precv);
01217 
01219 typedef struct SceKernelMppInfo {
01220         SceSize         size;
01221         char    name[32];
01222         SceUInt         attr;
01223         int     bufSize;
01224         int     freeSize;
01225         int     numSendWaitThreads;
01226         int     numReceiveWaitThreads;
01227 } SceKernelMppInfo;
01228  
01237 int sceKernelReferMsgPipeStatus(SceUID uid, SceKernelMppInfo *info);
01238 
01239 /* VPL Functions */
01240 
01241 struct SceKernelVplOptParam {
01242         SceSize         size;
01243 };
01244 
01256 SceUID sceKernelCreateVpl(const char *name, int part, int attr, unsigned int size, struct SceKernelVplOptParam *opt);
01257 
01265 int sceKernelDeleteVpl(SceUID uid);
01266 
01277 int sceKernelAllocateVpl(SceUID uid, unsigned int size, void **data, unsigned int *timeout);
01278 
01289 int sceKernelAllocateVplCB(SceUID uid, unsigned int size, void **data, unsigned int *timeout);
01290 
01300 int sceKernelTryAllocateVpl(SceUID uid, unsigned int size, void **data);
01301 
01310 int sceKernelFreeVpl(SceUID uid, void *data);
01311 
01320 int sceKernelCancelVpl(SceUID uid, int *pnum);
01321 
01323 typedef struct SceKernelVplInfo {
01324         SceSize         size;
01325         char    name[32];
01326         SceUInt         attr;
01327         int     poolSize;
01328         int     freeSize;
01329         int     numWaitThreads;
01330 } SceKernelVplInfo;
01331 
01340 int sceKernelReferVplStatus(SceUID uid, SceKernelVplInfo *info);
01341 
01342 /* FPL Functions */
01343 
01344 struct SceKernelFplOptParam {
01345         SceSize         size;
01346 };
01347 
01360 int sceKernelCreateFpl(const char *name, int part, int attr, unsigned int size, unsigned int blocks, struct SceKernelFplOptParam *opt);
01361 
01369 int sceKernelDeleteFpl(SceUID uid);
01370 
01380 int sceKernelAllocateFpl(SceUID uid, void **data, unsigned int *timeout);
01381 
01391 int sceKernelAllocateFplCB(SceUID uid, void **data, unsigned int *timeout);
01392 
01401 int sceKernelTryAllocateFpl(SceUID uid, void **data);
01402 
01411 int sceKernelFreeFpl(SceUID uid, void *data);
01412 
01421 int sceKernelCancelFpl(SceUID uid, int *pnum);
01422 
01424 typedef struct SceKernelFplInfo {
01425         SceSize         size;
01426         char    name[32];
01427         SceUInt         attr;
01428         int     blockSize;
01429         int     numBlocks;
01430         int     freeBlocks;
01431         int     numWaitThreads;
01432 } SceKernelFplInfo;
01433 
01442 int sceKernelReferFplStatus(SceUID uid, SceKernelFplInfo *info);
01443 
01447 void _sceKernelReturnFromTimerHandler(void);
01448 
01453 void _sceKernelReturnFromCallback(void);
01454 
01463 int sceKernelUSec2SysClock(unsigned int usec, SceKernelSysClock *clock);
01464 
01472 SceInt64 sceKernelUSec2SysClockWide(unsigned int usec);
01473 
01483 int sceKernelSysClock2USec(SceKernelSysClock *clock, unsigned int *low, unsigned int *high);
01484 
01494 int sceKernelSysClock2USecWide(SceInt64 clock, unsigned *low, unsigned int *high);
01495 
01503 int sceKernelGetSystemTime(SceKernelSysClock *time);
01504 
01510 SceInt64 sceKernelGetSystemTimeWide(void);
01511 
01517 unsigned int sceKernelGetSystemTimeLow(void);
01518 
01519 struct SceKernelVTimerOptParam {
01520         SceSize         size;
01521 };
01522 
01531 SceUID sceKernelCreateVTimer(const char *name, struct SceKernelVTimerOptParam *opt);
01532 
01540 int sceKernelDeleteVTimer(SceUID uid);
01541 
01550 int sceKernelGetVTimerBase(SceUID uid, SceKernelSysClock *base);
01551 
01559 SceInt64 sceKernelGetVTimerBaseWide(SceUID uid);
01560 
01569 int sceKernelGetVTimerTime(SceUID uid, SceKernelSysClock *time);
01570 
01578 SceInt64 sceKernelGetVTimerTimeWide(SceUID uid);
01579 
01588 int sceKernelSetVTimerTime(SceUID uid, SceKernelSysClock *time);
01589 
01598 SceInt64 sceKernelSetVTimerTimeWide(SceUID uid, SceInt64 time);
01599 
01607 int sceKernelStartVTimer(SceUID uid);
01608 
01616 int sceKernelStopVTimer(SceUID uid);
01617 
01618 typedef SceUInt (*SceKernelVTimerHandler)(SceUID uid, SceKernelSysClock *, SceKernelSysClock *, void *);
01619 typedef SceUInt (*SceKernelVTimerHandlerWide)(SceUID uid, SceInt64, SceInt64, void *);
01620 
01631 int sceKernelSetVTimerHandler(SceUID uid, SceKernelSysClock *time, SceKernelVTimerHandler handler, void *common);
01632 
01643 int sceKernelSetVTimerHandlerWide(SceUID uid, SceInt64 time, SceKernelVTimerHandlerWide handler, void *common);
01644 
01652 int sceKernelCancelVTimerHandler(SceUID uid);
01653 
01654 typedef struct SceKernelVTimerInfo {
01655         SceSize         size;
01656         char    name[32];
01657         int     active;
01658         SceKernelSysClock       base;
01659         SceKernelSysClock       current;
01660         SceKernelSysClock       schedule;
01661         SceKernelVTimerHandler  handler;
01662         void *  common;
01663 } SceKernelVTimerInfo;
01664 
01673 int sceKernelReferVTimerStatus(SceUID uid, SceKernelVTimerInfo *info);
01674 
01679 void _sceKernelExitThread(void);
01680 
01688 enum SceKernelIdListType sceKernelGetThreadmanIdType(SceUID uid);
01689 
01690 typedef int (*SceKernelThreadEventHandler)(int mask, SceUID thid, void *common);
01691 
01693 typedef struct SceKernelThreadEventHandlerInfo {
01694         SceSize         size;
01695         char    name[32];
01696         SceUID  threadId;
01697         int     mask;
01698         SceKernelThreadEventHandler     handler;
01699         void *  common;
01700 } SceKernelThreadEventHandlerInfo;
01701 
01702 enum ThreadEventIds
01703 {
01704         THREADEVENT_ALL = 0xFFFFFFFF,
01705         THREADEVENT_KERN = 0xFFFFFFF8,
01706         THREADEVENT_USER = 0xFFFFFFF0,
01707         THREADEVENT_CURRENT = 0
01708 };
01709 
01710 enum ThreadEvents
01711 {
01712         THREAD_CREATE = 1,
01713         THREAD_START  = 2,
01714         THREAD_EXIT   = 4,
01715         THREAD_DELETE = 8,
01716 };
01717 
01729 SceUID sceKernelRegisterThreadEventHandler(const char *name, SceUID threadID, int mask, SceKernelThreadEventHandler handler, void *common);
01730 
01738 int sceKernelReleaseThreadEventHandler(SceUID uid);
01739 
01748 int sceKernelReferThreadEventHandlerStatus(SceUID uid, struct SceKernelThreadEventHandlerInfo *info);
01749 
01754 PspDebugProfilerRegs *sceKernelReferThreadProfiler(void);
01755 
01760 PspDebugProfilerRegs *sceKernelReferGlobalProfiler(void);
01761 
01764 #ifdef __cplusplus
01765 }
01766 #endif
01767 
01768 #endif

Generated on Tue Jul 24 15:21:23 2007 for PSPSDK-Rev2272 by  doxygen 1.5.2