Ensure interrupting the GBA thread actually gets to a safe point to read from the thread
Jeffrey Pfau jeffrey@endrift.com
Tue, 08 Jul 2014 00:04:38 -0700
3 files changed,
12 insertions(+),
7 deletions(-)
M
src/gba/gba-thread.c
→
src/gba/gba-thread.c
@@ -147,7 +147,11 @@ ARMRun(&cpu);
} } MutexLock(&threadContext->stateMutex); - while (threadContext->state == THREAD_PAUSED || threadContext->state == THREAD_INTERRUPTED) { + if (threadContext->state == THREAD_INTERRUPTED) { + threadContext->state = THREAD_PAUSED; + ConditionWake(&threadContext->stateCond); + } + while (threadContext->state == THREAD_PAUSED) { ConditionWait(&threadContext->stateCond, &threadContext->stateMutex); } MutexUnlock(&threadContext->stateMutex);@@ -276,11 +280,12 @@ }
free(threadContext->rewindBuffer); } -void GBAThreadInterrupt(struct GBAThread* threadContext) { +void GBAThreadTryPause(struct GBAThread* threadContext) { MutexLock(&threadContext->stateMutex); - _waitOnInterrupt(threadContext); threadContext->savedState = threadContext->state; threadContext->state = THREAD_INTERRUPTED; + _waitOnInterrupt(threadContext); + threadContext->state = THREAD_PAUSED; if (threadContext->debugger && threadContext->debugger->state == DEBUGGER_RUNNING) { threadContext->debugger->state = DEBUGGER_EXITING; }
M
src/gba/gba-thread.h
→
src/gba/gba-thread.h
@@ -82,7 +82,7 @@ int GBAThreadHasStarted(struct GBAThread* threadContext);
void GBAThreadEnd(struct GBAThread* threadContext); void GBAThreadJoin(struct GBAThread* threadContext); -void GBAThreadInterrupt(struct GBAThread* threadContext); +void GBAThreadTryPause(struct GBAThread* threadContext); void GBAThreadContinue(struct GBAThread* threadContext); void GBAThreadPause(struct GBAThread* threadContext);
M
src/platform/sdl/sdl-events.c
→
src/platform/sdl/sdl-events.c
@@ -95,7 +95,7 @@ case SDLK_TAB:
context->sync.audioWait = event->type != SDL_KEYDOWN; return; case SDLK_LEFTBRACKET: - GBAThreadInterrupt(context); + GBAThreadTryPause(context); GBARewind(context, 10); GBAThreadContinue(context); return;@@ -133,7 +133,7 @@ case SDLK_F7:
case SDLK_F8: case SDLK_F9: case SDLK_F10: - GBAThreadInterrupt(context); + GBAThreadTryPause(context); GBASaveState(context->gba, event->keysym.sym - SDLK_F1); GBAThreadContinue(context); break;@@ -152,7 +152,7 @@ case SDLK_F7:
case SDLK_F8: case SDLK_F9: case SDLK_F10: - GBAThreadInterrupt(context); + GBAThreadTryPause(context); GBALoadState(context->gba, event->keysym.sym - SDLK_F1); GBAThreadContinue(context); break;