GBA Thread: Add a crashed state to the thread
Jeffrey Pfau jeffrey@endrift.com
Thu, 08 Jan 2015 20:04:44 -0800
4 files changed,
33 insertions(+),
9 deletions(-)
M
src/gba/gba-thread.c
→
src/gba/gba-thread.c
@@ -212,7 +212,7 @@ }
} } - while (threadContext->state != THREAD_SHUTDOWN) { + while (threadContext->state < THREAD_SHUTDOWN) { _changeState(threadContext, THREAD_SHUTDOWN, false); }@@ -354,6 +354,22 @@ MutexLock(&threadContext->stateMutex);
hasStarted = threadContext->state > THREAD_INITIALIZED; MutexUnlock(&threadContext->stateMutex); return hasStarted; +} + +bool GBAThreadHasExited(struct GBAThread* threadContext) { + bool hasExited; + MutexLock(&threadContext->stateMutex); + hasExited = threadContext->state > THREAD_EXITING; + MutexUnlock(&threadContext->stateMutex); + return hasExited; +} + +bool GBAThreadHasCrashed(struct GBAThread* threadContext) { + bool hasExited; + MutexLock(&threadContext->stateMutex); + hasExited = threadContext->state == THREAD_CRASHED; + MutexUnlock(&threadContext->stateMutex); + return hasExited; } void GBAThreadEnd(struct GBAThread* threadContext) {
M
src/gba/gba-thread.h
→
src/gba/gba-thread.h
@@ -28,7 +28,8 @@ THREAD_PAUSED,
THREAD_PAUSING, THREAD_RESETING, THREAD_EXITING, - THREAD_SHUTDOWN + THREAD_SHUTDOWN, + THREAD_CRASHED }; struct GBASync {@@ -107,6 +108,8 @@ void GBAMapArgumentsToContext(const struct GBAArguments*, struct GBAThread*);
bool GBAThreadStart(struct GBAThread* threadContext); bool GBAThreadHasStarted(struct GBAThread* threadContext); +bool GBAThreadHasExited(struct GBAThread* threadContext); +bool GBAThreadHasCrashed(struct GBAThread* threadContext); void GBAThreadEnd(struct GBAThread* threadContext); void GBAThreadReset(struct GBAThread* threadContext); void GBAThreadJoin(struct GBAThread* threadContext);
M
src/gba/gba.c
→
src/gba/gba.c
@@ -619,15 +619,23 @@ if (!(level & logLevel) && level != GBA_LOG_FATAL) {
return; } - if (threadContext && threadContext->logHandler) { - threadContext->logHandler(threadContext, level, format, args); - return; + gba->cpu->nextEvent = 0; + if (threadContext) { + if (level == GBA_LOG_FATAL) { + MutexLock(&threadContext->stateMutex); + threadContext->state = THREAD_CRASHED; + MutexUnlock(&threadContext->stateMutex); + } + if (threadContext->logHandler) { + threadContext->logHandler(threadContext, level, format, args); + return; + } } vprintf(format, args); printf("\n"); - if (level == GBA_LOG_FATAL) { + if (level == GBA_LOG_FATAL && !threadContext) { abort(); } }
M
src/platform/qt/GameController.cpp
→
src/platform/qt/GameController.cpp
@@ -109,9 +109,6 @@
m_threadContext.logHandler = [] (GBAThread* context, enum GBALogLevel level, const char* format, va_list args) { GameController* controller = static_cast<GameController*>(context->userData); if (level == GBA_LOG_FATAL) { - MutexLock(&controller->m_threadContext.stateMutex); - controller->m_threadContext.state = THREAD_EXITING; - MutexUnlock(&controller->m_threadContext.stateMutex); QMetaObject::invokeMethod(controller, "crashGame", Q_ARG(const QString&, QString().vsprintf(format, args))); } else if (!(controller->m_logLevels & level)) { return;