From dc5c59d4dbe157bb1c6fe1e00c0893815723a16b Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Wed, 28 Jun 2017 13:07:39 -0700 Subject: [PATCH] Core: Fix interrupting a thread while on the thread (fixes #692) --- CHANGES | 1 + src/core/thread.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 55ce1fd69..0890adf9d 100644 --- a/CHANGES +++ b/CHANGES @@ -73,6 +73,7 @@ Bugfixes: - OpenGL: Fix some shaders causing offset graphics - Qt: Fix game unpausing after frame advancing and refocusing - GB Timer: Fix sub-M-cycle DIV reset timing and edge triggering + - Core: Fix interrupting a thread while on the thread (fixes mgba.io/i/692) Misc: - SDL: Remove scancode key input - GBA Video: Clean up unused timers diff --git a/src/core/thread.c b/src/core/thread.c index 424260b7e..ed979d77a 100644 --- a/src/core/thread.c +++ b/src/core/thread.c @@ -401,11 +401,14 @@ void mCoreThreadInterruptFromThread(struct mCoreThread* threadContext) { MutexLock(&threadContext->stateMutex); ++threadContext->interruptDepth; if (threadContext->interruptDepth > 1 || !mCoreThreadIsActive(threadContext)) { + if (threadContext->state == THREAD_INTERRUPTING) { + threadContext->state = THREAD_INTERRUPTED; + } MutexUnlock(&threadContext->stateMutex); return; } threadContext->savedState = threadContext->state; - threadContext->state = THREAD_INTERRUPTING; + threadContext->state = THREAD_INTERRUPTED; ConditionWake(&threadContext->stateCond); MutexUnlock(&threadContext->stateMutex); }