From efaa2a67914962c1d193f227ce051f6b323a96c4 Mon Sep 17 00:00:00 2001 From: cathery Date: Thu, 20 Feb 2020 03:27:19 +0300 Subject: [PATCH] Use ams::StaticThread instead of SwitchThread in SwitchVirtualGamepadHandler --- .../SwitchVirtualGamepadHandler.cpp | 34 +++++++++++-------- .../SwitchVirtualGamepadHandler.h | 9 +++-- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/source/ControllerSwitch/SwitchVirtualGamepadHandler.cpp b/source/ControllerSwitch/SwitchVirtualGamepadHandler.cpp index bd64fe4..969e8aa 100644 --- a/source/ControllerSwitch/SwitchVirtualGamepadHandler.cpp +++ b/source/ControllerSwitch/SwitchVirtualGamepadHandler.cpp @@ -20,38 +20,44 @@ void SwitchVirtualGamepadHandler::Exit() void SwitchVirtualGamepadHandler::InputThreadLoop(void *handler) { - static_cast(handler)->UpdateInput(); + while (static_cast(handler)->m_inputThreadIsRunning) + { + static_cast(handler)->UpdateInput(); + } } void SwitchVirtualGamepadHandler::OutputThreadLoop(void *handler) { - static_cast(handler)->UpdateOutput(); + while (static_cast(handler)->m_outputThreadIsRunning) + { + static_cast(handler)->UpdateOutput(); + } } Result SwitchVirtualGamepadHandler::InitInputThread() { - Result rc = m_inputThread.Initialize(0x400, 0x3B); - if (R_SUCCEEDED(rc)) - rc = m_inputThread.Start(&SwitchVirtualGamepadHandler::InputThreadLoop, this); - - return rc; + R_TRY(m_inputThread.Initialize(&SwitchVirtualGamepadHandler::InputThreadLoop, this, 0x3B).GetValue()); + m_inputThreadIsRunning = true; + return m_inputThread.Start().GetValue(); } void SwitchVirtualGamepadHandler::ExitInputThread() { - m_inputThread.Exit(); + m_inputThreadIsRunning = false; + m_inputThread.CancelSynchronization(); + m_inputThread.Join(); } Result SwitchVirtualGamepadHandler::InitOutputThread() { - Result rc = m_outputThread.Initialize(0x400, 0x3B); - if (R_SUCCEEDED(rc)) - rc = m_outputThread.Start(&SwitchVirtualGamepadHandler::OutputThreadLoop, this); - - return rc; + R_TRY(m_outputThread.Initialize(&SwitchVirtualGamepadHandler::OutputThreadLoop, this, 0x3B).GetValue()); + m_outputThreadIsRunning = true; + return m_outputThread.Start().GetValue(); } void SwitchVirtualGamepadHandler::ExitOutputThread() { - m_outputThread.Exit(); + m_outputThreadIsRunning = false; + m_outputThread.CancelSynchronization(); + m_outputThread.Join(); } \ No newline at end of file diff --git a/source/ControllerSwitch/SwitchVirtualGamepadHandler.h b/source/ControllerSwitch/SwitchVirtualGamepadHandler.h index 7d20f59..10a45f2 100644 --- a/source/ControllerSwitch/SwitchVirtualGamepadHandler.h +++ b/source/ControllerSwitch/SwitchVirtualGamepadHandler.h @@ -2,7 +2,7 @@ #include "switch.h" #include "IController.h" #include "SwitchControllerHandler.h" -#include "SwitchThread.h" +#include //This class is a base class for SwitchHDLHandler and SwitchAbstractedPaadHandler. class SwitchVirtualGamepadHandler @@ -11,8 +11,11 @@ protected: u32 m_vibrationDeviceHandle; SwitchControllerHandler m_controllerHandler; - SwitchThread m_inputThread; - SwitchThread m_outputThread; + ams::os::StaticThread<0x1'000> m_inputThread; + ams::os::StaticThread<0x1'000> m_outputThread; + + bool m_inputThreadIsRunning = false; + bool m_outputThreadIsRunning = false; static void InputThreadLoop(void *argument); static void OutputThreadLoop(void *argument);