diff --git a/src/gba/gba-thread.c b/src/gba/gba-thread.c index 23fa47c1b..a8292b7f6 100644 --- a/src/gba/gba-thread.c +++ b/src/gba/gba-thread.c @@ -147,7 +147,11 @@ static THREAD_ENTRY _GBAThreadRun(void* context) { } } 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 @@ void GBAThreadJoin(struct GBAThread* threadContext) { 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; } diff --git a/src/gba/gba-thread.h b/src/gba/gba-thread.h index 87fcfef31..249739d8f 100644 --- a/src/gba/gba-thread.h +++ b/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); diff --git a/src/platform/sdl/sdl-events.c b/src/platform/sdl/sdl-events.c index 889194671..74f2fddd4 100644 --- a/src/platform/sdl/sdl-events.c +++ b/src/platform/sdl/sdl-events.c @@ -95,7 +95,7 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, struct GBASDLEvents 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 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, struct GBASDLEvents 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 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, struct GBASDLEvents case SDLK_F8: case SDLK_F9: case SDLK_F10: - GBAThreadInterrupt(context); + GBAThreadTryPause(context); GBALoadState(context->gba, event->keysym.sym - SDLK_F1); GBAThreadContinue(context); break;