diff options
| author | 2021-06-22 03:16:21 -0300 | |
|---|---|---|
| committer | 2021-06-22 03:16:21 -0300 | |
| commit | 15cc561d12719ef4e7bfc62701be88526f4869fe (patch) | |
| tree | 5476a0527b131d64cbde0b477c34fb9282e331b6 /src | |
| parent | Merge pull request #6499 from FernandoS27/we-were-on-a-break (diff) | |
| download | yuzu-15cc561d12719ef4e7bfc62701be88526f4869fe.tar.gz yuzu-15cc561d12719ef4e7bfc62701be88526f4869fe.tar.xz yuzu-15cc561d12719ef4e7bfc62701be88526f4869fe.zip | |
npad: Fix data race when updating devices
Add a lock to avoid data races.
This reduces the number of -fsanitize=thread errors significantly.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.h | 4 |
2 files changed, 8 insertions, 0 deletions
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 7acad3798..1eb02aee2 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp | |||
| @@ -314,6 +314,8 @@ void Controller_NPad::OnInit() { | |||
| 314 | 314 | ||
| 315 | void Controller_NPad::OnLoadInputDevices() { | 315 | void Controller_NPad::OnLoadInputDevices() { |
| 316 | const auto& players = Settings::values.players.GetValue(); | 316 | const auto& players = Settings::values.players.GetValue(); |
| 317 | |||
| 318 | std::lock_guard lock{mutex}; | ||
| 317 | for (std::size_t i = 0; i < players.size(); ++i) { | 319 | for (std::size_t i = 0; i < players.size(); ++i) { |
| 318 | std::transform(players[i].buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, | 320 | std::transform(players[i].buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, |
| 319 | players[i].buttons.begin() + Settings::NativeButton::BUTTON_HID_END, | 321 | players[i].buttons.begin() + Settings::NativeButton::BUTTON_HID_END, |
| @@ -348,6 +350,8 @@ void Controller_NPad::OnRelease() { | |||
| 348 | } | 350 | } |
| 349 | 351 | ||
| 350 | void Controller_NPad::RequestPadStateUpdate(u32 npad_id) { | 352 | void Controller_NPad::RequestPadStateUpdate(u32 npad_id) { |
| 353 | std::lock_guard lock{mutex}; | ||
| 354 | |||
| 351 | const auto controller_idx = NPadIdToIndex(npad_id); | 355 | const auto controller_idx = NPadIdToIndex(npad_id); |
| 352 | const auto controller_type = connected_controllers[controller_idx].type; | 356 | const auto controller_type = connected_controllers[controller_idx].type; |
| 353 | if (!connected_controllers[controller_idx].is_connected) { | 357 | if (!connected_controllers[controller_idx].is_connected) { |
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index c050c9a44..1409d82a2 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h | |||
| @@ -6,6 +6,8 @@ | |||
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <atomic> | 8 | #include <atomic> |
| 9 | #include <mutex> | ||
| 10 | |||
| 9 | #include "common/bit_field.h" | 11 | #include "common/bit_field.h" |
| 10 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 11 | #include "common/quaternion.h" | 13 | #include "common/quaternion.h" |
| @@ -563,6 +565,8 @@ private: | |||
| 563 | using MotionArray = std::array< | 565 | using MotionArray = std::array< |
| 564 | std::array<std::unique_ptr<Input::MotionDevice>, Settings::NativeMotion::NUM_MOTIONS_HID>, | 566 | std::array<std::unique_ptr<Input::MotionDevice>, Settings::NativeMotion::NUM_MOTIONS_HID>, |
| 565 | 10>; | 567 | 10>; |
| 568 | |||
| 569 | std::mutex mutex; | ||
| 566 | ButtonArray buttons; | 570 | ButtonArray buttons; |
| 567 | StickArray sticks; | 571 | StickArray sticks; |
| 568 | VibrationArray vibrations; | 572 | VibrationArray vibrations; |