-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathpspthreadman.h
1836 lines (1646 loc) · 46.5 KB
/
pspthreadman.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* PSP Software Development Kit - https://github.com/pspdev
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* pspthreadman.h - Library imports for the kernel threading library.
*
* Copyright (c) 2005 Marcus R. Brown <[email protected]>
* Copyright (c) 2005 James Forshaw <[email protected]>
* Copyright (c) 2005 John Kelley <[email protected]>
* Copyright (c) 2005 Florin Sasu
*
*/
#ifndef __THREADMAN_H__
#define __THREADMAN_H__
#include <psptypes.h>
#include <pspkerneltypes.h>
/* Include for profile register definitions */
#include <pspdebug.h>
/* Note: Some of the structures, types, and definitions in this file were
extrapolated from symbolic debugging information found in the Japanese
version of Puzzle Bobble. */
/** @defgroup ThreadMan Thread Manager Library
* Library imports for the kernel threading library.
*/
#ifdef __cplusplus
extern "C" {
#endif
/** @addtogroup ThreadMan */
/**@{*/
/** 64-bit system clock type. */
typedef struct SceKernelSysClock {
SceUInt32 low;
SceUInt32 hi;
} SceKernelSysClock;
/** Attribute for threads. */
enum PspThreadAttributes
{
/** Enable VFPU access for the thread. */
PSP_THREAD_ATTR_VFPU = 0x00004000,
/** Start the thread in user mode (done automatically
if the thread creating it is in user mode). */
PSP_THREAD_ATTR_USER = 0x80000000,
/** Thread is part of the USB/WLAN API. */
PSP_THREAD_ATTR_USBWLAN = 0xa0000000,
/** Thread is part of the VSH API. */
PSP_THREAD_ATTR_VSH = 0xc0000000,
/** Allow using scratchpad memory for a thread, NOT USABLE ON V1.0 */
PSP_THREAD_ATTR_SCRATCH_SRAM = 0x00008000,
/** Disables filling the stack with 0xFF on creation */
PSP_THREAD_ATTR_NO_FILLSTACK = 0x00100000,
/** Clear the stack when the thread is deleted */
PSP_THREAD_ATTR_CLEAR_STACK = 0x00200000,
};
/* Maintained for compatibility with older versions of PSPSDK. */
#define THREAD_ATTR_VFPU PSP_THREAD_ATTR_VFPU
#define THREAD_ATTR_USER PSP_THREAD_ATTR_USER
/* Threads. */
typedef int (*SceKernelThreadEntry)(SceSize args, void *argp);
/** Additional options used when creating threads. */
typedef struct SceKernelThreadOptParam {
/** Size of the ::SceKernelThreadOptParam structure. */
SceSize size;
/** UID of the memory block (?) allocated for the thread's stack. */
SceUID stackMpid;
} SceKernelThreadOptParam;
/** Structure to hold the status information for a thread
* @see sceKernelReferThreadStatus
*/
typedef struct SceKernelThreadInfo {
/** Size of the structure */
SceSize size;
/** Nul terminated name of the thread */
char name[32];
/** Thread attributes */
SceUInt attr;
/** Thread status */
int status;
/** Thread entry point */
SceKernelThreadEntry entry;
/** Thread stack pointer */
void * stack;
/** Thread stack size */
int stackSize;
/** Pointer to the gp */
void * gpReg;
/** Initial priority */
int initPriority;
/** Current priority */
int currentPriority;
/** Wait type */
int waitType;
/** Wait id */
SceUID waitId;
/** Wakeup count */
int wakeupCount;
/** Exit status of the thread */
int exitStatus;
/** Number of clock cycles run */
SceKernelSysClock runClocks;
/** Interrupt preemption count */
SceUInt intrPreemptCount;
/** Thread preemption count */
SceUInt threadPreemptCount;
/** Release count */
SceUInt releaseCount;
} SceKernelThreadInfo;
/** Statistics about a running thread.
* @see sceKernelReferThreadRunStatus.
*/
typedef struct SceKernelThreadRunStatus {
SceSize size;
int status;
int currentPriority;
int waitType;
int waitId;
int wakeupCount;
SceKernelSysClock runClocks;
SceUInt intrPreemptCount;
SceUInt threadPreemptCount;
SceUInt releaseCount;
} SceKernelThreadRunStatus;
/* Sure there must be more than this, but haven't seen them */
enum PspThreadStatus
{
PSP_THREAD_RUNNING = 1,
PSP_THREAD_READY = 2,
PSP_THREAD_WAITING = 4,
PSP_THREAD_SUSPEND = 8,
PSP_THREAD_STOPPED = 16,
PSP_THREAD_KILLED = 32, /* Thread manager has killed the thread (stack overflow) */
};
/**
* Create a thread
*
* @par Example:
* @code
* SceUID thid;
* thid = sceKernelCreateThread("my_thread", threadFunc, 0x18, 0x10000, 0, NULL);
* @endcode
*
* @param name - An arbitrary thread name.
* @param entry - The thread function to run when started.
* @param initPriority - The initial priority of the thread. Less if higher priority.
* @param stackSize - The size of the initial stack.
* @param attr - The thread attributes, zero or more of ::PspThreadAttributes.
* @param option - Additional options specified by ::SceKernelThreadOptParam.
* @return UID of the created thread, or an error code.
*/
SceUID sceKernelCreateThread(const char *name, SceKernelThreadEntry entry, int initPriority,
int stackSize, SceUInt attr, SceKernelThreadOptParam *option);
/**
* Delate a thread
*
* @param thid - UID of the thread to be deleted.
*
* @return < 0 on error.
*/
int sceKernelDeleteThread(SceUID thid);
/**
* Start a created thread
*
* @param thid - Thread id from sceKernelCreateThread
* @param arglen - Length of the data pointed to by argp, in bytes
* @param argp - Pointer to the arguments.
*/
int sceKernelStartThread(SceUID thid, SceSize arglen, void *argp);
/**
* Exit a thread
*
* @param status - Exit status.
*/
int sceKernelExitThread(int status);
/**
* Exit a thread and delete itself.
*
* @param status - Exit status
*/
int sceKernelExitDeleteThread(int status);
/**
* Terminate a thread.
*
* @param thid - UID of the thread to terminate.
*
* @return Success if >= 0, an error if < 0.
*/
int sceKernelTerminateThread(SceUID thid);
/**
* Terminate and delete a thread.
*
* @param thid - UID of the thread to terminate and delete.
*
* @return Success if >= 0, an error if < 0.
*/
int sceKernelTerminateDeleteThread(SceUID thid);
/**
* Suspend the dispatch thread
*
* @return The current state of the dispatch thread, < 0 on error
*/
int sceKernelSuspendDispatchThread(void);
/**
* Resume the dispatch thread
*
* @param state - The state of the dispatch thread
* (from ::sceKernelSuspendDispatchThread)
*
* @return 0 on success, < 0 on error
*/
int sceKernelResumeDispatchThread(int state);
/**
* Sleep thread
*
* @return < 0 on error.
*/
int sceKernelSleepThread(void);
/**
* Sleep thread but service any callbacks as necessary
*
* @par Example:
* @code
* // Once all callbacks have been setup call this function
* sceKernelSleepThreadCB();
* @endcode
*/
int sceKernelSleepThreadCB(void);
/**
* Wake a thread previously put into the sleep state.
*
* @param thid - UID of the thread to wake.
*
* @return Success if >= 0, an error if < 0.
*/
int sceKernelWakeupThread(SceUID thid);
/**
* Cancel a thread that was to be woken with ::sceKernelWakeupThread.
*
* @param thid - UID of the thread to cancel.
*
* @return Success if >= 0, an error if < 0.
*/
int sceKernelCancelWakeupThread(SceUID thid);
/**
* Suspend a thread.
*
* @param thid - UID of the thread to suspend.
*
* @return Success if >= 0, an error if < 0.
*/
int sceKernelSuspendThread(SceUID thid);
/**
* Resume a thread previously put into a suspended state with ::sceKernelSuspendThread.
*
* @param thid - UID of the thread to resume.
*
* @return Success if >= 0, an error if < 0.
*/
int sceKernelResumeThread(SceUID thid);
/**
* Wait until a thread has ended.
*
* @param thid - Id of the thread to wait for.
* @param timeout - Timeout in microseconds (assumed).
*
* @return < 0 on error.
*/
int sceKernelWaitThreadEnd(SceUID thid, SceUInt *timeout);
/**
* Wait until a thread has ended and handle callbacks if necessary.
*
* @param thid - Id of the thread to wait for.
* @param timeout - Timeout in microseconds (assumed).
*
* @return < 0 on error.
*/
int sceKernelWaitThreadEndCB(SceUID thid, SceUInt *timeout);
/**
* Delay the current thread by a specified number of microseconds
*
* @param delay - Delay in microseconds.
*
* @par Example:
* @code
* sceKernelDelayThread(1000000); // Delay for a second
* @endcode
*/
int sceKernelDelayThread(SceUInt delay);
/**
* Delay the current thread by a specified number of microseconds and handle any callbacks.
*
* @param delay - Delay in microseconds.
*
* @par Example:
* @code
* sceKernelDelayThread(1000000); // Delay for a second
* @endcode
*/
int sceKernelDelayThreadCB(SceUInt delay);
/**
* Delay the current thread by a specified number of sysclocks
*
* @param delay - Delay in sysclocks
*
* @return 0 on success, < 0 on error
*/
int sceKernelDelaySysClockThread(SceKernelSysClock *delay);
/**
* Delay the current thread by a specified number of sysclocks handling callbacks
*
* @param delay - Delay in sysclocks
*
* @return 0 on success, < 0 on error
*
*/
int sceKernelDelaySysClockThreadCB(SceKernelSysClock *delay);
/**
* Modify the attributes of the current thread.
*
* @param unknown - Set to 0.
* @param attr - The thread attributes to modify. One of ::PspThreadAttributes.
*
* @return < 0 on error.
*/
int sceKernelChangeCurrentThreadAttr(int unknown, SceUInt attr);
/**
* Change the threads current priority.
*
* @param thid - The ID of the thread (from sceKernelCreateThread or sceKernelGetThreadId)
* @param priority - The new priority (the lower the number the higher the priority)
*
* @par Example:
* @code
* int thid = sceKernelGetThreadId();
* // Change priority of current thread to 16
* sceKernelChangeThreadPriority(thid, 16);
* @endcode
*
* @return 0 if successful, otherwise the error code.
*/
int sceKernelChangeThreadPriority(SceUID thid, int priority);
/**
* Rotate thread ready queue at a set priority
*
* @param priority - The priority of the queue
*
* @return 0 on success, < 0 on error.
*/
int sceKernelRotateThreadReadyQueue(int priority);
/**
* Release a thread in the wait state.
*
* @param thid - The UID of the thread.
*
* @return 0 on success, < 0 on error
*/
int sceKernelReleaseWaitThread(SceUID thid);
/**
* Get the current thread Id
*
* @return The thread id of the calling thread.
*/
int sceKernelGetThreadId(void);
/**
* Get the current priority of the thread you are in.
*
* @return The current thread priority
*/
int sceKernelGetThreadCurrentPriority(void);
/**
* Get the exit status of a thread.
*
* @param thid - The UID of the thread to check.
*
* @return The exit status
*/
int sceKernelGetThreadExitStatus(SceUID thid);
/**
* Check the thread stack?
*
* @return Unknown.
*/
int sceKernelCheckThreadStack(void);
/**
* Get the free stack size for a thread.
*
* @param thid - The thread ID. Seem to take current thread
* if set to 0.
*
* @return The free size.
*/
int sceKernelGetThreadStackFreeSize(SceUID thid);
/**
* Get the status information for the specified thread.
*
* @param thid - Id of the thread to get status
* @param info - Pointer to the info structure to receive the data.
* Note: The structures size field should be set to
* sizeof(SceKernelThreadInfo) before calling this function.
*
* @par Example:
* @code
* SceKernelThreadInfo status;
* status.size = sizeof(SceKernelThreadInfo);
* if(sceKernelReferThreadStatus(thid, &status) == 0)
* { Do something... }
* @endcode
* @return 0 if successful, otherwise the error code.
*/
int sceKernelReferThreadStatus(SceUID thid, SceKernelThreadInfo *info);
/**
* Retrive the runtime status of a thread.
*
* @param thid - UID of the thread to retrive status.
* @param status - Pointer to a ::SceKernelThreadRunStatus struct to receive the runtime status.
*
* @return 0 if successful, otherwise the error code.
*/
int sceKernelReferThreadRunStatus(SceUID thid, SceKernelThreadRunStatus *status);
/* Semaphores. */
/** Additional options used when creating semaphores. */
typedef struct SceKernelSemaOptParam {
/** Size of the ::SceKernelSemaOptParam structure. */
SceSize size;
} SceKernelSemaOptParam;
/** Current state of a semaphore.
* @see sceKernelReferSemaStatus.
*/
typedef struct SceKernelSemaInfo {
/** Size of the ::SceKernelSemaInfo structure. */
SceSize size;
/** NUL-terminated name of the semaphore. */
char name[32];
/** Attributes. */
SceUInt attr;
/** The initial count the semaphore was created with. */
int initCount;
/** The current count. */
int currentCount;
/** The maximum count. */
int maxCount;
/** The number of threads waiting on the semaphore. */
int numWaitThreads;
} SceKernelSemaInfo;
/**
* Creates a new semaphore
*
* @par Example:
* @code
* int semaid;
* semaid = sceKernelCreateSema("MyMutex", 0, 1, 1, 0);
* @endcode
*
* @param name - Specifies the name of the sema
* @param attr - Sema attribute flags (normally set to 0)
* @param initVal - Sema initial value
* @param maxVal - Sema maximum value
* @param option - Sema options (normally set to 0)
* @return A semaphore id
*/
SceUID sceKernelCreateSema(const char *name, SceUInt attr, int initVal, int maxVal, SceKernelSemaOptParam *option);
/**
* Destroy a semaphore
*
* @param semaid - The semaid returned from a previous create call.
* @return Returns the value 0 if its succesful otherwise -1
*/
int sceKernelDeleteSema(SceUID semaid);
/**
* Send a signal to a semaphore
*
* @par Example:
* @code
* // Signal the sema
* sceKernelSignalSema(semaid, 1);
* @endcode
*
* @param semaid - The sema id returned from sceKernelCreateSema
* @param signal - The amount to signal the sema (i.e. if 2 then increment the sema by 2)
*
* @return < 0 On error.
*/
int sceKernelSignalSema(SceUID semaid, int signal);
/**
* Lock a semaphore
*
* @par Example:
* @code
* sceKernelWaitSema(semaid, 1, 0);
* @endcode
*
* @param semaid - The sema id returned from sceKernelCreateSema
* @param signal - The value to wait for (i.e. if 1 then wait till reaches a signal state of 1)
* @param timeout - Timeout in microseconds (assumed).
*
* @return < 0 on error.
*/
int sceKernelWaitSema(SceUID semaid, int signal, SceUInt *timeout);
/**
* Lock a semaphore a handle callbacks if necessary.
*
* @par Example:
* @code
* sceKernelWaitSemaCB(semaid, 1, 0);
* @endcode
*
* @param semaid - The sema id returned from sceKernelCreateSema
* @param signal - The value to wait for (i.e. if 1 then wait till reaches a signal state of 1)
* @param timeout - Timeout in microseconds (assumed).
*
* @return < 0 on error.
*/
int sceKernelWaitSemaCB(SceUID semaid, int signal, SceUInt *timeout);
/**
* Poll a sempahore.
*
* @param semaid - UID of the semaphore to poll.
* @param signal - The value to test for.
*
* @return < 0 on error.
*/
int sceKernelPollSema(SceUID semaid, int signal);
/**
* Retrieve information about a semaphore.
*
* @param semaid - UID of the semaphore to retrieve info for.
* @param info - Pointer to a ::SceKernelSemaInfo struct to receive the info.
*
* @return < 0 on error.
*/
int sceKernelReferSemaStatus(SceUID semaid, SceKernelSemaInfo *info);
/** Struct as workarea for lightweight mutex */
typedef struct {
/** Count */
int lockLevel;
/** Locking thread */
SceUID lockThread;
/** Attribute */
int attr;
/** Number of waiting threads */
int numWaitThreads;
/** UID */
SceUID uid;
/** Padding */
int pad[3];
} SceLwMutexWorkarea;
/**
* Create a lightweight mutex
*
* @param workarea - The pointer to the workarea
* @param name - The name of the lightweight mutex
* @param attr -
* @param initialCount - THe inital value of the mutex
* @param optionsPTr - Other optioons for mutex
*
* @return 0 on success, otherwise one of ::PspKernelErrorCodes
*/
int sceKernelCreateLwMutex(SceLwMutexWorkarea *workarea, const char *name, u32 attr, int initialCount, u32 *optionsPtr);
/**
* Delete a lightweight mutex
*
* @param workarea - The pointer to the workarea
*
* @return 0 on success, otherwise one of ::PspKernelErrorCodes
*/
int sceKernelDeleteLwMutex(SceLwMutexWorkarea *workarea);
/**
* Try to lock a lightweight mutex
*
* @param workarea - The pointer to the workarea
* @param lockCount - value of increase the lock counter
*
* @return 0 on success, otherwise one of ::PspKernelErrorCodes
*/
int sceKernelTryLockLwMutex(SceLwMutexWorkarea *workarea, int lockCount);
/**
* Lock a lightweight mutex
*
* @param workarea - The pointer to the workarea
* @param lockCount - value of increase the lock counter
* @param pTimeout - The pointer for timeout waiting
*
* @return 0 on success, otherwise one of ::PspKernelErrorCodes
*/
int sceKernelLockLwMutex(SceLwMutexWorkarea *workarea, int lockCount, unsigned int *pTimeout);
/**
* Lock a lightweight mutex
*
* @param workarea - The pointer to the workarea
* @param name - The name of the lightweight mutex
* @param lockCount - value of decrease the lock counter
*
* @return 0 on success, otherwise one of ::PspKernelErrorCodes
*/
int sceKernelUnlockLwMutex(SceLwMutexWorkarea *workarea, int lockCount);
/* Event flags. */
/** Structure to hold the event flag information */
typedef struct SceKernelEventFlagInfo {
SceSize size;
char name[32];
SceUInt attr;
SceUInt initPattern;
SceUInt currentPattern;
int numWaitThreads;
} SceKernelEventFlagInfo;
struct SceKernelEventFlagOptParam {
SceSize size;
};
typedef struct SceKernelEventFlagOptParam SceKernelEventFlagOptParam;
/** Event flag creation attributes */
enum PspEventFlagAttributes
{
/** Allow the event flag to be waited upon by multiple threads */
PSP_EVENT_WAITMULTIPLE = 0x200
};
/** Event flag wait types */
enum PspEventFlagWaitTypes
{
/** Wait for all bits in the pattern to be set */
PSP_EVENT_WAITAND = 0,
/** Wait for one or more bits in the pattern to be set */
PSP_EVENT_WAITOR = 1,
/** Clear the wait pattern when it matches */
PSP_EVENT_WAITCLEAR = 0x20
};
/**
* Create an event flag.
*
* @param name - The name of the event flag.
* @param attr - Attributes from ::PspEventFlagAttributes
* @param bits - Initial bit pattern.
* @param opt - Options, set to NULL
* @return < 0 on error. >= 0 event flag id.
*
* @par Example:
* @code
* int evid;
* evid = sceKernelCreateEventFlag("wait_event", 0, 0, 0);
* @endcode
*/
SceUID sceKernelCreateEventFlag(const char *name, int attr, int bits, SceKernelEventFlagOptParam *opt);
/**
* Set an event flag bit pattern.
*
* @param evid - The event id returned by sceKernelCreateEventFlag.
* @param bits - The bit pattern to set.
*
* @return < 0 On error
*/
int sceKernelSetEventFlag(SceUID evid, u32 bits);
/**
* Clear a event flag bit pattern
*
* @param evid - The event id returned by ::sceKernelCreateEventFlag
* @param bits - The bits to clean
*
* @return < 0 on Error
*/
int sceKernelClearEventFlag(SceUID evid, u32 bits);
/**
* Poll an event flag for a given bit pattern.
*
* @param evid - The event id returned by sceKernelCreateEventFlag.
* @param bits - The bit pattern to poll for.
* @param wait - Wait type, one or more of ::PspEventFlagWaitTypes or'ed together
* @param outBits - The bit pattern that was matched.
* @return < 0 On error
*/
int sceKernelPollEventFlag(int evid, u32 bits, u32 wait, u32 *outBits);
/**
* Wait for an event flag for a given bit pattern.
*
* @param evid - The event id returned by sceKernelCreateEventFlag.
* @param bits - The bit pattern to poll for.
* @param wait - Wait type, one or more of ::PspEventFlagWaitTypes or'ed together
* @param outBits - The bit pattern that was matched.
* @param timeout - Timeout in microseconds
* @return < 0 On error
*/
int sceKernelWaitEventFlag(int evid, u32 bits, u32 wait, u32 *outBits, SceUInt *timeout);
/**
* Wait for an event flag for a given bit pattern with callback.
*
* @param evid - The event id returned by sceKernelCreateEventFlag.
* @param bits - The bit pattern to poll for.
* @param wait - Wait type, one or more of ::PspEventFlagWaitTypes or'ed together
* @param outBits - The bit pattern that was matched.
* @param timeout - Timeout in microseconds
* @return < 0 On error
*/
int sceKernelWaitEventFlagCB(int evid, u32 bits, u32 wait, u32 *outBits, SceUInt *timeout);
/**
* Delete an event flag
*
* @param evid - The event id returned by sceKernelCreateEventFlag.
*
* @return < 0 On error
*/
int sceKernelDeleteEventFlag(int evid);
/**
* Get the status of an event flag.
*
* @param event - The UID of the event.
* @param status - A pointer to a ::SceKernelEventFlagInfo structure.
*
* @return < 0 on error.
*/
int sceKernelReferEventFlagStatus(SceUID event, SceKernelEventFlagInfo *status);
/* Message boxes. */
/** Additional options used when creating messageboxes. */
typedef struct SceKernelMbxOptParam {
/** Size of the ::SceKernelMbxOptParam structure. */
SceSize size;
} SceKernelMbxOptParam;
/** Current state of a messagebox.
* @see sceKernelReferMbxStatus.
*/
typedef struct SceKernelMbxInfo {
/** Size of the ::SceKernelMbxInfo structure. */
SceSize size;
/** NUL-terminated name of the messagebox. */
char name[32];
/** Attributes. */
SceUInt attr;
/** The number of threads waiting on the messagebox. */
int numWaitThreads;
/** Number of messages currently in the messagebox. */
int numMessages;
/** The message currently at the head of the queue. */
void *firstMessage;
} SceKernelMbxInfo;
/**
* Header for a message box packet
*/
typedef struct SceKernelMsgPacket {
/** Pointer to next msg (used by the kernel) */
struct SceKernelMsgPacket *next;
/** Priority ? */
SceUChar msgPriority;
SceUChar dummy[3];
/** After this can be any user defined data */
} SceKernelMsgPacket;
/**
* Creates a new messagebox
*
* @par Example:
* @code
* int mbxid;
* mbxid = sceKernelCreateMbx("MyMessagebox", 0, NULL);
* @endcode
*
* @param name - Specifies the name of the mbx
* @param attr - Mbx attribute flags (normally set to 0)
* @param option - Mbx options (normally set to NULL)
* @return A messagebox id
*/
SceUID sceKernelCreateMbx(const char *name, SceUInt attr, SceKernelMbxOptParam *option);
/**
* Destroy a messagebox
*
* @param mbxid - The mbxid returned from a previous create call.
* @return Returns the value 0 if its succesful otherwise an error code
*/
int sceKernelDeleteMbx(SceUID mbxid);
/**
* Send a message to a messagebox
*
* @par Example:
* @code
* struct MyMessage {
* SceKernelMsgPacket header;
* char text[8];
* };
*
* struct MyMessage msg = { {0}, "Hello" };
* // Send the message
* sceKernelSendMbx(mbxid, (void*) &msg);
* @endcode
*
* @param mbxid - The mbx id returned from sceKernelCreateMbx
* @param message - A message to be forwarded to the receiver.
* The start of the message should be the
* ::SceKernelMsgPacket structure, the rest
*
* @return < 0 On error.
*/
int sceKernelSendMbx(SceUID mbxid, void *message);
/**
* Wait for a message to arrive in a messagebox
*
* @par Example:
* @code
* void *msg;
* sceKernelReceiveMbx(mbxid, &msg, NULL);
* @endcode
*
* @param mbxid - The mbx id returned from sceKernelCreateMbx
* @param pmessage - A pointer to where a pointer to the
* received message should be stored
* @param timeout - Timeout in microseconds
*
* @return < 0 on error.
*/
int sceKernelReceiveMbx(SceUID mbxid, void **pmessage, SceUInt *timeout);
/**
* Wait for a message to arrive in a messagebox and handle callbacks if necessary.
*
* @par Example:
* @code
* void *msg;
* sceKernelReceiveMbxCB(mbxid, &msg, NULL);
* @endcode
*
* @param mbxid - The mbx id returned from sceKernelCreateMbx
* @param pmessage - A pointer to where a pointer to the
* received message should be stored
* @param timeout - Timeout in microseconds
*
* @return < 0 on error.
*/
int sceKernelReceiveMbxCB(SceUID mbxid, void **pmessage, SceUInt *timeout);
/**
* Check if a message has arrived in a messagebox
*
* @par Example:
* @code
* void *msg;
* sceKernelPollMbx(mbxid, &msg);
* @endcode
*
* @param mbxid - The mbx id returned from sceKernelCreateMbx
* @param pmessage - A pointer to where a pointer to the
* received message should be stored
*
* @return < 0 on error (SCE_KERNEL_ERROR_MBOX_NOMSG if the mbx is empty).
*/
int sceKernelPollMbx(SceUID mbxid, void **pmessage);
/**
* Abort all wait operations on a messagebox
*
* @par Example:
* @code
* sceKernelCancelReceiveMbx(mbxid, NULL);
* @endcode
*
* @param mbxid - The mbx id returned from sceKernelCreateMbx
* @param pnum - A pointer to where the number of threads which
* were waiting on the mbx should be stored (NULL
* if you don't care)
*
* @return < 0 on error
*/
int sceKernelCancelReceiveMbx(SceUID mbxid, int *pnum);
/**
* Retrieve information about a messagebox.
*
* @param mbxid - UID of the messagebox to retrieve info for.
* @param info - Pointer to a ::SceKernelMbxInfo struct to receive the info.
*
* @return < 0 on error.
*/
int sceKernelReferMbxStatus(SceUID mbxid, SceKernelMbxInfo *info);
/* Alarms. */
/** Prototype for alarm handlers. */
typedef SceUInt (*SceKernelAlarmHandler)(void *common);
/** Struct containing alarm info */
typedef struct SceKernelAlarmInfo {
/** Size of the structure (should be set before calling
* :: sceKernelReferAlarmStatus */
SceSize size;
/* The current schedule */
SceKernelSysClock schedule;
/** Pointer to the alarm handler */
SceKernelAlarmHandler handler;
/** Common pointer argument */
void * common;
} SceKernelAlarmInfo;
/**
* Set an alarm.
* @param clock - The number of micro seconds till the alarm occurrs.
* @param handler - Pointer to a ::SceKernelAlarmHandler
* @param common - Common pointer for the alarm handler
*
* @return A UID representing the created alarm, < 0 on error.
*/
SceUID sceKernelSetAlarm(SceUInt clock, SceKernelAlarmHandler handler, void *common);
/**
* Set an alarm using a ::SceKernelSysClock structure for the time
*
* @param clock - Pointer to a ::SceKernelSysClock structure
* @param handler - Pointer to a ::SceKernelAlarmHandler
* @param common - Common pointer for the alarm handler.
*
* @return A UID representing the created alarm, < 0 on error.
*/
SceUID sceKernelSetSysClockAlarm(SceKernelSysClock *clock, SceKernelAlarmHandler handler, void *common);
/**
* Cancel a pending alarm.
*
* @param alarmid - UID of the alarm to cancel.
*