Switch: Fix threading-related crash on second launch

This commit is contained in:
Vicki Pfau 2019-05-26 14:26:35 -07:00
parent d839098cae
commit 1f2bd30b14
13 changed files with 26 additions and 19 deletions

View File

@ -20,6 +20,7 @@ Emulation fixes:
Other fixes:
- Qt: Fix some Qt display driver race conditions
- Core: Improved lockstep driver reliability (Le Hoang Quyen)
- Switch: Fix threading-related crash on second launch
Misc:
- GBA Savedata: EEPROM performance fixes
- GBA Savedata: Automatically map 1Mbit Flash files as 1Mbit Flash

View File

@ -98,8 +98,8 @@ static inline int ThreadCreate(Thread* thread, ThreadEntry entry, void* context)
return !*thread;
}
static inline int ThreadJoin(Thread thread) {
return threadJoin(thread, U64_MAX);
static inline int ThreadJoin(Thread* thread) {
return threadJoin(*thread, U64_MAX);
}
static inline void ThreadSetName(const char* name) {

View File

@ -80,8 +80,8 @@ static inline int ThreadCreate(Thread* thread, ThreadEntry entry, void* context)
return pthread_create(thread, 0, entry, context);
}
static inline int ThreadJoin(Thread thread) {
return pthread_join(thread, 0);
static inline int ThreadJoin(Thread* thread) {
return pthread_join(*thread, 0);
}
static inline int ThreadSetName(const char* name) {

View File

@ -131,12 +131,12 @@ static inline int ThreadCreate(Thread* thread, ThreadEntry entry, void* context)
return 0;
}
static inline int ThreadJoin(Thread thread) {
int res = sceKernelWaitThreadEnd(thread, 0, 0);
static inline int ThreadJoin(Thread* thread) {
int res = sceKernelWaitThreadEnd(*thread, 0, 0);
if (res < 0) {
return res;
}
return sceKernelDeleteThread(thread);
return sceKernelDeleteThread(*thread);
}
static inline int ThreadSetName(const char* name) {

View File

@ -71,12 +71,12 @@ static inline int ThreadCreate(Thread* thread, ThreadEntry entry, void* context)
return threadStart(thread);
}
static inline int ThreadJoin(Thread thread) {
int res = threadWaitForExit(&thread);
static inline int ThreadJoin(Thread* thread) {
int res = threadWaitForExit(thread);
if(R_FAILED(res)) {
return res;
}
return threadClose(&thread);
return threadClose(thread);
}
static inline void ThreadSetName(const char* name) {

View File

@ -75,8 +75,8 @@ static inline int ThreadCreate(Thread* thread, ThreadEntry entry, void* context)
return GetLastError();
}
static inline int ThreadJoin(Thread thread) {
DWORD error = WaitForSingleObject(thread, INFINITE);
static inline int ThreadJoin(Thread* thread) {
DWORD error = WaitForSingleObject(*thread, INFINITE);
if (error == WAIT_FAILED) {
return GetLastError();
}

View File

@ -29,10 +29,16 @@ CXX_GUARD_START
#ifdef _3DS
// ctrulib already has a type called Thread
#include <3ds/thread.h>
#elif defined(__SWITCH__)
#include <switch/kernel/thread.h>
#else
typedef void* Thread;
#endif
#ifdef __SWITCH__
#include <switch/kernel/mutex.h>
#else
typedef void* Mutex;
#endif
typedef void* Condition;
static inline int MutexInit(Mutex* mutex) {

View File

@ -53,7 +53,7 @@ void mCoreRewindContextDeinit(struct mCoreRewindContext* context) {
context->onThread = false;
MutexUnlock(&context->mutex);
ConditionWake(&context->cond);
ThreadJoin(context->thread);
ThreadJoin(&context->thread);
MutexDeinit(&context->mutex);
ConditionDeinit(&context->cond);
}

View File

@ -413,7 +413,7 @@ void mCoreThreadJoin(struct mCoreThread* threadContext) {
if (!threadContext->impl) {
return;
}
ThreadJoin(threadContext->impl->thread);
ThreadJoin(&threadContext->impl->thread);
MutexDeinit(&threadContext->impl->stateMutex);
ConditionDeinit(&threadContext->impl->stateCond);

View File

@ -233,7 +233,7 @@ void mGUIDeinit(struct mGUIRunner* runner) {
ConditionWake(&runner->autosave.cond);
MutexUnlock(&runner->autosave.mutex);
ThreadJoin(runner->autosave.thread);
ThreadJoin(&runner->autosave.thread);
ConditionDeinit(&runner->autosave.cond);
MutexDeinit(&runner->autosave.mutex);

View File

@ -78,7 +78,7 @@ void mVideoThreadProxyDeinit(struct mVideoLogger* logger) {
}
MutexUnlock(&proxyRenderer->mutex);
if (waiting) {
ThreadJoin(proxyRenderer->thread);
ThreadJoin(&proxyRenderer->thread);
}
RingFIFODeinit(&proxyRenderer->dirtyQueue);
ConditionDeinit(&proxyRenderer->fromThreadCond);
@ -94,7 +94,7 @@ void _proxyThreadRecover(struct mVideoThreadProxy* proxyRenderer) {
}
RingFIFOClear(&proxyRenderer->dirtyQueue);
MutexUnlock(&proxyRenderer->mutex);
ThreadJoin(proxyRenderer->thread);
ThreadJoin(&proxyRenderer->thread);
proxyRenderer->threadState = PROXY_THREAD_IDLE;
ThreadCreate(&proxyRenderer->thread, _proxyThread, proxyRenderer);
}

View File

@ -958,7 +958,7 @@ int main() {
Thread thread2;
if (ThreadCreate(&thread2, _core2Test, NULL) == 0) {
core2 = true;
ThreadJoin(thread2);
ThreadJoin(&thread2);
}
mGUIInit(&runner, "3ds");

View File

@ -420,7 +420,7 @@ void mPSP2UnloadROM(struct mGUIRunner* runner) {
break;
}
audioContext.running = false;
ThreadJoin(audioThread);
ThreadJoin(&audioThread);
}
void mPSP2Paused(struct mGUIRunner* runner) {