Integrate 3ds_pxi and 3ds_sm
This commit is contained in:
42
sysmodules/pxi/source/MyThread.c
Normal file
42
sysmodules/pxi/source/MyThread.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
MyThread.c:
|
||||
Small threading library, based off ctrulib.
|
||||
|
||||
(c) TuxSH, 2016-2017
|
||||
This is part of 3ds_pxi, which is licensed under the MIT license (see LICENSE for details).
|
||||
*/
|
||||
|
||||
#include "MyThread.h"
|
||||
#include "memory.h"
|
||||
|
||||
static void _thread_begin(void* arg)
|
||||
{
|
||||
MyThread *t = (MyThread *)arg;
|
||||
t->ep();
|
||||
MyThread_Exit();
|
||||
}
|
||||
|
||||
Result MyThread_Create(MyThread *t, void (*entrypoint)(void), void *stack, u32 stackSize, int prio, int affinity)
|
||||
{
|
||||
t->ep = entrypoint;
|
||||
t->stacktop = (u8 *)stack + stackSize;
|
||||
|
||||
return svcCreateThread(&t->handle, _thread_begin, (u32)t, (u32*)t->stacktop, prio, affinity);
|
||||
}
|
||||
|
||||
Result MyThread_Join(MyThread *thread, s64 timeout_ns)
|
||||
{
|
||||
if (thread == NULL) return 0;
|
||||
Result res = svcWaitSynchronization(thread->handle, timeout_ns);
|
||||
if(R_FAILED(res)) return res;
|
||||
|
||||
svcCloseHandle(thread->handle);
|
||||
thread->handle = (Handle)0;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void MyThread_Exit(void)
|
||||
{
|
||||
svcExitThread();
|
||||
}
|
||||
Reference in New Issue
Block a user