From 47ca1b1dda06c59c65b8380a0d0a0c82bd6047cd Mon Sep 17 00:00:00 2001 From: eladash Date: Mon, 11 Mar 2019 09:30:00 +0200 Subject: [PATCH] Minor optimizations in cellPad - Dont bother with shared_ptr since all pad_t management is going under the pad mutex. - Change m_pads type into std::array since its size is known --- rpcs3/Emu/Cell/Modules/cellPad.cpp | 30 +++++++++++++++--------------- rpcs3/pad_thread.cpp | 9 ++++----- rpcs3/pad_thread.h | 4 ++-- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellPad.cpp b/rpcs3/Emu/Cell/Modules/cellPad.cpp index e4973d5961..3b58c7e44b 100644 --- a/rpcs3/Emu/Cell/Modules/cellPad.cpp +++ b/rpcs3/Emu/Cell/Modules/cellPad.cpp @@ -66,7 +66,7 @@ error_code cellPadClearBuf(u32 port_no) std::lock_guard lock(pad::g_pad_mutex); - const auto config = fxm::get(); + const auto config = fxm::check(); if (!config) return CELL_PAD_ERROR_UNINITIALIZED; @@ -110,7 +110,7 @@ error_code cellPadGetData(u32 port_no, vm::ptr data) std::lock_guard lock(pad::g_pad_mutex); - const auto config = fxm::get(); + const auto config = fxm::check(); if (!config) return CELL_PAD_ERROR_UNINITIALIZED; @@ -363,7 +363,7 @@ error_code cellPadPeriphGetInfo(vm::ptr info) std::lock_guard lock(pad::g_pad_mutex); - const auto config = fxm::get(); + const auto config = fxm::check(); if (!config) return CELL_PAD_ERROR_UNINITIALIZED; @@ -407,7 +407,7 @@ error_code cellPadPeriphGetData(u32 port_no, vm::ptr data) std::lock_guard lock(pad::g_pad_mutex); - const auto config = fxm::get(); + const auto config = fxm::check(); if (!config) return CELL_PAD_ERROR_UNINITIALIZED; @@ -441,7 +441,7 @@ error_code cellPadGetRawData(u32 port_no, vm::ptr data) std::lock_guard lock(pad::g_pad_mutex); - const auto config = fxm::get(); + const auto config = fxm::check(); if (!config) return CELL_PAD_ERROR_UNINITIALIZED; @@ -472,7 +472,7 @@ error_code cellPadGetDataExtra(u32 port_no, vm::ptr device_type, vm::ptr(); + const auto config = fxm::check(); if (!config) return CELL_PAD_ERROR_UNINITIALIZED; @@ -513,7 +513,7 @@ error_code cellPadSetActDirect(u32 port_no, vm::ptr param) std::lock_guard lock(pad::g_pad_mutex); - const auto config = fxm::get(); + const auto config = fxm::check(); if (!config) return CELL_PAD_ERROR_UNINITIALIZED; @@ -553,7 +553,7 @@ error_code cellPadGetInfo(vm::ptr info) std::lock_guard lock(pad::g_pad_mutex); - const auto config = fxm::get(); + const auto config = fxm::check(); if (!config) return CELL_PAD_ERROR_UNINITIALIZED; @@ -608,7 +608,7 @@ error_code cellPadGetInfo2(vm::ptr info) std::lock_guard lock(pad::g_pad_mutex); - const auto config = fxm::get(); + const auto config = fxm::check(); if (!config) return CELL_PAD_ERROR_UNINITIALIZED; @@ -648,7 +648,7 @@ error_code cellPadGetCapabilityInfo(u32 port_no, vm::ptr std::lock_guard lock(pad::g_pad_mutex); - const auto config = fxm::get(); + const auto config = fxm::check(); if (!config) return CELL_PAD_ERROR_UNINITIALIZED; @@ -681,7 +681,7 @@ error_code cellPadSetPortSetting(u32 port_no, u32 port_setting) std::lock_guard lock(pad::g_pad_mutex); - const auto config = fxm::get(); + const auto config = fxm::check(); if (!config) return CELL_PAD_ERROR_UNINITIALIZED; @@ -708,7 +708,7 @@ s32 cellPadInfoPressMode(u32 port_no) std::lock_guard lock(pad::g_pad_mutex); - const auto config = fxm::get(); + const auto config = fxm::check(); if (!config) return CELL_PAD_ERROR_UNINITIALIZED; @@ -737,7 +737,7 @@ s32 cellPadInfoSensorMode(u32 port_no) std::lock_guard lock(pad::g_pad_mutex); - const auto config = fxm::get(); + const auto config = fxm::check(); if (!config) return CELL_PAD_ERROR_UNINITIALIZED; @@ -766,7 +766,7 @@ error_code cellPadSetPressMode(u32 port_no, u32 mode) std::lock_guard lock(pad::g_pad_mutex); - const auto config = fxm::get(); + const auto config = fxm::check(); if (!config) return CELL_PAD_ERROR_UNINITIALIZED; @@ -802,7 +802,7 @@ error_code cellPadSetSensorMode(u32 port_no, u32 mode) std::lock_guard lock(pad::g_pad_mutex); - const auto config = fxm::get(); + const auto config = fxm::check(); if (!config) return CELL_PAD_ERROR_UNINITIALIZED; diff --git a/rpcs3/pad_thread.cpp b/rpcs3/pad_thread.cpp index 831db36c70..cb4f81aab6 100644 --- a/rpcs3/pad_thread.cpp +++ b/rpcs3/pad_thread.cpp @@ -48,7 +48,7 @@ void pad_thread::Init() std::vector pad_settings; for (u32 i = 0; i < CELL_PAD_MAX_PORT_NUM; i++) // max 7 pads { - if (i >= m_pads.size()) + if (!m_pads[i]) { pad_settings.push_back({ CELL_PAD_STATUS_DISCONNECTED, CELL_PAD_CAPABILITY_PS3_CONFORMITY | CELL_PAD_CAPABILITY_PRESS_MODE | CELL_PAD_CAPABILITY_ACTUATOR, CELL_PAD_DEV_TYPE_STANDARD }); } @@ -63,7 +63,6 @@ void pad_thread::Init() m_info.now_connect = 0; m_info.system_info |= system_info; - m_pads.clear(); handlers.clear(); g_cfg_input.load(); @@ -120,13 +119,13 @@ void pad_thread::Init() } cur_pad_handler->Init(); - m_pads.push_back(std::make_shared(CELL_PAD_STATUS_DISCONNECTED, pad_settings[i].device_capability, pad_settings[i].device_type)); + m_pads[i] = std::make_shared(CELL_PAD_STATUS_DISCONNECTED, pad_settings[i].device_capability, pad_settings[i].device_type); - if (cur_pad_handler->bindPadToDevice(m_pads.back(), g_cfg_input.player[i]->device.to_string()) == false) + if (cur_pad_handler->bindPadToDevice(m_pads[i], g_cfg_input.player[i]->device.to_string()) == false) { // Failed to bind the device to cur_pad_handler so binds to NullPadHandler LOG_ERROR(GENERAL, "Failed to bind device %s to handler %s", g_cfg_input.player[i]->device.to_string(), handler_type.to_string()); - nullpad->bindPadToDevice(m_pads.back(), g_cfg_input.player[i]->device.to_string()); + nullpad->bindPadToDevice(m_pads[i], g_cfg_input.player[i]->device.to_string()); } } } diff --git a/rpcs3/pad_thread.h b/rpcs3/pad_thread.h index 37efebc081..e918366bd4 100644 --- a/rpcs3/pad_thread.h +++ b/rpcs3/pad_thread.h @@ -20,7 +20,7 @@ public: ~pad_thread(); PadInfo& GetInfo() { return m_info; } - std::vector>& GetPads() { return m_pads; } + auto& GetPads() { return m_pads; } void SetRumble(const u32 pad, u8 largeMotor, bool smallMotor); void Init(); void Reset(); @@ -38,7 +38,7 @@ protected: void *curwindow; PadInfo m_info{ 0, 0 }; - std::vector> m_pads; + std::array, CELL_PAD_MAX_PORT_NUM> m_pads; atomic_t active{ false }; atomic_t reset{ false };