PSP2SDK  dirty-f9e4f2d
The free SDK for PSP2
include/psp2/kernel/threadmgr.h
Go to the documentation of this file.
00001 
00012 #ifndef _PSP2_KERNEL_THREADMGR_H_
00013 #define _PSP2_KERNEL_THREADMGR_H_
00014 
00015 #include <psp2/types.h>
00016 
00017 #ifdef __cplusplus
00018 extern "C" {
00019 #endif
00020 
00022 typedef SceUInt64 SceKernelSysClock;
00023 
00024 /* Threads. */
00025 
00026 typedef int (*SceKernelThreadEntry)(SceSize args, void *argp);
00027 
00029 typedef struct SceKernelThreadOptParam {
00031     SceSize     size;
00033     SceUInt32       attr;
00034 } SceKernelThreadOptParam;
00035 
00039 typedef struct SceKernelThreadInfo {
00041     SceSize         size;
00043     SceUID          processId; //Needs confirmation
00045     char            name[32];
00047     SceUInt         attr;
00049     int             status;
00051     SceKernelThreadEntry entry;
00053     void            *stack;
00055     int             stackSize;
00057     int             initPriority;
00059     int             currentPriority;
00061     int             initCpuAffinityMask;
00063     int             currentCpuAffinityMask;
00065     int             currentCpuId;
00067     int             lastExecutedCpuId;
00069     int             waitType;
00071     SceUID          waitId;
00073     int             exitStatus;
00075     SceKernelSysClock runClocks;
00077     SceUInt     intrPreemptCount;
00079     SceUInt     threadPreemptCount;
00081     SceUInt     threadReleaseCount;
00083     SceUID      fNotifyCallback;
00085     int         reserved;
00086 } SceKernelThreadInfo;
00087 
00091 typedef struct SceKernelThreadRunStatus {
00092     SceSize        size;
00093     struct {
00094         SceUID processId;
00095         SceUID threadId;
00096         int    priority;
00097     } cpuInfo[4];
00098 } SceKernelThreadRunStatus;
00099 
00100 /* Sure there must be more than this, but haven't seen them */
00101 typedef enum Psp2ThreadStatus
00102 {
00103     PSP2_THREAD_RUNNING = 1,
00104     PSP2_THREAD_READY   = 2,
00105     PSP2_THREAD_WAITING = 4,
00106     PSP2_THREAD_SUSPEND = 8,
00107     PSP2_THREAD_STOPPED = 16,
00108     PSP2_THREAD_KILLED  = 32, /* Thread manager has killed the thread (stack overflow) */
00109 } Psp2ThreadStatus;
00110 
00130 SceUID sceKernelCreateThread(const char *name, SceKernelThreadEntry entry, int initPriority,
00131                              int stackSize, SceUInt attr, int cpuAffinityMask,
00132                              const SceKernelThreadOptParam *option);
00133 
00141 int sceKernelDeleteThread(SceUID thid);
00142 
00150 int sceKernelStartThread(SceUID thid, SceSize arglen, void *argp);
00151 
00157 int sceKernelExitThread(int status);
00158 
00164 int sceKernelExitDeleteThread(int status);
00165 
00175 int sceKernelWaitThreadEnd(SceUID thid, int *stat, SceUInt *timeout);
00176 
00186 int sceKernelWaitThreadEndCB(SceUID thid, int *stat, SceUInt *timeout);
00187 
00198 int sceKernelDelayThread(SceUInt delay);
00199 
00210 int sceKernelDelayThreadCB(SceUInt delay);
00211 
00220 int sceKernelChangeCurrentThreadAttr(int unknown, SceUInt attr);
00221 
00237 int sceKernelChangeThreadPriority(SceUID thid, int priority);
00238 
00246 int sceKernelRotateThreadReadyQueue(int priority);
00247 
00255 int sceKernelReleaseWaitThread(SceUID thid);
00256 
00262 int sceKernelGetThreadId(void);
00263 
00269 int sceKernelGetThreadCurrentPriority(void);
00270 
00278 int sceKernelGetThreadExitStatus(SceUID thid);
00279 
00285 int sceKernelCheckThreadStack(void);
00286 
00295 int sceKernelGetThreadStackFreeSize(SceUID thid);
00296 
00314 int sceKernelGetThreadInfo(SceUID thid, SceKernelThreadInfo *info);
00315 
00324 int sceKernelGetThreadRunStatus(SceUID thid, SceKernelThreadRunStatus *status);
00325 
00326 
00327 /* Semaphores. */
00328 
00330 typedef struct SceKernelSemaOptParam {
00332     SceSize     size;
00333 } SceKernelSemaOptParam;
00334 
00338 typedef struct SceKernelSemaInfo {
00340     SceSize         size;
00342     SceUID          semaId;
00344     char            name[32];
00346     SceUInt         attr;
00348     int             initCount;
00350     int             currentCount;
00352     int             maxCount;
00354     int             numWaitThreads;
00355 } SceKernelSemaInfo;
00356 
00373 SceUID sceKernelCreateSema(const char *name, SceUInt attr, int initVal, int maxVal, SceKernelSemaOptParam *option);
00374 
00381 int sceKernelDeleteSema(SceUID semaid);
00382 
00397 int sceKernelSignalSema(SceUID semaid, int signal);
00398 
00413 int sceKernelWaitSema(SceUID semaid, int signal, SceUInt *timeout);
00414 
00429 int sceKernelWaitSemaCB(SceUID semaid, int signal, SceUInt *timeout);
00430 
00439 int sceKernelPollSema(SceUID semaid, int signal);
00440 
00449 int sceKernelCancelSema(SceUID semaid, int setCount, int *numWaitThreads);
00450 
00459 int sceKernelGetSemaInfo(SceUID semaid, SceKernelSemaInfo *info);
00460 
00461 
00462 /* Mutexes. */
00463 
00465 typedef struct SceKernelMutexOptParam {
00467     SceSize     size;
00468     int             ceilingPriority;
00469 } SceKernelMutexOptParam;
00470 
00474 typedef struct SceKernelMutexInfo {
00476     SceSize         size;
00478     SceUID          mutexId;
00480     char            name[32];
00482     SceUInt         attr;
00484     int             initCount;
00486     int             currentCount;
00488     SceUID          currentOwnerId;
00490     int             numWaitThreads;
00491 } SceKernelMutexInfo;
00492 
00508 SceUID sceKernelCreateMutex(const char *name, SceUInt attr, int initCount, SceKernelMutexOptParam *option);
00509 
00516 int sceKernelDeleteMutex(SceUID mutexid);
00517 
00524 int sceKernelOpenMutex(const char *name);
00525 
00532 int sceKernelCloseMutex(SceUID mutexid);
00533 
00542 int sceKernelLockMutex(SceUID mutexid, int lockCount, unsigned int *timeout);
00543 
00552 int sceKernelLockMutexCB(SceUID mutexid, int lockCount, unsigned int *timeout);
00553 
00561 int sceKernelTryLockMutex(SceUID mutexid, int lockCount);
00562 
00570 int sceKernelUnlockMutex(SceUID mutexid, int unlockCount);
00571 
00580 int sceKernelCancelMutex(SceUID mutexid, int newCount, int *numWaitThreads);
00581 
00590 int sceKernelGetMutexInfo(SceUID mutexid, SceKernelMutexInfo info);
00591 
00592 
00593 /* Event flags. */
00594 
00596 typedef struct SceKernelEventFlagInfo {
00597     SceSize     size;
00598     SceUID          evfId; // Needs confirmation
00599     char        name[32];
00600     SceUInt     attr;
00601     SceUInt     initPattern;
00602     SceUInt     currentPattern;
00603     int         numWaitThreads;
00604 } SceKernelEventFlagInfo;
00605 
00606 typedef struct SceKernelEventFlagOptParam {
00607     SceSize         size;
00608 } SceKernelEventFlagOptParam;
00609 
00610 typedef struct SceKernelEventFlagOptParam SceKernelEventFlagOptParam;
00611 
00613 typedef enum Psp2EventFlagAttributes {
00615     PSP2_EVENT_WAITMULTIPLE = 0x200
00616 } Psp2EventFlagAttributes;
00617 
00619 typedef enum Psp2EventFlagWaitTypes {
00621     PSP2_EVENT_WAITAND = 0,
00623     PSP2_EVENT_WAITOR  = 1,
00625     PSP2_EVENT_WAITCLEAR = 0x20
00626 } Psp2EventFlagWaitTypes;
00627 
00643 SceUID sceKernelCreateEventFlag(const char *name, int attr, int bits, SceKernelEventFlagOptParam *opt);
00644 
00653 int sceKernelSetEventFlag(SceUID evid, unsigned int bits);
00654 
00663 int sceKernelClearEventFlag(SceUID evid, unsigned int bits);
00664 
00674 int sceKernelPollEventFlag(int evid, unsigned int bits, unsigned int wait, unsigned int *outBits);
00675 
00686 int sceKernelWaitEventFlag(int evid, unsigned int bits, unsigned int wait, unsigned int *outBits, SceUInt *timeout);
00687 
00698 int sceKernelWaitEventFlagCB(int evid, unsigned int bits, unsigned int wait, unsigned int *outBits, SceUInt *timeout);
00699 
00707 int sceKernelDeleteEventFlag(int evid);
00708 
00717 int sceKernelGetEventFlagInfo(SceUID event, SceKernelEventFlagInfo *info);
00718 
00719 
00720 /* Callbacks. */
00721 
00723 typedef int (*SceKernelCallbackFunction)(int notifyId, int notifyCount, int notifyArg, void *common);
00724 
00726 typedef struct SceKernelCallbackInfo {
00728     SceSize size;
00730     SceUID  callbackId; // Needs confirmation
00732     char    name[32];
00734     SceUID  threadId;
00736     SceKernelCallbackFunction callback;
00738     void    *common;
00740     int     notifyCount;
00742     int     notifyArg;
00743 } SceKernelCallbackInfo;
00744 
00760 int sceKernelCreateCallback(const char *name, unsigned int attr, SceKernelCallbackFunction func, void *arg);
00761 
00771 int sceKernelGetCallbackInfo(SceUID cb, SceKernelCallbackInfo *infop);
00772 
00780 int sceKernelDeleteCallback(SceUID cb);
00781 
00790 int sceKernelNotifyCallback(SceUID cb, int arg2);
00791 
00799 int sceKernelCancelCallback(SceUID cb);
00800 
00808 int sceKernelGetCallbackCount(SceUID cb);
00809 
00815 int sceKernelCheckCallback(void);
00816 
00817 
00818 /* Message pipes */
00819 
00831 SceUID sceKernelCreateMsgPipe(const char *name, int part, int attr, void *unk1, void *opt);
00832 
00840 int sceKernelDeleteMsgPipe(SceUID uid);
00841 
00854 int sceKernelSendMsgPipe(SceUID uid, void *message, unsigned int size, int unk1, void *unk2, unsigned int *timeout);
00855 
00868 int sceKernelSendMsgPipeCB(SceUID uid, void *message, unsigned int size, int unk1, void *unk2, unsigned int *timeout);
00869 
00881 int sceKernelTrySendMsgPipe(SceUID uid, void *message, unsigned int size, int unk1, void *unk2);
00882 
00895 int sceKernelReceiveMsgPipe(SceUID uid, void *message, unsigned int size, int unk1, void *unk2, unsigned int *timeout);
00896 
00909 int sceKernelReceiveMsgPipeCB(SceUID uid, void *message, unsigned int size, int unk1, void *unk2, unsigned int *timeout);
00910 
00922 int sceKernelTryReceiveMsgPipe(SceUID uid, void *message, unsigned int size, int unk1, void *unk2);
00923 
00933 int sceKernelCancelMsgPipe(SceUID uid, int *psend, int *precv);
00934 
00936 typedef struct SceKernelMppInfo {
00937     SceSize size;
00938     SceUID  mppId; // Needs confirmation
00939     char    name[32];
00940     SceUInt attr;
00941     int     bufSize;
00942     int     freeSize;
00943     int     numSendWaitThreads;
00944     int     numReceiveWaitThreads;
00945 } SceKernelMppInfo;
00946 
00955 int sceKernelGetMsgPipeInfo(SceUID uid, SceKernelMppInfo *info);
00956 
00957 
00958 /* Misc. */
00959 
00960 typedef struct SceKernelSystemInfo {
00961     SceSize   size;
00962     SceUInt32 activeCpuMask;
00963 
00964     struct {
00965         SceKernelSysClock idleClock;
00966         SceUInt32         comesOutOfIdleCount;
00967         SceUInt32         threadSwitchCount;
00968     } cpuInfo[4];
00969 } SceKernelSystemInfo;
00970 
00978 int sceKernelGetSystemInfo(SceKernelSystemInfo *info);
00979 
00980 /* Misc. */
00981 
00983 typedef enum SceKernelIdListType {
00984     SCE_KERNEL_TMID_Thread = 1,
00985     SCE_KERNEL_TMID_Semaphore = 2,
00986     SCE_KERNEL_TMID_EventFlag = 3,
00987     SCE_KERNEL_TMID_Mbox = 4,
00988     SCE_KERNEL_TMID_Vpl = 5,
00989     SCE_KERNEL_TMID_Fpl = 6,
00990     SCE_KERNEL_TMID_Mpipe = 7,
00991     SCE_KERNEL_TMID_Callback = 8,
00992     SCE_KERNEL_TMID_ThreadEventHandler = 9,
00993     SCE_KERNEL_TMID_Alarm = 10,
00994     SCE_KERNEL_TMID_VTimer = 11,
00995     SCE_KERNEL_TMID_SleepThread = 64,
00996     SCE_KERNEL_TMID_DelayThread = 65,
00997     SCE_KERNEL_TMID_SuspendThread = 66,
00998     SCE_KERNEL_TMID_DormantThread = 67,
00999 } SceKernelIdListType;
01000 
01008 SceKernelIdListType sceKernelGetThreadmgrUIDClass(SceUID uid);
01009 
01010 #ifdef __cplusplus
01011 }
01012 #endif
01013 
01014 #endif /* _PSP2_KERNEL_THREADMGR_H_ */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines