-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy paththread.c
68 lines (55 loc) · 1.34 KB
/
thread.c
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
#include <sdk/ee/eekernel.h>
#include <sce/memset.h>
#include <thread.h>
#include <frm.h>
int SemaCreate(int initCount, int maxCount)
{
SemaParam sp;
memset(&sp, 0, sizeof(SemaParam));
sp.initCount = initCount;
sp.maxCount = maxCount;
return CreateSema(&sp);
}
INCLUDE_ASM(const s32, "P2/thread", func_001E22B8);
void InitCritSect(CRITSECT *pcritsect)
{
pcritsect->thread = -1;
pcritsect->sema = SemaCreate(1, 1);
}
void EnterCritSect(CRITSECT *pcritsect)
{
int threadId = GetThreadId();
if (threadId != pcritsect->thread)
{
WaitSema(pcritsect->sema);
pcritsect->thread = threadId;
pcritsect->cEnter = 1;
}
else
{
pcritsect->cEnter++;
}
}
void LeaveCritSect(CRITSECT *pcritsect)
{
int critSects = pcritsect->cEnter - 1;
pcritsect->cEnter = critSects;
if (critSects == 0) {
pcritsect->thread = -1;
SignalSema(pcritsect->sema);
}
}
INCLUDE_ASM(const s32, "P2/thread", func_001E2390);
void StartupThread()
{
ThreadParam tp;
g_athread.cEnter = GetThreadId();
ChangeThreadPriority(g_athread.cEnter, 4);
memset(&tp, 0, sizeof(ThreadParam));
tp.stackSize = 0x20000;
tp.stack = g_abRenderLoopStack;
tp.initPriority = 2;
tp.gpReg = &_gpReg;
tp.entry = FrameRenderLoop;
g_athread.thread = CreateThread(&tp);
}