Fix hang on stop before run w/ multithreading.

And clarify logic.
This commit is contained in:
Unknown W. Brackets committed 2014-04-28 23:42:17 -07:00
1 parent d97c229eaf
commit e08fbfd0af
1 file changed
+17 -1
+17 -1
View File
@@ -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_);
}
}