From effcee475b443374edb8e95aec6d8b4b0f93a7fb Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 28 Apr 2014 22:12:33 -0700 Subject: [PATCH] Fix another race condition. If EVENT_FINISH is received, but coreState is still CORE_RUNNING and the thread is still enabled, it would hang. Makes more sense to wait for events before processing them anyhow... --- Core/ThreadEventQueue.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Core/ThreadEventQueue.h b/Core/ThreadEventQueue.h index f18a2df4f1..3d594f52e6 100644 --- a/Core/ThreadEventQueue.h +++ b/Core/ThreadEventQueue.h @@ -75,6 +75,10 @@ struct ThreadEventQueue : public B { eventsHaveRun_ = true; do { + if (!HasEvents()) { + eventsWait_.wait(eventsLock_); + } + for (Event ev = GetNextEvent(); EventType(ev) != EVENT_INVALID; ev = GetNextEvent()) { eventsLock_.unlock(); switch (EventType(ev)) { @@ -96,11 +100,6 @@ struct ThreadEventQueue : public B { if (ShouldExitEventLoop() || !threadEnabled_) { break; } - - // coreState changes won't wake us, so recheck periodically. - if (!HasEvents()) { - eventsWait_.wait(eventsLock_); - } } while (CoreTiming::GetTicks() < globalticks); // This will force the waiter to check coreState, even if we didn't actually drain.