mirror of https://github.com/mgba-emu/mgba.git
Switch: Fix threading-related crash on second launch
This commit is contained in:
parent
d839098cae
commit
1f2bd30b14
1
CHANGES
1
CHANGES
|
@ -20,6 +20,7 @@ Emulation fixes:
|
||||||
Other fixes:
|
Other fixes:
|
||||||
- Qt: Fix some Qt display driver race conditions
|
- Qt: Fix some Qt display driver race conditions
|
||||||
- Core: Improved lockstep driver reliability (Le Hoang Quyen)
|
- Core: Improved lockstep driver reliability (Le Hoang Quyen)
|
||||||
|
- Switch: Fix threading-related crash on second launch
|
||||||
Misc:
|
Misc:
|
||||||
- GBA Savedata: EEPROM performance fixes
|
- GBA Savedata: EEPROM performance fixes
|
||||||
- GBA Savedata: Automatically map 1Mbit Flash files as 1Mbit Flash
|
- GBA Savedata: Automatically map 1Mbit Flash files as 1Mbit Flash
|
||||||
|
|
|
@ -98,8 +98,8 @@ static inline int ThreadCreate(Thread* thread, ThreadEntry entry, void* context)
|
||||||
return !*thread;
|
return !*thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int ThreadJoin(Thread thread) {
|
static inline int ThreadJoin(Thread* thread) {
|
||||||
return threadJoin(thread, U64_MAX);
|
return threadJoin(*thread, U64_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void ThreadSetName(const char* name) {
|
static inline void ThreadSetName(const char* name) {
|
||||||
|
|
|
@ -80,8 +80,8 @@ static inline int ThreadCreate(Thread* thread, ThreadEntry entry, void* context)
|
||||||
return pthread_create(thread, 0, entry, context);
|
return pthread_create(thread, 0, entry, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int ThreadJoin(Thread thread) {
|
static inline int ThreadJoin(Thread* thread) {
|
||||||
return pthread_join(thread, 0);
|
return pthread_join(*thread, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int ThreadSetName(const char* name) {
|
static inline int ThreadSetName(const char* name) {
|
||||||
|
|
|
@ -131,12 +131,12 @@ static inline int ThreadCreate(Thread* thread, ThreadEntry entry, void* context)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int ThreadJoin(Thread thread) {
|
static inline int ThreadJoin(Thread* thread) {
|
||||||
int res = sceKernelWaitThreadEnd(thread, 0, 0);
|
int res = sceKernelWaitThreadEnd(*thread, 0, 0);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
return sceKernelDeleteThread(thread);
|
return sceKernelDeleteThread(*thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int ThreadSetName(const char* name) {
|
static inline int ThreadSetName(const char* name) {
|
||||||
|
|
|
@ -71,12 +71,12 @@ static inline int ThreadCreate(Thread* thread, ThreadEntry entry, void* context)
|
||||||
return threadStart(thread);
|
return threadStart(thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int ThreadJoin(Thread thread) {
|
static inline int ThreadJoin(Thread* thread) {
|
||||||
int res = threadWaitForExit(&thread);
|
int res = threadWaitForExit(thread);
|
||||||
if(R_FAILED(res)) {
|
if(R_FAILED(res)) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
return threadClose(&thread);
|
return threadClose(thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void ThreadSetName(const char* name) {
|
static inline void ThreadSetName(const char* name) {
|
||||||
|
|
|
@ -75,8 +75,8 @@ static inline int ThreadCreate(Thread* thread, ThreadEntry entry, void* context)
|
||||||
return GetLastError();
|
return GetLastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int ThreadJoin(Thread thread) {
|
static inline int ThreadJoin(Thread* thread) {
|
||||||
DWORD error = WaitForSingleObject(thread, INFINITE);
|
DWORD error = WaitForSingleObject(*thread, INFINITE);
|
||||||
if (error == WAIT_FAILED) {
|
if (error == WAIT_FAILED) {
|
||||||
return GetLastError();
|
return GetLastError();
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,16 @@ CXX_GUARD_START
|
||||||
#ifdef _3DS
|
#ifdef _3DS
|
||||||
// ctrulib already has a type called Thread
|
// ctrulib already has a type called Thread
|
||||||
#include <3ds/thread.h>
|
#include <3ds/thread.h>
|
||||||
|
#elif defined(__SWITCH__)
|
||||||
|
#include <switch/kernel/thread.h>
|
||||||
#else
|
#else
|
||||||
typedef void* Thread;
|
typedef void* Thread;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef __SWITCH__
|
||||||
|
#include <switch/kernel/mutex.h>
|
||||||
|
#else
|
||||||
typedef void* Mutex;
|
typedef void* Mutex;
|
||||||
|
#endif
|
||||||
typedef void* Condition;
|
typedef void* Condition;
|
||||||
|
|
||||||
static inline int MutexInit(Mutex* mutex) {
|
static inline int MutexInit(Mutex* mutex) {
|
||||||
|
|
|
@ -53,7 +53,7 @@ void mCoreRewindContextDeinit(struct mCoreRewindContext* context) {
|
||||||
context->onThread = false;
|
context->onThread = false;
|
||||||
MutexUnlock(&context->mutex);
|
MutexUnlock(&context->mutex);
|
||||||
ConditionWake(&context->cond);
|
ConditionWake(&context->cond);
|
||||||
ThreadJoin(context->thread);
|
ThreadJoin(&context->thread);
|
||||||
MutexDeinit(&context->mutex);
|
MutexDeinit(&context->mutex);
|
||||||
ConditionDeinit(&context->cond);
|
ConditionDeinit(&context->cond);
|
||||||
}
|
}
|
||||||
|
|
|
@ -413,7 +413,7 @@ void mCoreThreadJoin(struct mCoreThread* threadContext) {
|
||||||
if (!threadContext->impl) {
|
if (!threadContext->impl) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ThreadJoin(threadContext->impl->thread);
|
ThreadJoin(&threadContext->impl->thread);
|
||||||
|
|
||||||
MutexDeinit(&threadContext->impl->stateMutex);
|
MutexDeinit(&threadContext->impl->stateMutex);
|
||||||
ConditionDeinit(&threadContext->impl->stateCond);
|
ConditionDeinit(&threadContext->impl->stateCond);
|
||||||
|
|
|
@ -233,7 +233,7 @@ void mGUIDeinit(struct mGUIRunner* runner) {
|
||||||
ConditionWake(&runner->autosave.cond);
|
ConditionWake(&runner->autosave.cond);
|
||||||
MutexUnlock(&runner->autosave.mutex);
|
MutexUnlock(&runner->autosave.mutex);
|
||||||
|
|
||||||
ThreadJoin(runner->autosave.thread);
|
ThreadJoin(&runner->autosave.thread);
|
||||||
|
|
||||||
ConditionDeinit(&runner->autosave.cond);
|
ConditionDeinit(&runner->autosave.cond);
|
||||||
MutexDeinit(&runner->autosave.mutex);
|
MutexDeinit(&runner->autosave.mutex);
|
||||||
|
|
|
@ -78,7 +78,7 @@ void mVideoThreadProxyDeinit(struct mVideoLogger* logger) {
|
||||||
}
|
}
|
||||||
MutexUnlock(&proxyRenderer->mutex);
|
MutexUnlock(&proxyRenderer->mutex);
|
||||||
if (waiting) {
|
if (waiting) {
|
||||||
ThreadJoin(proxyRenderer->thread);
|
ThreadJoin(&proxyRenderer->thread);
|
||||||
}
|
}
|
||||||
RingFIFODeinit(&proxyRenderer->dirtyQueue);
|
RingFIFODeinit(&proxyRenderer->dirtyQueue);
|
||||||
ConditionDeinit(&proxyRenderer->fromThreadCond);
|
ConditionDeinit(&proxyRenderer->fromThreadCond);
|
||||||
|
@ -94,7 +94,7 @@ void _proxyThreadRecover(struct mVideoThreadProxy* proxyRenderer) {
|
||||||
}
|
}
|
||||||
RingFIFOClear(&proxyRenderer->dirtyQueue);
|
RingFIFOClear(&proxyRenderer->dirtyQueue);
|
||||||
MutexUnlock(&proxyRenderer->mutex);
|
MutexUnlock(&proxyRenderer->mutex);
|
||||||
ThreadJoin(proxyRenderer->thread);
|
ThreadJoin(&proxyRenderer->thread);
|
||||||
proxyRenderer->threadState = PROXY_THREAD_IDLE;
|
proxyRenderer->threadState = PROXY_THREAD_IDLE;
|
||||||
ThreadCreate(&proxyRenderer->thread, _proxyThread, proxyRenderer);
|
ThreadCreate(&proxyRenderer->thread, _proxyThread, proxyRenderer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -958,7 +958,7 @@ int main() {
|
||||||
Thread thread2;
|
Thread thread2;
|
||||||
if (ThreadCreate(&thread2, _core2Test, NULL) == 0) {
|
if (ThreadCreate(&thread2, _core2Test, NULL) == 0) {
|
||||||
core2 = true;
|
core2 = true;
|
||||||
ThreadJoin(thread2);
|
ThreadJoin(&thread2);
|
||||||
}
|
}
|
||||||
|
|
||||||
mGUIInit(&runner, "3ds");
|
mGUIInit(&runner, "3ds");
|
||||||
|
|
|
@ -420,7 +420,7 @@ void mPSP2UnloadROM(struct mGUIRunner* runner) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
audioContext.running = false;
|
audioContext.running = false;
|
||||||
ThreadJoin(audioThread);
|
ThreadJoin(&audioThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mPSP2Paused(struct mGUIRunner* runner) {
|
void mPSP2Paused(struct mGUIRunner* runner) {
|
||||||
|
|
Loading…
Reference in New Issue