Ensure interrupting the GBA thread actually gets to a safe point to read from the thread

This commit is contained in:
Jeffrey Pfau 2014-07-08 00:04:38 -07:00
parent 8c9790bb3b
commit a62a932282
3 changed files with 12 additions and 7 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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;