Skip to content

Commit

Permalink
Really no need to hold eventMutex_ while dispatching events, only whe…
Browse files Browse the repository at this point in the history
…n interacting with the queue. Might fix further deadlocks (see #9698)
  • Loading branch information
hrydgard committed May 18, 2017
1 parent 85654aa commit ad84058
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions ext/native/ui/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace UI {
static View *focusedView;
static bool focusMovementEnabled;
bool focusForced;
static std::recursive_mutex eventMutex_; // needs recursivity!
static std::mutex eventMutex_; // needs recursivity!

const float ITEM_HEIGHT = 64.f;
const float MIN_TEXT_SCALE = 0.8f;
Expand All @@ -34,20 +34,24 @@ struct DispatchQueueItem {
std::deque<DispatchQueueItem> g_dispatchQueue;

void EventTriggered(Event *e, EventParams params) {
std::unique_lock<std::recursive_mutex> guard(eventMutex_);

DispatchQueueItem item;
item.e = e;
item.params = params;

std::unique_lock<std::mutex> guard(eventMutex_);
g_dispatchQueue.push_front(item);
}

void DispatchEvents() {
std::unique_lock<std::recursive_mutex> guard(eventMutex_);

while (!g_dispatchQueue.empty()) {
DispatchQueueItem item = g_dispatchQueue.back();
g_dispatchQueue.pop_back();
while (true) {
DispatchQueueItem item;
{

This comment has been minimized.

Copy link
@unknownbrackets

unknownbrackets May 20, 2017

Collaborator

Personally would prefer...

DispatchQueueItem item;
while (GetDispatchItem(item)) {

Always feel like stray curlies are a "suggestion" that a separate function might be a cleaner approach...

-[Unknown]

This comment has been minimized.

Copy link
@hrydgard

hrydgard May 21, 2017

Author Owner

Yeah, that'd be a little nicer, I agree.

std::unique_lock<std::mutex> guard(eventMutex_);
if (g_dispatchQueue.empty())
break;
item = g_dispatchQueue.back();
g_dispatchQueue.pop_back();
}
if (item.e) {
item.e->Dispatch(item.params);
}
Expand Down

0 comments on commit ad84058

Please sign in to comment.