From 6898d056d421857c5337d26e40af3b9ee2fdd8c1 Mon Sep 17 00:00:00 2001 From: cathery Date: Mon, 2 Mar 2020 18:21:40 +0300 Subject: [PATCH] while {} -> do {} while It makes more sense that all threads check if they can still run after they've completed their cycle, not before it --- .../ControllerSwitch/SwitchVirtualGamepadHandler.cpp | 10 ++++------ source/Sysmodule/source/config_handler.cpp | 5 ++--- source/Sysmodule/source/usb_module.cpp | 10 ++++------ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/source/ControllerSwitch/SwitchVirtualGamepadHandler.cpp b/source/ControllerSwitch/SwitchVirtualGamepadHandler.cpp index 969e8aa..765bce1 100644 --- a/source/ControllerSwitch/SwitchVirtualGamepadHandler.cpp +++ b/source/ControllerSwitch/SwitchVirtualGamepadHandler.cpp @@ -20,18 +20,16 @@ void SwitchVirtualGamepadHandler::Exit() void SwitchVirtualGamepadHandler::InputThreadLoop(void *handler) { - while (static_cast(handler)->m_inputThreadIsRunning) - { + do { static_cast(handler)->UpdateInput(); - } + } while (static_cast(handler)->m_inputThreadIsRunning); } void SwitchVirtualGamepadHandler::OutputThreadLoop(void *handler) { - while (static_cast(handler)->m_outputThreadIsRunning) - { + do { static_cast(handler)->UpdateOutput(); - } + } while (static_cast(handler)->m_outputThreadIsRunning); } Result SwitchVirtualGamepadHandler::InitInputThread() diff --git a/source/Sysmodule/source/config_handler.cpp b/source/Sysmodule/source/config_handler.cpp index 6272a30..922e538 100644 --- a/source/Sysmodule/source/config_handler.cpp +++ b/source/Sysmodule/source/config_handler.cpp @@ -181,8 +181,7 @@ namespace syscon::config void ConfigChangedCheckThreadFunc(void *arg) { - while (is_config_changed_check_thread_running) - { + do { if (R_SUCCEEDED(waitSingle(filecheckTimerWaiter, 0))) { if (config::CheckForFileChanges()) @@ -192,7 +191,7 @@ namespace syscon::config usb::ReloadDualshock4Event(); } } - } + } while (is_config_changed_check_thread_running); } } diff --git a/source/Sysmodule/source/usb_module.cpp b/source/Sysmodule/source/usb_module.cpp index 533d2a9..d6cefc2 100644 --- a/source/Sysmodule/source/usb_module.cpp +++ b/source/Sysmodule/source/usb_module.cpp @@ -39,8 +39,7 @@ namespace syscon::usb void UsbEventThreadFunc(void *arg) { WriteToLog("Starting USB Event Thread!"); - while (is_usb_event_thread_running) - { + do { if (R_SUCCEEDED(eventWait(&g_usbCatchAllEvent, U64_MAX))) { WriteToLog("Event got caught!"); @@ -67,14 +66,13 @@ namespace syscon::usb else if ((total_entries = QueryVendorProduct(VENDOR_SONY, PRODUCT_DUALSHOCK4_2X)) != 0) handler::Insert(std::make_unique(std::make_unique(interfaces, total_entries))); } - } + } while (is_usb_event_thread_running); } void UsbInterfaceChangeThreadFunc(void *arg) { WriteToLog("Starting USB Interface Change Thread!"); - while (is_usb_interface_change_thread_running) - { + do { if (R_SUCCEEDED(eventWait(usbHsGetInterfaceStateChangeEvent(), UINT64_MAX))) { s32 total_entries; @@ -109,7 +107,7 @@ namespace syscon::usb } } } - } + } while (is_usb_interface_change_thread_running); } s32 QueryInterfaces(u8 iclass, u8 isubclass, u8 iprotocol)