mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-11-27 11:04:23 +01:00
npad: Fix data race when updating devices
Add a lock to avoid data races. This reduces the number of -fsanitize=thread errors significantly.
This commit is contained in:
parent
0485b8e84b
commit
15cc561d12
@ -314,6 +314,8 @@ void Controller_NPad::OnInit() {
|
|||||||
|
|
||||||
void Controller_NPad::OnLoadInputDevices() {
|
void Controller_NPad::OnLoadInputDevices() {
|
||||||
const auto& players = Settings::values.players.GetValue();
|
const auto& players = Settings::values.players.GetValue();
|
||||||
|
|
||||||
|
std::lock_guard lock{mutex};
|
||||||
for (std::size_t i = 0; i < players.size(); ++i) {
|
for (std::size_t i = 0; i < players.size(); ++i) {
|
||||||
std::transform(players[i].buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN,
|
std::transform(players[i].buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN,
|
||||||
players[i].buttons.begin() + Settings::NativeButton::BUTTON_HID_END,
|
players[i].buttons.begin() + Settings::NativeButton::BUTTON_HID_END,
|
||||||
@ -348,6 +350,8 @@ void Controller_NPad::OnRelease() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Controller_NPad::RequestPadStateUpdate(u32 npad_id) {
|
void Controller_NPad::RequestPadStateUpdate(u32 npad_id) {
|
||||||
|
std::lock_guard lock{mutex};
|
||||||
|
|
||||||
const auto controller_idx = NPadIdToIndex(npad_id);
|
const auto controller_idx = NPadIdToIndex(npad_id);
|
||||||
const auto controller_type = connected_controllers[controller_idx].type;
|
const auto controller_type = connected_controllers[controller_idx].type;
|
||||||
if (!connected_controllers[controller_idx].is_connected) {
|
if (!connected_controllers[controller_idx].is_connected) {
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include "common/bit_field.h"
|
#include "common/bit_field.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/quaternion.h"
|
#include "common/quaternion.h"
|
||||||
@ -563,6 +565,8 @@ private:
|
|||||||
using MotionArray = std::array<
|
using MotionArray = std::array<
|
||||||
std::array<std::unique_ptr<Input::MotionDevice>, Settings::NativeMotion::NUM_MOTIONS_HID>,
|
std::array<std::unique_ptr<Input::MotionDevice>, Settings::NativeMotion::NUM_MOTIONS_HID>,
|
||||||
10>;
|
10>;
|
||||||
|
|
||||||
|
std::mutex mutex;
|
||||||
ButtonArray buttons;
|
ButtonArray buttons;
|
||||||
StickArray sticks;
|
StickArray sticks;
|
||||||
VibrationArray vibrations;
|
VibrationArray vibrations;
|
||||||
|
Loading…
Reference in New Issue
Block a user