From 288900ff7edd94ea58e93f4d1a6adc1101366a66 Mon Sep 17 00:00:00 2001 From: Gliniak Date: Sat, 24 Feb 2024 20:54:27 +0100 Subject: [PATCH] [HID] Removed controllers_mutex from SDL. Seems like it is unnecessary as there is some internal mutex that causes deadlocks with this one --- src/xenia/hid/sdl/sdl_input_driver.cc | 15 --------------- src/xenia/hid/sdl/sdl_input_driver.h | 1 - 2 files changed, 16 deletions(-) diff --git a/src/xenia/hid/sdl/sdl_input_driver.cc b/src/xenia/hid/sdl/sdl_input_driver.cc index b2728e5eb..b77bf6891 100644 --- a/src/xenia/hid/sdl/sdl_input_driver.cc +++ b/src/xenia/hid/sdl/sdl_input_driver.cc @@ -40,7 +40,6 @@ SDLInputDriver::SDLInputDriver(xe::ui::Window* window, size_t window_z_order) sdl_events_unflushed_(0), sdl_pumpevents_queued_(false), controllers_(), - controllers_mutex_(), keystroke_states_() {} SDLInputDriver::~SDLInputDriver() { @@ -151,8 +150,6 @@ X_RESULT SDLInputDriver::GetCapabilities(uint32_t user_index, uint32_t flags, QueueControllerUpdate(); - std::unique_lock guard(controllers_mutex_); - auto controller = GetControllerState(user_index); if (!controller) { return X_ERROR_DEVICE_NOT_CONNECTED; @@ -180,8 +177,6 @@ X_RESULT SDLInputDriver::GetState(uint32_t user_index, QueueControllerUpdate(); } - std::unique_lock guard(controllers_mutex_); - auto controller = GetControllerState(user_index); if (!controller) { return X_ERROR_DEVICE_NOT_CONNECTED; @@ -295,8 +290,6 @@ X_RESULT SDLInputDriver::GetKeystroke(uint32_t users, uint32_t flags, QueueControllerUpdate(); } - std::unique_lock guard(controllers_mutex_); - for (uint32_t user_index = (user_any ? 0 : users); user_index < (user_any ? HID_SDL_USER_COUNT : users + 1); user_index++) { auto controller = GetControllerState(user_index); @@ -420,8 +413,6 @@ void SDLInputDriver::HandleEvent(const SDL_Event& event) { } void SDLInputDriver::OnControllerDeviceAdded(const SDL_Event& event) { - std::unique_lock guard(controllers_mutex_); - // Open the controller. const auto controller = SDL_GameControllerOpen(event.cdevice.which); if (!controller) { @@ -485,8 +476,6 @@ void SDLInputDriver::OnControllerDeviceAdded(const SDL_Event& event) { } void SDLInputDriver::OnControllerDeviceRemoved(const SDL_Event& event) { - std::unique_lock guard(controllers_mutex_); - // Find the disconnected gamecontroller and close it. auto idx = GetControllerIndexFromInstanceID(event.cdevice.which); if (idx) { @@ -501,8 +490,6 @@ void SDLInputDriver::OnControllerDeviceRemoved(const SDL_Event& event) { } void SDLInputDriver::OnControllerDeviceAxisMotion(const SDL_Event& event) { - std::unique_lock guard(controllers_mutex_); - auto idx = GetControllerIndexFromInstanceID(event.caxis.which); assert(idx); auto& pad = controllers_.at(*idx).state.gamepad; @@ -533,8 +520,6 @@ void SDLInputDriver::OnControllerDeviceAxisMotion(const SDL_Event& event) { } void SDLInputDriver::OnControllerDeviceButtonChanged(const SDL_Event& event) { - std::unique_lock guard(controllers_mutex_); - // Define a lookup table to map between SDL and XInput button codes. // These need to be in the order of the SDL_GameControllerButton enum. static constexpr std::array< diff --git a/src/xenia/hid/sdl/sdl_input_driver.h b/src/xenia/hid/sdl/sdl_input_driver.h index de5c48e7c..1dfcd756b 100644 --- a/src/xenia/hid/sdl/sdl_input_driver.h +++ b/src/xenia/hid/sdl/sdl_input_driver.h @@ -84,7 +84,6 @@ class SDLInputDriver final : public InputDriver { int sdl_events_unflushed_; std::atomic sdl_pumpevents_queued_; std::array controllers_; - std::mutex controllers_mutex_; std::array keystroke_states_; };