mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2024-11-25 15:15:41 +01:00
service: hid: Remove data races when handling shared memory
This commit is contained in:
parent
6a244465ce
commit
5562322290
@ -21,10 +21,11 @@ void CaptureButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::scoped_lock shared_lock{*shared_mutex};
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
|
||||
if (data == nullptr) {
|
||||
if (data == nullptr || !data->flag.is_assigned) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -20,10 +20,11 @@ void ConsoleSixAxis::OnInit() {}
|
||||
void ConsoleSixAxis::OnRelease() {}
|
||||
|
||||
void ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
std::scoped_lock shared_lock{*shared_mutex};
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
|
||||
if (data == nullptr) {
|
||||
if (data == nullptr || !data->flag.is_assigned) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,10 @@ bool ControllerBase::IsControllerActivated() const {
|
||||
return is_activated;
|
||||
}
|
||||
|
||||
void ControllerBase::SetAppletResource(std::shared_ptr<AppletResource> resource) {
|
||||
void ControllerBase::SetAppletResource(std::shared_ptr<AppletResource> resource,
|
||||
std::recursive_mutex* resource_mutex) {
|
||||
applet_resource = resource;
|
||||
shared_mutex = resource_mutex;
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
||||
|
@ -42,11 +42,13 @@ public:
|
||||
|
||||
bool IsControllerActivated() const;
|
||||
|
||||
void SetAppletResource(std::shared_ptr<AppletResource> resource);
|
||||
void SetAppletResource(std::shared_ptr<AppletResource> resource,
|
||||
std::recursive_mutex* resource_mutex);
|
||||
|
||||
protected:
|
||||
bool is_activated{false};
|
||||
std::shared_ptr<AppletResource> applet_resource{nullptr};
|
||||
std::recursive_mutex* shared_mutex{nullptr};
|
||||
|
||||
Core::HID::HIDCore& hid_core;
|
||||
};
|
||||
|
@ -21,10 +21,11 @@ void DebugMouse::OnInit() {}
|
||||
void DebugMouse::OnRelease() {}
|
||||
|
||||
void DebugMouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
std::scoped_lock shared_lock{*shared_mutex};
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
|
||||
if (data == nullptr) {
|
||||
if (data == nullptr || !data->flag.is_assigned) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -23,10 +23,11 @@ void DebugPad::OnInit() {}
|
||||
void DebugPad::OnRelease() {}
|
||||
|
||||
void DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
std::scoped_lock shared_lock{*shared_mutex};
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
|
||||
if (data == nullptr) {
|
||||
if (data == nullptr || !data->flag.is_assigned) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,11 @@ void Digitizer::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::scoped_lock shared_lock{*shared_mutex};
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
|
||||
if (data == nullptr) {
|
||||
if (data == nullptr || !data->flag.is_assigned) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -28,10 +28,11 @@ Gesture::Gesture(Core::HID::HIDCore& hid_core_) : ControllerBase(hid_core_) {
|
||||
Gesture::~Gesture() = default;
|
||||
|
||||
void Gesture::OnInit() {
|
||||
std::scoped_lock shared_lock{*shared_mutex};
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
|
||||
if (data == nullptr) {
|
||||
if (data == nullptr || !data->flag.is_assigned) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -44,10 +45,11 @@ void Gesture::OnInit() {
|
||||
void Gesture::OnRelease() {}
|
||||
|
||||
void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
std::scoped_lock shared_lock{*shared_mutex};
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
|
||||
if (data == nullptr) {
|
||||
if (data == nullptr || !data->flag.is_assigned) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,11 @@ void HomeButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::scoped_lock shared_lock{*shared_mutex};
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
|
||||
if (data == nullptr) {
|
||||
if (data == nullptr || !data->flag.is_assigned) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -22,10 +22,11 @@ void Keyboard::OnInit() {}
|
||||
void Keyboard::OnRelease() {}
|
||||
|
||||
void Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
std::scoped_lock shared_lock{*shared_mutex};
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
|
||||
if (data == nullptr) {
|
||||
if (data == nullptr || !data->flag.is_assigned) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,11 @@ void Mouse::OnInit() {}
|
||||
void Mouse::OnRelease() {}
|
||||
|
||||
void Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
std::scoped_lock shared_lock{*shared_mutex};
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
|
||||
if (data == nullptr) {
|
||||
if (data == nullptr || !data->flag.is_assigned) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ void NPad::ControllerUpdate(Core::HID::ControllerTriggerType type, std::size_t c
|
||||
|
||||
auto* data = applet_resource_holder.applet_resource->GetAruidDataByIndex(aruid_index);
|
||||
|
||||
if (data->flag.is_assigned) {
|
||||
if (!data->flag.is_assigned) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -27,10 +27,11 @@ void SixAxis::OnInit() {}
|
||||
void SixAxis::OnRelease() {}
|
||||
|
||||
void SixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
std::scoped_lock shared_lock{*shared_mutex};
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
|
||||
if (data == nullptr) {
|
||||
if (data == nullptr || !data->flag.is_assigned) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,11 @@ void SleepButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::scoped_lock shared_lock{*shared_mutex};
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
|
||||
if (data == nullptr) {
|
||||
if (data == nullptr || !data->flag.is_assigned) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ void TouchScreen::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
|
||||
if (data == nullptr) {
|
||||
if (data == nullptr || !data->flag.is_assigned) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ void UniquePad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
|
||||
if (data == nullptr) {
|
||||
if (data == nullptr || !data->flag.is_assigned) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -171,31 +171,31 @@ void ResourceManager::InitializeHidCommonSampler() {
|
||||
palma = std::make_shared<Palma>(system.HIDCore(), service_context);
|
||||
six_axis = std::make_shared<SixAxis>(system.HIDCore(), npad);
|
||||
|
||||
debug_pad->SetAppletResource(applet_resource);
|
||||
digitizer->SetAppletResource(applet_resource);
|
||||
keyboard->SetAppletResource(applet_resource);
|
||||
debug_pad->SetAppletResource(applet_resource, &shared_mutex);
|
||||
digitizer->SetAppletResource(applet_resource, &shared_mutex);
|
||||
keyboard->SetAppletResource(applet_resource, &shared_mutex);
|
||||
npad->SetNpadExternals(applet_resource, &shared_mutex);
|
||||
six_axis->SetAppletResource(applet_resource);
|
||||
mouse->SetAppletResource(applet_resource);
|
||||
debug_mouse->SetAppletResource(applet_resource);
|
||||
home_button->SetAppletResource(applet_resource);
|
||||
sleep_button->SetAppletResource(applet_resource);
|
||||
capture_button->SetAppletResource(applet_resource);
|
||||
six_axis->SetAppletResource(applet_resource, &shared_mutex);
|
||||
mouse->SetAppletResource(applet_resource, &shared_mutex);
|
||||
debug_mouse->SetAppletResource(applet_resource, &shared_mutex);
|
||||
home_button->SetAppletResource(applet_resource, &shared_mutex);
|
||||
sleep_button->SetAppletResource(applet_resource, &shared_mutex);
|
||||
capture_button->SetAppletResource(applet_resource, &shared_mutex);
|
||||
}
|
||||
|
||||
void ResourceManager::InitializeTouchScreenSampler() {
|
||||
gesture = std::make_shared<Gesture>(system.HIDCore());
|
||||
touch_screen = std::make_shared<TouchScreen>(system.HIDCore());
|
||||
|
||||
touch_screen->SetAppletResource(applet_resource);
|
||||
gesture->SetAppletResource(applet_resource);
|
||||
touch_screen->SetAppletResource(applet_resource, &shared_mutex);
|
||||
gesture->SetAppletResource(applet_resource, &shared_mutex);
|
||||
}
|
||||
|
||||
void ResourceManager::InitializeConsoleSixAxisSampler() {
|
||||
console_six_axis = std::make_shared<ConsoleSixAxis>(system.HIDCore());
|
||||
seven_six_axis = std::make_shared<SevenSixAxis>(system);
|
||||
|
||||
console_six_axis->SetAppletResource(applet_resource);
|
||||
console_six_axis->SetAppletResource(applet_resource, &shared_mutex);
|
||||
}
|
||||
|
||||
void ResourceManager::InitializeAHidSampler() {
|
||||
|
Loading…
Reference in New Issue
Block a user