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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
|
#ifndef _PSP2_KERNEL_THREADMGR_H_
#define _PSP2_KERNEL_THREADMGR_H_
#include <psp2common/kernel/threadmgr.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Threads. */
/** Additional options used when creating threads. */
typedef struct _SceKernelThreadOptParam {
/** Size of the ::SceKernelThreadOptParam structure. */
SceSize size;
SceUInt32 attr;
} SceKernelThreadOptParam;
/** Structure to hold the status information for a thread
* @see sceKernelGetThreadInfo
*/
typedef struct _SceKernelThreadInfo {
/** Size of the structure */
SceSize size;
SceUID processId;
char name[SCE_UID_NAMELEN+1];
SceUInt32 attr;
SceUInt32 status;
SceKernelThreadEntry entry;
void *pStack;
SceSize stackSize;
SceInt32 initPriority;
SceInt32 currentPriority;
SceInt32 initCpuAffinityMask;
SceInt32 currentCpuAffinityMask;
SceInt32 currentCpuId;
SceInt32 lastExecutedCpuId;
SceUInt32 waitType;
SceUID waitId;
SceInt32 exitStatus;
SceKernelSysClock runClocks;
SceUInt32 intrPreemptCount;
SceUInt32 threadPreemptCount;
SceUInt32 threadReleaseCount;
SceInt32 changeCpuCount;
/** Function notify callback UID */
SceInt32 fNotifyCallback;
SceInt32 reserved;
} SceKernelThreadInfo;
/** Statistics about a running thread.
* @see sceKernelGetThreadRunStatus.
*/
typedef struct SceKernelThreadRunStatus {
SceSize size;
struct {
SceUID processId;
SceUID threadId;
int priority;
} cpuInfo[SCE_KERNEL_MAX_CPU];
} SceKernelThreadRunStatus;
/* Sure there must be more than this, but haven't seen them */
typedef enum SceThreadStatus {
SCE_THREAD_RUNNING = 1,
SCE_THREAD_READY = 2,
SCE_THREAD_WAITING = 4,
SCE_THREAD_SUSPEND = 8,
SCE_THREAD_STOPPED = 16,
SCE_THREAD_KILLED = 32, /* Thread manager has killed the thread (stack overflow) */
} SceThreadStatus;
/**
* Create a thread
*
* @param pName - 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 ::SceThreadAttributes.
* @param cpuAffinityMask - The CPU affinity mask
* @param pOptParam - Additional options specified by ::SceKernelThreadOptParam.
* @return UID of the created thread, or an error code.
*/
SceUID sceKernelCreateThread(
const char *pName,
SceKernelThreadEntry entry,
SceInt32 initPriority,
SceSize stackSize,
SceUInt32 attr,
SceInt32 cpuAffinityMask,
const SceKernelThreadOptParam *pOptParam);
/**
* Delate a thread
*
* @param threadId - UID of the thread to be deleted.
*
* @return < 0 on error.
*/
SceInt32 sceKernelDeleteThread(SceUID threadId);
/**
* Start a created thread
*
* @param threadId - Thread id from ::sceKernelCreateThread
* @param argSize - Length of the data pointed to by argp, in bytes
* @param pArgBlock - Pointer to the arguments.
*/
SceInt32 sceKernelStartThread(SceUID threadId, SceSize argSize, const void *pArgBlock);
/**
* Exit a thread
*
* @param exitStatus - Exit status.
*/
SceInt32 sceKernelExitThread(SceInt32 exitStatus);
/**
* Exit a thread and delete itself.
*
* @param exitStatus - Exit status
*/
SceInt32 sceKernelExitDeleteThread(SceInt32 exitStatus);
/**
* Wait until a thread has ended.
*
* @param threadId - Id of the thread to wait for.
* @param pExitStatus - Exit status.
* @param pTimeout - Timeout in microseconds.
*
* @return < 0 on error.
*/
SceInt32 sceKernelWaitThreadEnd(SceUID threadId, SceInt32 *pExitStatus, SceUInt32 *pTimeout);
/**
* Wait until a thread has ended and handle callbacks if necessary.
*
* @param threadId - Id of the thread to wait for.
* @param pExitStatus - Exit status.
* @param pTimeout - Timeout in microseconds.
*
* @return < 0 on error.
*/
SceInt32 sceKernelWaitThreadEndCB(SceUID threadId, SceInt32 *pExitStatus, SceUInt32 *pTimeout);
/**
* Delay the current thread by a specified number of microseconds
*
* @param usec - Delay in microseconds.
*
* @par Example:
* @code
* sceKernelDelayThread(1000000); // Delay for a second
* @endcode
*/
SceInt32 sceKernelDelayThread(SceUInt32 usec);
/**
* Delay the current thread by a specified number of microseconds and handle any callbacks.
*
* @param usec - Delay in microseconds.
*
* @par Example:
* @code
* sceKernelDelayThread(1000000); // Delay for a second
* @endcode
*/
SceInt32 sceKernelDelayThreadCB(SceUInt32 usec);
/**
* Modify the attributes of the current thread.
*
* @param clearAttr - Bits to clear
* @param setAttr - Bits to set
*
* @return < 0 on error.
*/
SceInt32 sceKernelChangeCurrentThreadAttr(SceUInt32 clearAttr, SceUInt32 setAttr);
/**
* Change the threads current priority.
*
* @param threadId - 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 threadId = sceKernelGetThreadId();
* // Change priority of current thread to 16
* sceKernelChangeThreadPriority(thid, 16);
* @endcode
*
* @return 0 if successful, otherwise the error code.
*/
SceInt32 sceKernelChangeThreadPriority(SceUID threadId, SceInt32 priority);
/**
* Change the threads current priority.
*
* @param threadId - The ID of the thread (from ::sceKernelCreateThread or ::sceKernelGetThreadId)
* @param priority - The new priority (the lower the number the higher the priority)
*
* @return old priority or error code
*/
SceInt32 sceKernelChangeThreadPriority2(SceUID threadId, SceInt32 priority);
/**
* Get the current thread Id
*
* @return The thread id of the calling thread.
*/
SceUID sceKernelGetThreadId(void);
/**
* Get the current priority of the thread you are in.
*
* @return The current thread priority
*/
SceInt32 sceKernelGetThreadCurrentPriority(void);
/**
* Get the exit status of a thread.
*
* @param threadId - The UID of the thread to check.
* @param pExitStatus - pointer to area to store result
*
* @return 0 or <0 on error
*/
SceInt32 sceKernelGetThreadExitStatus(SceUID threadId, SceInt32 *pExitStatus);
/**
* Check remaining thread stack size
*
* @return Stack size at the time of function call
*/
SceSize sceKernelCheckThreadStack(void);
/**
* Get the free stack size for a thread.
*
* @param threadId - The thread ID
*
* @return The free size.
*/
SceSize sceKernelGetThreadStackFreeSize(SceUID threadId);
/**
* Get the status information for the specified thread.
*
* @param threadId - Id of the thread to get status
* @param pInfo - 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(sceKernelGetThreadInfo(thid, &status) == 0)
* { Do something... }
* @endcode
* @return 0 if successful, otherwise the error code.
*/
SceInt32 sceKernelGetThreadInfo(SceUID threadId, SceKernelThreadInfo *pInfo);
/**
* Retrive the runtime status of a thread.
*
* @param pStatus - Pointer to a ::SceKernelThreadRunStatus struct to receive the runtime status.
*
* @return 0 if successful, otherwise the error code.
*/
SceInt32 sceKernelGetThreadRunStatus(SceKernelThreadRunStatus *pStatus);
typedef SceInt32 (*SceKernelChangeStackFunction)(void *pArg);
SceInt32 sceKernelCallWithChangeStack(
void *pBase,
SceSize size,
SceKernelChangeStackFunction changeStackFunc,
void *pCommon);
SceInt32 sceKernelChangeThreadCpuAffinityMask(SceUID threadId, SceInt32 cpuAffinityMask);
SceInt32 sceKernelGetThreadCpuAffinityMask(SceUID threadId);
/**
* Get the process ID of the current thread.
*
* @return process ID of the current thread
*/
SceUID sceKernelGetProcessId(void);
SceInt32 sceKernelCheckWaitableStatus(void);
SceInt32 sceKernelChangeThreadVfpException(SceInt32 clearMask, SceInt32 setMask);
SceInt32 sceKernelGetCurrentThreadVfpException(void);
/* Semaphores. */
/** Additional options used when creating semaphores. */
typedef struct SceKernelSemaOptParam {
/** Size of the ::SceKernelSemaOptParam structure. */
SceSize size;
} SceKernelSemaOptParam;
/** Current state of a semaphore.
* @see sceKernelGetSemaInfo.
*/
typedef struct SceKernelSemaInfo {
/** Size of the ::SceKernelSemaInfo structure. */
SceSize size;
/** The UID of the semaphore */
SceUID semaId;
/** NUL-terminated name of the semaphore. */
char name[SCE_UID_NAMELEN + 1];
/** 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 initCount - Sema initial value
* @param maxCount - Sema maximum value
* @param pOptParam - Sema options (normally set to 0)
* @return A semaphore id
*/
SceUID sceKernelCreateSema(
const char *name,
SceUInt32 attr,
SceInt32 initCount,
SceInt32 maxCount,
SceKernelSemaOptParam *pOptParam);
/**
* Destroy a semaphore
*
* @param semaId - The semaid returned from a previous create call.
* @return Returns the value 0 if it's successful, otherwise negative
*/
SceInt32 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 signalCount - The amount to signal the sema (i.e. if 2 then increment the sema by 2)
*
* @return < 0 On error.
*/
SceInt32 sceKernelSignalSema(SceUID semaId, SceInt32 signalCount);
/**
* Lock a semaphore
*
* @par Example:
* @code
* sceKernelWaitSema(semaId, 1, 0);
* @endcode
*
* @param semaId - The sema id returned from ::sceKernelCreateSema
* @param needCount - The value to wait for (i.e. if 1 then wait till reaches a signal state of 1)
* @param pTimeout - Timeout in microseconds.
*
* @return < 0 on error.
*/
SceInt32 sceKernelWaitSema(SceUID semaId, SceInt32 needCount, SceUInt32 *pTimeout);
/**
* Lock a semaphore and handle callbacks if necessary.
*
* @par Example:
* @code
* sceKernelWaitSemaCB(semaId, 1, 0);
* @endcode
*
* @param semaId - The sema id returned from ::sceKernelCreateSema
* @param needCount - The value to wait for (i.e. if 1 then wait till reaches a signal state of 1)
* @param pTimeout - Timeout in microseconds.
*
* @return < 0 on error.
*/
SceInt32 sceKernelWaitSemaCB(SceUID semaId, SceInt32 needCount, SceUInt32 *pTimeout);
/**
* Poll a semaphore.
*
* @param semaId - UID of the semaphore to poll.
* @param needCount - The value to test for.
*
* @return < 0 on error.
*/
SceInt32 sceKernelPollSema(SceUID semaId, SceInt32 needCount);
/**
* Cancels a semaphore
*
* @param semaId - The sema id returned from ::sceKernelCreateSema
* @param setCount - The new lock count of the semaphore
* @param pNumWaitThreads - Number of threads waiting for the semaphore
* @return < 0 On error.
*/
SceInt32 sceKernelCancelSema(SceUID semaId, SceInt32 setCount, SceUInt32 *pNumWaitThreads);
/**
* Retrieve information about a semaphore.
*
* @param semaId - UID of the semaphore to retrieve info for.
* @param pInfo - Pointer to a ::SceKernelSemaInfo struct to receive the info.
*
* @return < 0 on error.
*/
SceInt32 sceKernelGetSemaInfo(SceUID semaId, SceKernelSemaInfo *pInfo);
SceUID sceKernelOpenSema(const char *pName);
SceInt32 sceKernelCloseSema(SceUID semaId);
/* Mutexes. */
/** Additional options used when creating mutexes. */
typedef struct SceKernelMutexOptParam {
/** Size of the ::SceKernelMutexOptParam structure. */
SceSize size;
SceInt32 ceilingPriority;
} SceKernelMutexOptParam;
/** Current state of a mutex.
* @see sceKernelGetMutexInfo.
*/
typedef struct SceKernelMutexInfo {
/** Size of the ::SceKernelMutexInfo structure. */
SceSize size;
/** The UID of the mutex. */
SceUID mutexId;
/** NUL-terminated name of the mutex. */
char name[SCE_UID_NAMELEN + 1];
/** Attributes. */
SceUInt32 attr;
/** The initial count the mutex was created with. */
SceInt32 initCount;
/** The current count. */
SceInt32 currentCount;
/** The UID of the current owner of the mutex. */
SceUID currentOwnerId;
/** The number of threads waiting on the mutex. */
SceUInt32 numWaitThreads;
SceInt32 ceilingPriority;
} SceKernelMutexInfo;
/**
* Creates a new mutex
*
* @par Example:
* @code
* int mutexid;
* mutexid = sceKernelCreateMutex("MyMutex", 0, 1, 1, 0);
* @endcode
*
* @param pName - Specifies the name of the mutex
* @param attr - Mutex attribute flags (normally set to 0)
* @param initCount - Mutex initial value
* @param pOptParam - Mutex options (normally set to 0)
* @return A mutex id
*/
SceUID sceKernelCreateMutex(
const char *pName,
SceUInt32 attr,
SceInt32 initCount,
const SceKernelMutexOptParam *pOptParam);
/**
* Destroy a mutex
*
* @param mutexId - The mutex id returned from ::sceKernelCreateMutex
* @return Returns the value 0 if it's successful, otherwise < 0
*/
SceInt32 sceKernelDeleteMutex(SceUID mutexId);
/**
* Open a mutex
*
* @param pName - The name of the mutex to open
* @return Returns an UID if successful, otherwise < 0
*/
SceUID sceKernelOpenMutex(const char *pName);
/**
* Close a mutex
*
* @param mutexId - The mutex id returned from ::sceKernelCreateMutex
* @return Returns the value 0 if it's successful, otherwise < 0
*/
SceInt32 sceKernelCloseMutex(SceUID mutexId);
/**
* Lock a mutex
*
* @param mutexId - The mutex id returned from ::sceKernelCreateMutex
* @param lockCount - The value to increment to the lock count of the mutex
* @param pTimeout - Timeout in microseconds
* @return < 0 On error.
*/
SceInt32 sceKernelLockMutex(SceUID mutexId, SceInt32 lockCount, SceUInt32 *pTimeout);
/**
* Lock a mutex and handle callbacks if necessary.
*
* @param mutexId - The mutex id returned from ::sceKernelCreateMutex
* @param lockCount - The value to increment to the lock count of the mutex
* @param pTimeout - Timeout in microseconds
* @return < 0 On error.
*/
SceInt32 sceKernelLockMutexCB(SceUID mutexId, SceInt32 lockCount, SceUInt32 *pTimeout);
/**
* Try to lock a mutex (non-blocking)
*
* @param mutexId - The mutex id returned from ::sceKernelCreateMutex
* @param lockCount - The value to increment to the lock count of the mutex
* @return < 0 On error.
*/
SceInt32 sceKernelTryLockMutex(SceUID mutexId, SceInt32 lockCount);
/**
* Try to unlock a mutex (non-blocking)
*
* @param mutexId - The mutex id returned from ::sceKernelCreateMutex
* @param unlockCount - The value to decrement to the lock count of the mutex
* @return < 0 On error.
*/
SceInt32 sceKernelUnlockMutex(SceUID mutexId, SceInt32 unlockCount);
/**
* Cancels a mutex
*
* @param mutexId - The mutex id returned from ::sceKernelCreateMutex
* @param newCount - The new lock count of the mutex
* @param pNumWaitThreads - Number of threads waiting for the mutex
* @return < 0 On error.
*/
SceInt32 sceKernelCancelMutex(SceUID mutexId, SceInt32 newCount, SceUInt32 *pNumWaitThreads);
/**
* Retrieve information about a mutex.
*
* @param mutexId - UID of the mutex to retrieve info for.
* @param pInfo - Pointer to a ::SceKernelMutexInfo struct to receive the info.
*
* @return < 0 on error.
*/
SceInt32 sceKernelGetMutexInfo(SceUID mutexId, SceKernelMutexInfo *pInfo);
/* Event flags. */
/** Structure to hold the event flag information */
typedef struct SceKernelEventFlagInfo {
SceSize size;
SceUID evfId;
char name[SCE_UID_NAMELEN + 1];
SceUInt32 attr;
SceUInt32 initPattern;
SceUInt32 currentPattern;
SceUInt32 numWaitThreads;
} SceKernelEventFlagInfo;
typedef struct SceKernelEventFlagOptParam {
SceSize size;
} SceKernelEventFlagOptParam;
/**
* Create an event flag.
*
* @param pName - The name of the event flag.
* @param attr - Attributes from ::SceEventFlagAttributes
* @param initPattern - Initial bit pattern.
* @param pOptParam - 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 *pName,
SceUInt32 attr,
SceUInt32 initPattern,
const SceKernelEventFlagOptParam *pOptParam);
/**
* Set an event flag bit pattern.
*
* @param evfId - The event id returned by ::sceKernelCreateEventFlag.
* @param bitPattern - The bit pattern to set.
*
* @return < 0 On error
*/
SceInt32 sceKernelSetEventFlag(SceUID evfId, SceUInt32 bitPattern);
/**
* Clear a event flag bit pattern
*
* @param evfId - The event id returned by ::sceKernelCreateEventFlag
* @param bitPattern - The bits to unset
*
* @return < 0 on Error
*/
SceInt32 sceKernelClearEventFlag(SceUID evfId, SceUInt32 bitPattern);
/**
* Poll an event flag for a given bit pattern.
*
* @param evfId - The event id returned by ::sceKernelCreateEventFlag.
* @param bitPattern - The bit pattern to poll for.
* @param waitMode - Wait type, one or more of ::SceEventFlagWaitTypes or'ed together
* @param pResultPat - The bit pattern that was matched.
* @return < 0 On error
*/
SceInt32 sceKernelPollEventFlag(SceUID evfId, SceUInt32 bitPattern, SceUInt32 waitMode, SceUInt32 *pResultPat);
/**
* Wait for an event flag for a given bit pattern.
*
* @param evfId - The event id returned by ::sceKernelCreateEventFlag.
* @param bitPattern - The bit pattern to poll for.
* @param waitMode - Wait type, one or more of ::SceEventFlagWaitTypes or'ed together
* @param pResultPat - The bit pattern that was matched.
* @param pTimeout - Timeout in microseconds
* @return < 0 On error
*/
SceInt32 sceKernelWaitEventFlag(
SceUID evfId,
SceUInt32 bitPattern,
SceUInt32 waitMode,
SceUInt32 *pResultPat,
SceUInt32 *pTimeout);
/**
* Wait for an event flag for a given bit pattern with callback.
*
* @param evfId - The event id returned by ::sceKernelCreateEventFlag.
* @param bitPattern - The bit pattern to poll for.
* @param waitMode - Wait type, one or more of ::SceEventFlagWaitTypes or'ed together
* @param pResultPat - The bit pattern that was matched.
* @param pTimeout - Timeout in microseconds
* @return < 0 On error
*/
SceInt32 sceKernelWaitEventFlagCB(
SceUID evfId,
SceUInt32 bitPattern,
SceUInt32 waitMode,
SceUInt32 *pResultPat,
SceUInt32 *pTimeout);
/**
* Delete an event flag
*
* @param evfId - The event id returned by ::sceKernelCreateEventFlag.
*
* @return < 0 On error
*/
SceInt32 sceKernelDeleteEventFlag(SceUID evfId);
/**
* Get the status of an event flag.
*
* @param evfId - The UID of the event.
* @param pInfo - A pointer to a ::SceKernelEventFlagInfo structure.
*
* @return < 0 on error.
*/
SceInt32 sceKernelGetEventFlagInfo(SceUID evfId, SceKernelEventFlagInfo *pInfo);
SceUID sceKernelOpenEventFlag(const char *pName);
SceInt32 sceKernelCloseEventFlag(SceUID evfId);
SceInt32 sceKernelCancelEventFlag(SceUID evfId, SceUInt32 setPattern, SceUInt32 *pNumWaitThreads);
/* Condition variables */
/** Additional options used when creating condition variables. */
typedef struct SceKernelCondOptParam {
/** Size of the ::SceKernelCondOptParam structure. */
SceSize size;
} SceKernelCondOptParam;
/** Current state of a condition variable.
* @see sceKernelGetCondInfo.
*/
typedef struct SceKernelCondInfo {
/** Size of the ::SceKernelCondInfo structure. */
SceSize size;
/** The UID of the condition variable. */
SceUID condId;
/** NUL-terminated name of the condition variable. */
char name[SCE_UID_NAMELEN + 1];
/** Attributes. */
SceUInt attr;
/** Mutex associated with the condition variable. */
SceUID mutexId;
/** The number of threads waiting on the condition variable. */
int numWaitThreads;
} SceKernelCondInfo;
/**
* Creates a new condition variable
*
* @par Example:
* @code
* SceUID condId;
* condId = sceKernelCreateCond("MyCond", 0, mutexId, NULL);
* @endcode
*
* @param pName - Specifies the name of the condition variable
* @param attr - Condition variable attribute flags (normally set to 0)
* @param mutexId - Mutex to be related to the condition variable
* @param pOptParam - Condition variable options (normally set to 0)
* @return A condition variable id
*/
SceUID sceKernelCreateCond(
const char *pName,
SceUInt32 attr,
SceUID mutexId,
const SceKernelCondOptParam *pOptParam);
/**
* Destroy a condition variable
*
* @param condition variableid - The condition variable id returned from ::sceKernelCreateCond
* @return Returns the value 0 if it's successful, otherwise < 0
*/
SceInt32 sceKernelDeleteCond(SceUID condId);
/**
* Open a condition variable
*
* @param pName - The name of the condition variable to open
* @return Returns an UID if successful, otherwise < 0
*/
SceUID sceKernelOpenCond(const char *pName);
/**
* Close a condition variable
*
* @param condition variableid - The condition variable id returned from ::sceKernelCreateCond
* @return Returns the value 0 if it's successful, otherwise < 0
*/
SceInt32 sceKernelCloseCond(SceUID condId);
/**
* Waits for a signal of a condition variable
*
* @param condId - The condition variable id returned from ::sceKernelCreateCond
* @param pTimeout - Timeout in microseconds
* @return < 0 On error.
*/
SceInt32 sceKernelWaitCond(SceUID condId, SceUInt32 *pTimeout);
/**
* Waits for a signal of a condition variable (with callbacks)
*
* @param condId - The condition variable id returned from ::sceKernelCreateCond
* @param pTimeout - Timeout in microseconds
* @return < 0 On error.
*/
SceInt32 sceKernelWaitCondCB(SceUID condId, SceUInt32 *pTimeout);
/**
* Signals a condition variable
*
* @param condId - The condition variable id returned from ::sceKernelCreateCond
* @return < 0 On error.
*/
SceInt32 sceKernelSignalCond(SceUID condId);
/**
* Signals a condition variable to all threads waiting for it
*
* @param condId - The condition variable id returned from ::sceKernelCreateCond
* @return < 0 On error.
*/
SceInt32 sceKernelSignalCondAll(SceUID condId);
/**
* Signals a condition variable to a specific thread waiting for it
*
* @param condId - The condition variable id returned from ::sceKernelCreateCond
* @param threadId - The thread id returned from ::sceKernelCreateThread
* @return < 0 On error.
*/
SceInt32 sceKernelSignalCondTo(SceUID condId, SceUID threadId);
SceInt32 sceKernelGetCondInfo(SceUID condId, SceKernelCondInfo *pInfo);
/* Callbacks. */
/** Callback function prototype */
typedef SceInt32 (*SceKernelCallbackFunction)(
SceUID notifyId,
SceInt32 notifyCount,
SceInt32 notifyArg,
void *pCommon);
/** Structure to hold the status information for a callback */
typedef struct SceKernelCallbackInfo {
/** Size of the structure (i.e. sizeof(SceKernelCallbackInfo)) */
SceSize size;
/** The UID of the callback. */
SceUID callbackId;
/** The name given to the callback */
char name[SCE_UID_NAMELEN + 1];
SceUInt32 attr;
/** The thread id associated with the callback */
SceUID threadId;
/** Pointer to the callback function */
SceKernelCallbackFunction callbackFunc;
SceUID notifyId;
SceInt32 notifyCount;
SceInt32 notifyArg;
/** User supplied argument for the callback */
void *pCommon;
} SceKernelCallbackInfo;
/**
* Create callback
*
* @par Example:
* @code
* int cbid;
* cbid = sceKernelCreateCallback("Exit Callback", 0, exit_cb, NULL);
* @endcode
*
* @param name - A textual name for the callback
* @param attr - Set to 0. There are no attributes.
* @param callbackFunc - A pointer to a function that will be called as the callback
* @param pCommon - Common data for the callback
*
* @return >= 0 A callback id which can be used in subsequent functions, < 0 an error.
*/
SceUID sceKernelCreateCallback(
const char *name,
SceUInt32 attr,
SceKernelCallbackFunction callbackFunc,
void *pCommon);
/**
* Gets the status of a specified callback.
*
* @param callbackId - The UID of the callback to retrieve info for.
* @param pInfo - Pointer to a status structure. The size parameter should be
* initialised before calling.
*
* @return < 0 on error.
*/
SceInt32 sceKernelGetCallbackInfo(SceUID callbackId, SceKernelCallbackInfo *pInfo);
/**
* Delete a callback
*
* @param callbackId - The UID of the specified callback
*
* @return 0 on success, < 0 on error
*/
SceInt32 sceKernelDeleteCallback(SceUID callbackId);
/**
* Notify a callback
*
* @param callbackId - The UID of the specified callback
* @param notifyArg - Passed as arg2 into the callback function
*
* @return 0 on success, < 0 on error
*/
SceInt32 sceKernelNotifyCallback(SceUID callbackId, SceInt32 notifyArg);
/**
* Cancel a callback ?
*
* @param callbackId - The UID of the specified callback
*
* @return 0 on success, < 0 on error
*/
SceInt32 sceKernelCancelCallback(SceUID callbackId);
/**
* Get the callback count
*
* @param callbackId - The UID of the specified callback
*
* @return The callback count, < 0 on error
*/
SceInt32 sceKernelGetCallbackCount(SceUID callbackId);
/**
* Check callback notification
*
* @return Callback notification count or < 0 on error
*/
SceInt32 sceKernelCheckCallback(void);
/* Message pipes */
typedef struct _SceKernelMsgPipeOptParam {
SceSize size;
SceUInt32 attr;
SceInt32 reserved[2];
SceUInt32 openLimit;
} SceKernelMsgPipeOptParam;
/**
* Create a message pipe
*
* @param pName - Name of the pipe
* @param type - Message pipe memory type
* @param attr - Message pipe attribute
* @param bufSize - The size of the internal buffer in multiples of 0x1000 (4KiB) up to 32MiB
* @param pOptParam - Message pipe options
*
* @return The UID of the created pipe, < 0 on error
*/
SceUID sceKernelCreateMsgPipe(
const char *pName,
SceUInt32 type,
SceUInt32 attr,
SceSize bufSize,
const SceKernelMsgPipeOptParam *pOptParam);
/**
* Delete a message pipe
*
* @param msgPipeId - The UID of the pipe
*
* @return 0 on success, < 0 on error
*/
SceInt32 sceKernelDeleteMsgPipe(SceUID msgPipeId);
/**
* Send a message to a pipe
*
* @param msgPipeId - The UID of the pipe
* @param pSendBuf - Pointer to the message
* @param sendSize - Size of the message
* @param waitMode - Wait mode when sending
* @param pResult - Pointer to area to store sent size
* @param pTimeout - Timeout in microseconds
*
* @return 0 on success, < 0 on error
*/
SceInt32 sceKernelSendMsgPipe(
SceUID msgPipeId,
const void *pSendBuf,
SceSize sendSize,
SceUInt32 waitMode,
SceSize *pResult,
SceUInt32 *pTimeout);
/**
* Send a message to a pipe (with callback)
*
* @param msgPipeId - The UID of the pipe
* @param pSendBuf - Pointer to the message
* @param sendSize - Size of the message
* @param waitMode - Wait mode when sending
* @param pResult - Pointer to area to store sent size
* @param pTimeout - Timeout in microseconds
*
* @return 0 on success, < 0 on error
*/
SceInt32 sceKernelSendMsgPipeCB(
SceUID msgPipeId,
const void *pSendBuf,
SceSize sendSize,
SceUInt32 waitMode,
SceSize *pResult,
SceUInt32 *pTimeout);
/**
* Send a message to a pipe (non blocking)
*
* @param msgPipeId - The UID of the pipe
* @param pSendBuf - Pointer to the message
* @param sendSize - Size of the message
* @param waitMode - Wait mode when sending
* @param pResult - Pointer to area to store sent size
*
* @return 0 on success, < 0 on error
*/
SceInt32 sceKernelTrySendMsgPipe(
SceUID msgPipeId,
const void *pSendBuf,
SceSize sendSize,
SceUInt32 waitMode,
SceSize *pResult);
/**
* Receive a message from a pipe
*
* @param msgPipeId - The UID of the pipe
* @param pRecvBuf - Pointer to the message
* @param recvSize - Size of the message
* @param waitMode - Wait mode when receiving
* @param pResult - Pointer to area to store received size
* @param pTimeout - Timeout in microseconds
*
* @return 0 on success, < 0 on error
*/
SceInt32 sceKernelReceiveMsgPipe(
SceUID msgPipeId,
const void *pRecvBuf,
SceSize recvSize,
SceUInt32 waitMode,
SceSize *pResult,
SceUInt32 *pTimeout);
/**
* Receive a message from a pipe (with callback)
*
* @param msgPipeId - The UID of the pipe
* @param pRecvBuf - Pointer to the message
* @param recvSize - Size of the message
* @param waitMode - Wait mode when receiving
* @param pResult - Pointer to area to store received size
* @param pTimeout - Timeout in microseconds
*
* @return 0 on success, < 0 on error
*/
SceInt32 sceKernelReceiveMsgPipeCB(
SceUID msgPipeId,
const void *pRecvBuf,
SceSize recvSize,
SceUInt32 waitMode,
SceSize *pResult,
SceUInt32 *pTimeout);
/**
* Receive a message from a pipe (non blocking)
*
* @param msgPipeId - The UID of the pipe
* @param pRecvBuf - Pointer to the message
* @param recvSize - Size of the message
* @param waitMode - Wait mode when receiving
* @param pResult - Pointer to area to store received size
*
* @return 0 on success, < 0 on error
*/
SceInt32 sceKernelTryReceiveMsgPipe(
SceUID msgPipeId,
void *pRecvBuf,
SceSize recvSize,
SceUInt32 waitMode,
SceSize *pResult);
/**
* Cancel a message pipe
*
* @param msgPipeId - UID of the pipe to cancel
* @param pNumSendWaitThreads - Receive number of sending threads, NULL is valid
* @param pNumReceiveWaitThreads - Receive number of receiving threads, NULL is valid
*
* @return 0 on success, < 0 on error
*/
SceInt32 sceKernelCancelMsgPipe(
SceUID msgPipeId,
SceUInt32 *pNumSendWaitThreads,
SceUInt32 *pNumReceiveWaitThreads);
/** Message Pipe status info */
typedef struct SceKernelMppInfo {
SceSize size;
SceUID msgPipeId;
char name[SCE_UID_NAMELEN + 1];
SceUInt32 attr;
SceSize bufSize;
SceSize freeSize;
SceUInt32 numSendWaitThreads;
SceUInt32 numReceiveWaitThreads;
} SceKernelMppInfo;
/**
* Get the status of a Message Pipe
*
* @param msgPipeId - The uid of the Message Pipe
* @param pInfo - Pointer to a ::SceKernelMppInfo structure
*
* @return 0 on success, < 0 on error
*/
SceInt32 sceKernelGetMsgPipeInfo(SceUID msgPipeId, SceKernelMppInfo *pInfo);
SceUID sceKernelOpenMsgPipe(const char *pName);
SceInt32 sceKernelCloseMsgPipe(SceUID msgPipeId);
typedef struct _SceKernelMsgPipeVector {
void *pBase;
SceSize bufSize;
} SceKernelMsgPipeVector;
SceInt32 sceKernelSendMsgPipeVector(
SceUID msgPipeId,
const SceKernelMsgPipeVector *pVector,
SceUInt32 numVector,
SceUInt32 waitMode,
SceSize *pResult,
SceUInt32 *pTimeout
);
SceInt32 sceKernelSendMsgPipeVectorCB(
SceUID msgPipeId,
const SceKernelMsgPipeVector *pVector,
SceUInt32 numVector,
SceUInt32 waitMode,
SceSize *pResult,
SceUInt32 *pTimeout);
SceInt32 sceKernelTrySendMsgPipeVector(
SceUID msgPipeId,
const SceKernelMsgPipeVector *pVector,
SceUInt32 numVector,
SceUInt32 waitMode,
SceSize *pResult);
SceInt32 sceKernelReceiveMsgPipeVector(
SceUID msgPipeId,
const SceKernelMsgPipeVector *pVector,
SceUInt32 numVector,
SceUInt32 waitMode,
SceSize *pResult,
SceUInt32 *pTimeout);
SceInt32 sceKernelReceiveMsgPipeVectorCB(
SceUID msgPipeId,
const SceKernelMsgPipeVector *pVector,
SceUInt32 numVector,
SceUInt32 waitMode,
SceSize *pResult,
SceUInt32 *pTimeout);
SceInt32 sceKernelTryReceiveMsgPipeVector(
SceUID msgPipeId,
const SceKernelMsgPipeVector *pVector,
SceUInt32 numVector,
SceUInt32 waitMode,
SceSize *pResult);
/* Thread event */
SceInt32 sceKernelRegisterCallbackToEvent(SceUID eventId, SceUID callbackId);
SceInt32 sceKernelUnregisterCallbackFromEvent(SceUID eventId, SceUID callbackId);
SceInt32 sceKernelUnregisterCallbackFromEventAll(SceUID eventId);
typedef SceInt32 (*SceKernelThreadEventHandler)(SceInt32 type, SceUID threadId, SceInt32 arg, void *pCommon);
typedef struct _SceKernelEventInfo {
SceSize size;
SceUID eventId;
char name[SCE_UID_NAMELEN + 1];
SceUInt32 attr;
SceUInt32 eventPattern;
SceUInt64 userData;
SceUInt32 numWaitThreads;
SceInt32 reserved[1];
} SceKernelEventInfo;
SceInt32 sceKernelWaitEvent(
SceUID eventId,
SceUInt32 waitPattern,
SceUInt32 *pResultPattern,
SceUInt64 *pUserData,
SceUInt32 *pTimeout
);
SceInt32 sceKernelWaitEventCB(
SceUID eventId,
SceUInt32 waitPattern,
SceUInt32 *pResultPattern,
SceUInt64 *pUserData,
SceUInt32 *pTimeout
);
SceInt32 sceKernelPollEvent(
SceUID eventId,
SceUInt32 bitPattern,
SceUInt32 *pResultPattern,
SceUInt64 *pUserData
);
typedef struct _SceKernelWaitEvent {
SceUID eventId;
SceUInt32 eventPattern;
} SceKernelWaitEvent;
typedef struct _SceKernelResultEvent {
SceUID eventId;
SceInt32 result;
SceUInt32 resultPattern;
SceInt32 reserved[1];
SceUInt64 userData;
} SceKernelResultEvent;
SceInt32 sceKernelWaitMultipleEvents(
SceKernelWaitEvent *pWaitEventList,
SceUInt32 numEvents,
SceUInt32 waitMode,
SceKernelResultEvent *pResultEventList,
SceUInt32 *pTimeout);
SceInt32 sceKernelWaitMultipleEventsCB(
SceKernelWaitEvent *pWaitEventList,
SceUInt32 numEvents,
SceUInt32 waitMode,
SceKernelResultEvent *pResultEventList,
SceUInt32 *pTimeout);
SceInt32 sceKernelSetEvent(
SceUID eventId,
SceUInt32 setPattern,
SceUInt64 userData);
SceInt32 sceKernelSetEventWithNotifyCallback(
SceUID eventId,
SceUInt32 setPattern,
SceUInt64 userData,
SceInt32 notifyArg);
SceInt32 sceKernelPulseEvent(
SceUID eventId,
SceUInt32 pulsePattern,
SceUInt64 userData);
SceInt32 sceKernelPulseEventWithNotifyCallback(
SceUID eventId,
SceUInt32 pulsePattern,
SceUInt64 userData,
SceInt32 notifyArg);
SceInt32 sceKernelClearEvent(
SceUID eventId,
SceUInt32 clearPattern);
SceInt32 sceKernelCancelEventWithSetPattern(
SceUID eventId,
SceUInt32 setPattern,
SceUInt64 userData,
SceUInt32 *pNumWaitThreads);
SceInt32 sceKernelGetEventPattern(
SceUID eventId,
SceUInt32 *pPattern);
SceInt32 sceKernelCancelEvent(
SceUID eventId,
SceUInt32 *pNumWaitThreads);
SceInt32 sceKernelGetEventInfo(
SceUID eventId,
SceKernelEventInfo *pInfo);
/* Reader/writer lock */
typedef struct _SceKernelRWLockOptParam {
SceSize size;
} SceKernelRWLockOptParam;
typedef struct _SceKernelRWLockInfo {
SceSize size;
SceUID rwLockId;
char name[SCE_UID_NAMELEN + 1];
SceUInt32 attr;
SceInt32 lockCount;
SceUID writeOwnerId;
SceUInt32 numReadWaitThreads;
SceUInt32 numWriteWaitThreads;
} SceKernelRWLockInfo;
SceUID sceKernelCreateRWLock(
const char *pName,
SceUInt32 attr,
const SceKernelRWLockOptParam*pOptParam);
SceInt32 sceKernelDeleteRWLock(SceUID rwLockId);
SceUID sceKernelOpenRWLock(const char pName);
SceInt32 sceKernelCloseRWLock(SceUID rwLockId);
SceInt32 sceKernelLockReadRWLock(SceUID rwLockId, SceUInt32 *pTimeout);
SceInt32 sceKernelLockReadRWLockCB(SceUID rwLockId, SceUInt32 *pTimeout);
SceInt32 sceKernelTryLockReadRWLock(SceUID rwLockId);
SceInt32 sceKernelUnlockReadRWLock(SceUID rwLockId);
SceInt32 sceKernelLockWriteRWLock(SceUID rwLockId, SceUInt32 *pTimeout);
SceInt32 sceKernelLockWriteRWLockCB(SceUID rwLockId, SceUInt32 *pTimeout);
SceInt32 sceKernelTryLockWriteRWLock(SceUID rwLockId);
SceInt32 sceKernelUnlockWriteRWLock(SceUID rwLockId);
SceInt32 sceKernelCancelRWLock(
SceUID rwLockId,
SceUInt32 *pNumReadWaitThreads,
SceUInt32 *pNumWriteWaitThreads,
SceInt32 flag);
SceInt32 sceKernelGetRWLockInfo(SceUID rwLockId, SceKernelRWLockInfo *pInfo);
/* Thread timer */
typedef struct _SceKernelTimerOptParam {
SceSize size;
} SceKernelTimerOptParam;
typedef struct _SceKernelTimerInfo {
SceSize size;
SceUID timerId;
char name[SCE_UID_NAMELEN + 1];
SceUInt32 attr;
SceInt32 fActive;
SceKernelSysClock baseTime;
SceKernelSysClock currentTime;
SceKernelSysClock schedule;
SceKernelSysClock interval;
SceInt32 type;
SceInt32 fRepeat;
SceUInt32 numWaitThreads;
SceInt32 reserved[1];
} SceKernelTimerInfo;
SceUID sceKernelCreateTimer(
const char *pName,
SceUInt32 attr,
const SceKernelTimerOptParam *pOptParam);
SceInt32 sceKernelDeleteTimer(SceUID timerId);
SceUID sceKernelOpenTimer(const char *pName);
SceInt32 sceKernelCloseTimer(SceUID timerId);
SceInt32 sceKernelStartTimer(SceUID timerId);
SceInt32 sceKernelStopTimer(SceUID timerId);
SceInt32 sceKernelGetTimerBase(SceUID timerId, SceKernelSysClock *pBase);
SceUInt64 sceKernelGetTimerBaseWide(SceUID timerId);
SceInt32 sceKernelGetTimerTime(SceUID timerId, SceKernelSysClock *pClock);
SceUInt64 sceKernelGetTimerTimeWide(SceUID timerId);
SceInt32 sceKernelSetTimerTime(SceUID timerId, SceKernelSysClock *pClock);
SceUInt64 sceKernelSetTimerTimeWide(SceUID timerId, SceUInt64 clock);
SceInt32 sceKernelSetTimerEvent(
SceUID timerId,
SceInt32 type,
SceKernelSysClock *pInterval,
SceInt32 fRepeat);
SceInt32 sceKernelCancelTimer(SceUID timerId, SceUInt32 *pNumWaitThreads);
SceInt32 sceKernelGetTimerInfo(SceUID timerId, SceKernelTimerInfo *pInfo);
SceInt32 sceKernelGetTimerEventRemainingTime(SceUID timerId, SceKernelSysClock *pClock);
/* Simple event */
typedef struct _SceKernelSimpleEventOptParam {
SceSize size;
} SceKernelSimpleEventOptParam;
SceUID sceKernelCreateSimpleEvent(
const char *pName,
SceUInt32 attr,
SceUInt32 initPattern,
const SceKernelSimpleEventOptParam *pOptParam);
SceInt32 sceKernelDeleteSimpleEvent(SceUID simpleEventId);
SceUID sceKernelOpenSimpleEvent(const char *pName);
SceInt32 sceKernelCloseSimpleEvent(SceUID simpleEventId);
/* Misc. */
typedef struct SceKernelSystemInfo {
SceSize size;
SceUInt32 activeCpuMask;
struct {
SceKernelSysClock idleClock;
SceUInt32 comesOutOfIdleCount;
SceUInt32 threadSwitchCount;
} cpuInfo[SCE_KERNEL_MAX_CPU];
} SceKernelSystemInfo;
/**
* Get the system information
*
* @param pInfo - Pointer to a ::SceKernelSystemInfo structure
*
* @return 0 on success, < 0 on error
*/
SceInt32 sceKernelGetSystemInfo(SceKernelSystemInfo *pInfo);
/* Misc. */
/** Threadmgr types */
typedef enum SceKernelIdListType {
SCE_KERNEL_TMID_Thread = 1,
SCE_KERNEL_TMID_Semaphore = 2,
SCE_KERNEL_TMID_EventFlag = 3,
SCE_KERNEL_TMID_Mbox = 4,
SCE_KERNEL_TMID_Vpl = 5,
SCE_KERNEL_TMID_Fpl = 6,
SCE_KERNEL_TMID_Mpipe = 7,
SCE_KERNEL_TMID_Callback = 8,
SCE_KERNEL_TMID_ThreadEventHandler = 9,
SCE_KERNEL_TMID_Alarm = 10,
SCE_KERNEL_TMID_VTimer = 11,
SCE_KERNEL_TMID_SleepThread = 64,
SCE_KERNEL_TMID_DelayThread = 65,
SCE_KERNEL_TMID_SuspendThread = 66,
SCE_KERNEL_TMID_DormantThread = 67
} SceKernelIdListType;
/**
* Get the type of a Threadmgr uid
*
* @param uid - The uid to get the type from
*
* @return The type, < 0 on error
*/
SceKernelIdListType sceKernelGetThreadmgrUIDClass(SceUID uid);
/* Lightweight mutex */
typedef struct SceKernelLwMutexWork {
SceInt64 data[4];
} SceKernelLwMutexWork;
typedef struct SceKernelLwMutexOptParam {
SceSize size;
} SceKernelLwMutexOptParam;
typedef struct _SceKernelLwMutexInfo {
SceSize size;
SceUID uid;
char name[SCE_UID_NAMELEN + 1];
SceUInt32 attr;
SceKernelLwMutexWork *pWork;
SceInt32 initCount;
SceInt32 currentCount;
SceUID currentOwnerId;
SceUInt32 numWaitThreads;
} SceKernelLwMutexInfo;
SceInt32 sceKernelCreateLwMutex(
SceKernelLwMutexWork *pWork,
const char *pName,
SceUInt32 attr,
SceInt32 initCount,
const SceKernelLwMutexOptParam *pOptParam);
SceInt32 sceKernelDeleteLwMutex(SceKernelLwMutexWork *pWork);
SceInt32 sceKernelLockLwMutex(SceKernelLwMutexWork *pWork, SceInt32 lockCount, SceUInt32 *pTimeout);
SceInt32 sceKernelLockLwMutexCB(SceKernelLwMutexWork *pWork, SceInt32 lockCount, SceUInt32 *pTimeout);
SceInt32 sceKernelTryLockLwMutex(SceKernelLwMutexWork *pWork, SceInt32 lockCount);
SceInt32 sceKernelUnlockLwMutex(SceKernelLwMutexWork *pWork, SceInt32 unlockCount);
SceInt32 sceKernelGetLwMutexInfo(SceKernelLwMutexWork *pWork, SceKernelLwMutexInfo *pInfo);
SceInt32 sceKernelGetLwMutexInfoById(SceUID lwMutexId, SceKernelLwMutexInfo *pInfo);
/* Lightweight condition */
typedef struct SceKernelLwCondWork {
SceInt64 data[4];
} SceKernelLwCondWork;
typedef struct SceKernelLwCondOptParam {
SceSize size;
} SceKernelLwCondOptParam;
typedef struct _SceKernelLwCondInfo {
SceSize size;
SceUID uid;
char name[SCE_UID_NAMELEN + 1];
SceUInt32 attr;
SceKernelLwCondWork *pWork;
SceKernelLwMutexWork *pLwMutex;
SceUInt32 numWaitThreads;
} SceKernelLwCondInfo;
SceInt32 sceKernelCreateLwCond(
SceKernelLwCondWork *pWork,
const char *pName,
SceUInt32 attr,
SceKernelLwMutexWork *pLwMutex,
const SceKernelLwCondOptParam *pOptParam
);
SceInt32 sceKernelDeleteLwCond(SceKernelLwCondWork *pWork);
SceInt32 sceKernelSignalLwCond(SceKernelLwCondWork *pWork);
SceInt32 sceKernelWaitLwCond(SceKernelLwCondWork *pWork, SceUInt32 *pTimeout);
SceInt32 sceKernelSignalLwCondAll(SceKernelLwCondWork *pWork);
SceInt32 sceKernelSignalLwCondTo(SceKernelLwCondWork *pWork, SceUID threadId);
SceInt32 sceKernelGetLwCondInfo (SceKernelLwCondWork *pWork, SceKernelLwCondInfo *pInfo);
SceInt32 sceKernelGetLwCondInfoById(SceUID lwCondId, SceKernelLwCondInfo *pInfo);
/**
* Get the system time (wide version)
*
* @return The system time
*/
SceInt64 sceKernelGetSystemTimeWide(void);
/**
* @brief sceKernelGetThreadTLSAddr gets an address to a 4 bytes area of TLS memory for the specified thread
* @param thid - The UID of the thread to access TLS
* @param key - the TLS keyslot index
* @return pointer to TLS memory
*/
void *sceKernelGetThreadTLSAddr(SceUID thid, int key);
/**
* @brief sceKernelGetTLSAddr get pointer to TLS key area for current thread
* @param key - the TLS keyslot index
* @return pointer to TLS key value
*/
void *sceKernelGetTLSAddr(int key);
#ifdef __cplusplus
}
#endif
#endif /* _PSP2_KERNEL_THREADMGR_H_ */
|