From f77ba7ba3ac72e52cac8c0f7dd62ec7ffd5e7a3b Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 11 Sep 2016 18:59:06 +0200 Subject: [PATCH] Make the last commit slightly safer by adding a mutex --- UI/ControlMappingScreen.cpp | 8 ++++++++ UI/ControlMappingScreen.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index 03a95e82eb..8086cf59d6 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -18,6 +18,7 @@ #include #include +#include "base/mutex.h" #include "base/colorutil.h" #include "base/logging.h" #include "i18n/i18n.h" @@ -437,6 +438,9 @@ bool AnalogTestScreen::key(const KeyInput &key) { screenManager()->finishDialog(this, DR_BACK); return true; } + + lock_guard guard(eventLock_); + char buf[512]; snprintf(buf, sizeof(buf), "Keycode: %d Device ID: %d [%s%s%s%s]", key.keyCode, key.deviceId, (key.flags & KEY_IS_REPEAT) ? "REP" : "", @@ -457,6 +461,8 @@ bool AnalogTestScreen::axis(const AxisInput &axis) { // a controller would be confusing for the user. char buf[512]; + lock_guard guard(eventLock_); + if (IgnoreAxisForMapping(axis.axisId)) return false; @@ -476,6 +482,8 @@ bool AnalogTestScreen::axis(const AxisInput &axis) { void AnalogTestScreen::CreateViews() { using namespace UI; + lock_guard guard(eventLock_); + I18NCategory *di = GetI18NCategory("Dialog"); root_ = new LinearLayout(ORIENT_VERTICAL); diff --git a/UI/ControlMappingScreen.h b/UI/ControlMappingScreen.h index b971839906..69fd34e73a 100644 --- a/UI/ControlMappingScreen.h +++ b/UI/ControlMappingScreen.h @@ -19,6 +19,7 @@ #include #include "base/functional.h" +#include "base/mutex.h" #include "ui/view.h" #include "ui/ui_screen.h" @@ -80,4 +81,6 @@ protected: UI::TextView *lastKeyEvent_; UI::TextView *lastLastKeyEvent_; + + recursive_mutex eventLock_; };