mirror of https://github.com/mgba-emu/mgba.git
Ensure interrupting the GBA thread actually gets to a safe point to read from the thread
This commit is contained in:
parent
8c9790bb3b
commit
a62a932282
|
@ -147,7 +147,11 @@ static THREAD_ENTRY _GBAThreadRun(void* context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MutexLock(&threadContext->stateMutex);
|
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);
|
ConditionWait(&threadContext->stateCond, &threadContext->stateMutex);
|
||||||
}
|
}
|
||||||
MutexUnlock(&threadContext->stateMutex);
|
MutexUnlock(&threadContext->stateMutex);
|
||||||
|
@ -276,11 +280,12 @@ void GBAThreadJoin(struct GBAThread* threadContext) {
|
||||||
free(threadContext->rewindBuffer);
|
free(threadContext->rewindBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBAThreadInterrupt(struct GBAThread* threadContext) {
|
void GBAThreadTryPause(struct GBAThread* threadContext) {
|
||||||
MutexLock(&threadContext->stateMutex);
|
MutexLock(&threadContext->stateMutex);
|
||||||
_waitOnInterrupt(threadContext);
|
|
||||||
threadContext->savedState = threadContext->state;
|
threadContext->savedState = threadContext->state;
|
||||||
threadContext->state = THREAD_INTERRUPTED;
|
threadContext->state = THREAD_INTERRUPTED;
|
||||||
|
_waitOnInterrupt(threadContext);
|
||||||
|
threadContext->state = THREAD_PAUSED;
|
||||||
if (threadContext->debugger && threadContext->debugger->state == DEBUGGER_RUNNING) {
|
if (threadContext->debugger && threadContext->debugger->state == DEBUGGER_RUNNING) {
|
||||||
threadContext->debugger->state = DEBUGGER_EXITING;
|
threadContext->debugger->state = DEBUGGER_EXITING;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ int GBAThreadHasStarted(struct GBAThread* threadContext);
|
||||||
void GBAThreadEnd(struct GBAThread* threadContext);
|
void GBAThreadEnd(struct GBAThread* threadContext);
|
||||||
void GBAThreadJoin(struct GBAThread* threadContext);
|
void GBAThreadJoin(struct GBAThread* threadContext);
|
||||||
|
|
||||||
void GBAThreadInterrupt(struct GBAThread* threadContext);
|
void GBAThreadTryPause(struct GBAThread* threadContext);
|
||||||
void GBAThreadContinue(struct GBAThread* threadContext);
|
void GBAThreadContinue(struct GBAThread* threadContext);
|
||||||
|
|
||||||
void GBAThreadPause(struct GBAThread* threadContext);
|
void GBAThreadPause(struct GBAThread* threadContext);
|
||||||
|
|
|
@ -95,7 +95,7 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, struct GBASDLEvents
|
||||||
context->sync.audioWait = event->type != SDL_KEYDOWN;
|
context->sync.audioWait = event->type != SDL_KEYDOWN;
|
||||||
return;
|
return;
|
||||||
case SDLK_LEFTBRACKET:
|
case SDLK_LEFTBRACKET:
|
||||||
GBAThreadInterrupt(context);
|
GBAThreadTryPause(context);
|
||||||
GBARewind(context, 10);
|
GBARewind(context, 10);
|
||||||
GBAThreadContinue(context);
|
GBAThreadContinue(context);
|
||||||
return;
|
return;
|
||||||
|
@ -133,7 +133,7 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, struct GBASDLEvents
|
||||||
case SDLK_F8:
|
case SDLK_F8:
|
||||||
case SDLK_F9:
|
case SDLK_F9:
|
||||||
case SDLK_F10:
|
case SDLK_F10:
|
||||||
GBAThreadInterrupt(context);
|
GBAThreadTryPause(context);
|
||||||
GBASaveState(context->gba, event->keysym.sym - SDLK_F1);
|
GBASaveState(context->gba, event->keysym.sym - SDLK_F1);
|
||||||
GBAThreadContinue(context);
|
GBAThreadContinue(context);
|
||||||
break;
|
break;
|
||||||
|
@ -152,7 +152,7 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, struct GBASDLEvents
|
||||||
case SDLK_F8:
|
case SDLK_F8:
|
||||||
case SDLK_F9:
|
case SDLK_F9:
|
||||||
case SDLK_F10:
|
case SDLK_F10:
|
||||||
GBAThreadInterrupt(context);
|
GBAThreadTryPause(context);
|
||||||
GBALoadState(context->gba, event->keysym.sym - SDLK_F1);
|
GBALoadState(context->gba, event->keysym.sym - SDLK_F1);
|
||||||
GBAThreadContinue(context);
|
GBAThreadContinue(context);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue