all repos — mgba @ 64ba9d2d8ec105b9e2aec816bb3440ae23888957

mGBA Game Boy Advance Emulator

GBA: Make sure interrupting the thread actually pauses it
Jeffrey Pfau jeffrey@endrift.com
Thu, 27 Nov 2014 00:06:49 -0800
commit

64ba9d2d8ec105b9e2aec816bb3440ae23888957

parent

22e7eff33cd2b2a42f4422acf51fa79c1ed64222

1 files changed, 16 insertions(+), 14 deletions(-)

jump to
M src/gba/gba-thread.csrc/gba/gba-thread.c

@@ -180,20 +180,22 @@ }

int resetScheduled = 0; MutexLock(&threadContext->stateMutex); - if (threadContext->state == THREAD_PAUSING) { - threadContext->state = THREAD_PAUSED; - ConditionWake(&threadContext->stateCond); - } - if (threadContext->state == THREAD_INTERRUPTING) { - threadContext->state = THREAD_INTERRUPTED; - ConditionWake(&threadContext->stateCond); - } - if (threadContext->state == THREAD_RESETING) { - threadContext->state = THREAD_RUNNING; - resetScheduled = 1; - } - while (threadContext->state == THREAD_PAUSED) { - ConditionWait(&threadContext->stateCond, &threadContext->stateMutex); + while (threadContext->state > THREAD_RUNNING && threadContext->state < THREAD_EXITING) { + if (threadContext->state == THREAD_PAUSING) { + threadContext->state = THREAD_PAUSED; + ConditionWake(&threadContext->stateCond); + } + if (threadContext->state == THREAD_INTERRUPTING) { + threadContext->state = THREAD_INTERRUPTED; + ConditionWake(&threadContext->stateCond); + } + if (threadContext->state == THREAD_RESETING) { + threadContext->state = THREAD_RUNNING; + resetScheduled = 1; + } + while (threadContext->state == THREAD_PAUSED || threadContext->state == THREAD_INTERRUPTED) { + ConditionWait(&threadContext->stateCond, &threadContext->stateMutex); + } } MutexUnlock(&threadContext->stateMutex); if (resetScheduled) {