From e08fbfd0af59cb658df525144ac33ba27c0ba52f Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 28 Apr 2014 23:42:17 -0700 Subject: [PATCH] Fix hang on stop before run w/ multithreading. And clarify logic. --- Core/ThreadEventQueue.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Core/ThreadEventQueue.h b/Core/ThreadEventQueue.h index 3d594f52e6..3fdc0d043a 100644 --- a/Core/ThreadEventQueue.h +++ b/Core/ThreadEventQueue.h @@ -112,6 +112,22 @@ struct ThreadEventQueue : public B { eventsHaveRun_ = false; } + inline bool ShouldSyncThread(bool force) { + if (!HasEvents()) + return false; + if (coreState != CORE_RUNNING && !force) + return false; + + // Don't run if it's not running, but wait for startup. + if (!eventsRunning_) { + if (eventsHaveRun_ || coreState == CORE_ERROR || coreState == CORE_POWERDOWN) { + return false; + } + } + + return true; + } + // Force ignores coreState. void SyncThread(bool force = false) { if (!threadEnabled_) { @@ -122,7 +138,7 @@ struct ThreadEventQueue : public B { // While processing the last event, HasEvents() will be false even while not done. // So we schedule a nothing event and wait for that to finish. ScheduleEvent(EVENT_SYNC); - while (HasEvents() && (eventsRunning_ || !eventsHaveRun_) && (force || coreState == CORE_RUNNING)) { + while (ShouldSyncThread(force)) { eventsDrain_.wait(eventsLock_); } }