diff options
Diffstat (limited to 'src/input_common/input_engine.cpp')
-rw-r--r-- | src/input_common/input_engine.cpp | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/src/input_common/input_engine.cpp b/src/input_common/input_engine.cpp index 738022ece..12214d146 100644 --- a/src/input_common/input_engine.cpp +++ b/src/input_common/input_engine.cpp @@ -1,6 +1,5 @@ -// Copyright 2021 yuzu Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included +// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later #include "common/logging/log.h" #include "input_common/input_engine.h" @@ -8,37 +7,37 @@ namespace InputCommon { void InputEngine::PreSetController(const PadIdentifier& identifier) { - std::lock_guard lock{mutex}; + std::scoped_lock lock{mutex}; controller_list.try_emplace(identifier); } void InputEngine::PreSetButton(const PadIdentifier& identifier, int button) { - std::lock_guard lock{mutex}; + std::scoped_lock lock{mutex}; ControllerData& controller = controller_list.at(identifier); controller.buttons.try_emplace(button, false); } void InputEngine::PreSetHatButton(const PadIdentifier& identifier, int button) { - std::lock_guard lock{mutex}; + std::scoped_lock lock{mutex}; ControllerData& controller = controller_list.at(identifier); controller.hat_buttons.try_emplace(button, u8{0}); } void InputEngine::PreSetAxis(const PadIdentifier& identifier, int axis) { - std::lock_guard lock{mutex}; + std::scoped_lock lock{mutex}; ControllerData& controller = controller_list.at(identifier); controller.axes.try_emplace(axis, 0.0f); } void InputEngine::PreSetMotion(const PadIdentifier& identifier, int motion) { - std::lock_guard lock{mutex}; + std::scoped_lock lock{mutex}; ControllerData& controller = controller_list.at(identifier); controller.motions.try_emplace(motion); } void InputEngine::SetButton(const PadIdentifier& identifier, int button, bool value) { { - std::lock_guard lock{mutex}; + std::scoped_lock lock{mutex}; ControllerData& controller = controller_list.at(identifier); if (!configuring) { controller.buttons.insert_or_assign(button, value); @@ -49,7 +48,7 @@ void InputEngine::SetButton(const PadIdentifier& identifier, int button, bool va void InputEngine::SetHatButton(const PadIdentifier& identifier, int button, u8 value) { { - std::lock_guard lock{mutex}; + std::scoped_lock lock{mutex}; ControllerData& controller = controller_list.at(identifier); if (!configuring) { controller.hat_buttons.insert_or_assign(button, value); @@ -60,7 +59,7 @@ void InputEngine::SetHatButton(const PadIdentifier& identifier, int button, u8 v void InputEngine::SetAxis(const PadIdentifier& identifier, int axis, f32 value) { { - std::lock_guard lock{mutex}; + std::scoped_lock lock{mutex}; ControllerData& controller = controller_list.at(identifier); if (!configuring) { controller.axes.insert_or_assign(axis, value); @@ -71,7 +70,7 @@ void InputEngine::SetAxis(const PadIdentifier& identifier, int axis, f32 value) void InputEngine::SetBattery(const PadIdentifier& identifier, Common::Input::BatteryLevel value) { { - std::lock_guard lock{mutex}; + std::scoped_lock lock{mutex}; ControllerData& controller = controller_list.at(identifier); if (!configuring) { controller.battery = value; @@ -82,7 +81,7 @@ void InputEngine::SetBattery(const PadIdentifier& identifier, Common::Input::Bat void InputEngine::SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value) { { - std::lock_guard lock{mutex}; + std::scoped_lock lock{mutex}; ControllerData& controller = controller_list.at(identifier); if (!configuring) { controller.motions.insert_or_assign(motion, value); @@ -92,7 +91,7 @@ void InputEngine::SetMotion(const PadIdentifier& identifier, int motion, const B } bool InputEngine::GetButton(const PadIdentifier& identifier, int button) const { - std::lock_guard lock{mutex}; + std::scoped_lock lock{mutex}; const auto controller_iter = controller_list.find(identifier); if (controller_iter == controller_list.cend()) { LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), @@ -109,7 +108,7 @@ bool InputEngine::GetButton(const PadIdentifier& identifier, int button) const { } bool InputEngine::GetHatButton(const PadIdentifier& identifier, int button, u8 direction) const { - std::lock_guard lock{mutex}; + std::scoped_lock lock{mutex}; const auto controller_iter = controller_list.find(identifier); if (controller_iter == controller_list.cend()) { LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), @@ -126,7 +125,7 @@ bool InputEngine::GetHatButton(const PadIdentifier& identifier, int button, u8 d } f32 InputEngine::GetAxis(const PadIdentifier& identifier, int axis) const { - std::lock_guard lock{mutex}; + std::scoped_lock lock{mutex}; const auto controller_iter = controller_list.find(identifier); if (controller_iter == controller_list.cend()) { LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), @@ -143,7 +142,7 @@ f32 InputEngine::GetAxis(const PadIdentifier& identifier, int axis) const { } Common::Input::BatteryLevel InputEngine::GetBattery(const PadIdentifier& identifier) const { - std::lock_guard lock{mutex}; + std::scoped_lock lock{mutex}; const auto controller_iter = controller_list.find(identifier); if (controller_iter == controller_list.cend()) { LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), @@ -155,7 +154,7 @@ Common::Input::BatteryLevel InputEngine::GetBattery(const PadIdentifier& identif } BasicMotion InputEngine::GetMotion(const PadIdentifier& identifier, int motion) const { - std::lock_guard lock{mutex}; + std::scoped_lock lock{mutex}; const auto controller_iter = controller_list.find(identifier); if (controller_iter == controller_list.cend()) { LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), @@ -186,7 +185,7 @@ void InputEngine::ResetAnalogState() { } void InputEngine::TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value) { - std::lock_guard lock{mutex_callback}; + std::scoped_lock lock{mutex_callback}; for (const auto& poller_pair : callback_list) { const InputIdentifier& poller = poller_pair.second; if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Button, button)) { @@ -214,7 +213,7 @@ void InputEngine::TriggerOnButtonChange(const PadIdentifier& identifier, int but } void InputEngine::TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value) { - std::lock_guard lock{mutex_callback}; + std::scoped_lock lock{mutex_callback}; for (const auto& poller_pair : callback_list) { const InputIdentifier& poller = poller_pair.second; if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::HatButton, button)) { @@ -243,7 +242,7 @@ void InputEngine::TriggerOnHatButtonChange(const PadIdentifier& identifier, int } void InputEngine::TriggerOnAxisChange(const PadIdentifier& identifier, int axis, f32 value) { - std::lock_guard lock{mutex_callback}; + std::scoped_lock lock{mutex_callback}; for (const auto& poller_pair : callback_list) { const InputIdentifier& poller = poller_pair.second; if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Analog, axis)) { @@ -270,7 +269,7 @@ void InputEngine::TriggerOnAxisChange(const PadIdentifier& identifier, int axis, void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier, [[maybe_unused]] Common::Input::BatteryLevel value) { - std::lock_guard lock{mutex_callback}; + std::scoped_lock lock{mutex_callback}; for (const auto& poller_pair : callback_list) { const InputIdentifier& poller = poller_pair.second; if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Battery, 0)) { @@ -284,7 +283,7 @@ void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier, void InputEngine::TriggerOnMotionChange(const PadIdentifier& identifier, int motion, const BasicMotion& value) { - std::lock_guard lock{mutex_callback}; + std::scoped_lock lock{mutex_callback}; for (const auto& poller_pair : callback_list) { const InputIdentifier& poller = poller_pair.second; if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Motion, motion)) { @@ -346,18 +345,18 @@ const std::string& InputEngine::GetEngineName() const { } int InputEngine::SetCallback(InputIdentifier input_identifier) { - std::lock_guard lock{mutex_callback}; + std::scoped_lock lock{mutex_callback}; callback_list.insert_or_assign(last_callback_key, std::move(input_identifier)); return last_callback_key++; } void InputEngine::SetMappingCallback(MappingCallback callback) { - std::lock_guard lock{mutex_callback}; + std::scoped_lock lock{mutex_callback}; mapping_callback = std::move(callback); } void InputEngine::DeleteCallback(int key) { - std::lock_guard lock{mutex_callback}; + std::scoped_lock lock{mutex_callback}; const auto& iterator = callback_list.find(key); if (iterator == callback_list.end()) { LOG_ERROR(Input, "Tried to delete non-existent callback {}", key); |