mirror of https://github.com/mgba-emu/mgba.git
3DS: Use ctrlib Thread abstraction
This commit is contained in:
parent
715efc63bd
commit
7097d249af
|
@ -11,18 +11,9 @@
|
||||||
#include <3ds.h>
|
#include <3ds.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
|
||||||
#ifdef _3DS
|
|
||||||
// ctrulib already has a type called Thread
|
|
||||||
#define Thread CustomThread
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define THREAD_ENTRY void
|
#define THREAD_ENTRY void
|
||||||
typedef ThreadFunc ThreadEntry;
|
typedef ThreadFunc ThreadEntry;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Handle handle;
|
|
||||||
u8* stack;
|
|
||||||
} Thread;
|
|
||||||
typedef LightLock Mutex;
|
typedef LightLock Mutex;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Mutex mutex;
|
Mutex mutex;
|
||||||
|
@ -103,22 +94,12 @@ static inline int ThreadCreate(Thread* thread, ThreadEntry entry, void* context)
|
||||||
if (!entry || !thread) {
|
if (!entry || !thread) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
thread->stack = memalign(8, 0x8000);
|
*thread = threadCreate(entry, context, 0x8000, 0x18, 2, true);
|
||||||
if (!thread->stack) {
|
return !*thread;
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
bool isNew3DS;
|
|
||||||
APT_CheckNew3DS(&isNew3DS);
|
|
||||||
if (isNew3DS && svcCreateThread(&thread->handle, entry, (u32) context, (u32*) &thread->stack[0x8000], 0x18, 2) == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return svcCreateThread(&thread->handle, entry, (u32) context, (u32*) &thread->stack[0x8000], 0x18, -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int ThreadJoin(Thread thread) {
|
static inline int ThreadJoin(Thread thread) {
|
||||||
svcWaitSynchronization(thread.handle, U64_MAX);
|
return threadJoin(thread, U64_MAX);
|
||||||
free(thread.stack);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void ThreadSetName(const char* name) {
|
static inline void ThreadSetName(const char* name) {
|
||||||
|
|
Loading…
Reference in New Issue