Skip to content

Commit

Permalink
Fix hang on stop before run w/ multithreading.
Browse files Browse the repository at this point in the history
And clarify logic.
  • Loading branch information
unknownbrackets committed Apr 29, 2014
1 parent d97c229 commit e08fbfd
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Core/ThreadEventQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand All @@ -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_);
}
}
Expand Down

0 comments on commit e08fbfd

Please sign in to comment.