-
Notifications
You must be signed in to change notification settings - Fork 5
/
thread.cpp
56 lines (44 loc) · 985 Bytes
/
thread.cpp
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
#include "thread.h"
#include "log.h"
#include <psp2/kernel/threadmgr.h>
Thread::Thread(const char *name)
: m_name(name)
{
}
Thread::~Thread()
{
sceKernelWaitThreadEnd(m_thid, nullptr, nullptr);
sceKernelDeleteThread(m_thid);
}
int Thread::start()
{
const auto thid = sceKernelCreateThread(m_name, &threadEntry, 0x40, m_stackSize, 0, 0, NULL);
if (thid < 0)
{
LOG("failed to create thread: 0x%08X\n", thid);
return thid;
}
Thread *ptr = this;
const auto res = sceKernelStartThread(thid, sizeof(ptr), &ptr);
if (res < 0)
{
LOG("failed to start thread 0x%08X\n", res);
return res;
}
m_thid = thid;
return 0;
}
unsigned int Thread::stackSize() const
{
return m_stackSize;
}
void Thread::setStackSize(unsigned int size)
{
m_stackSize = size;
}
int Thread::threadEntry(SceSize args, void *argp)
{
Thread *ptr = *reinterpret_cast<Thread **>(argp);
ptr->run();
return 0;
}