1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-07-08 03:58:43 +00:00

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
This commit is contained in:
cathery 2020-03-02 18:21:40 +03:00
parent b68134504b
commit 6898d056d4
3 changed files with 10 additions and 15 deletions

View File

@ -20,18 +20,16 @@ void SwitchVirtualGamepadHandler::Exit()
void SwitchVirtualGamepadHandler::InputThreadLoop(void *handler) void SwitchVirtualGamepadHandler::InputThreadLoop(void *handler)
{ {
while (static_cast<SwitchVirtualGamepadHandler*>(handler)->m_inputThreadIsRunning) do {
{
static_cast<SwitchVirtualGamepadHandler *>(handler)->UpdateInput(); static_cast<SwitchVirtualGamepadHandler *>(handler)->UpdateInput();
} } while (static_cast<SwitchVirtualGamepadHandler*>(handler)->m_inputThreadIsRunning);
} }
void SwitchVirtualGamepadHandler::OutputThreadLoop(void *handler) void SwitchVirtualGamepadHandler::OutputThreadLoop(void *handler)
{ {
while (static_cast<SwitchVirtualGamepadHandler*>(handler)->m_outputThreadIsRunning) do {
{
static_cast<SwitchVirtualGamepadHandler *>(handler)->UpdateOutput(); static_cast<SwitchVirtualGamepadHandler *>(handler)->UpdateOutput();
} } while (static_cast<SwitchVirtualGamepadHandler*>(handler)->m_outputThreadIsRunning);
} }
Result SwitchVirtualGamepadHandler::InitInputThread() Result SwitchVirtualGamepadHandler::InitInputThread()

View File

@ -181,8 +181,7 @@ namespace syscon::config
void ConfigChangedCheckThreadFunc(void *arg) void ConfigChangedCheckThreadFunc(void *arg)
{ {
while (is_config_changed_check_thread_running) do {
{
if (R_SUCCEEDED(waitSingle(filecheckTimerWaiter, 0))) if (R_SUCCEEDED(waitSingle(filecheckTimerWaiter, 0)))
{ {
if (config::CheckForFileChanges()) if (config::CheckForFileChanges())
@ -192,7 +191,7 @@ namespace syscon::config
usb::ReloadDualshock4Event(); usb::ReloadDualshock4Event();
} }
} }
} } while (is_config_changed_check_thread_running);
} }
} }

View File

@ -39,8 +39,7 @@ namespace syscon::usb
void UsbEventThreadFunc(void *arg) void UsbEventThreadFunc(void *arg)
{ {
WriteToLog("Starting USB Event Thread!"); WriteToLog("Starting USB Event Thread!");
while (is_usb_event_thread_running) do {
{
if (R_SUCCEEDED(eventWait(&g_usbCatchAllEvent, U64_MAX))) if (R_SUCCEEDED(eventWait(&g_usbCatchAllEvent, U64_MAX)))
{ {
WriteToLog("Event got caught!"); WriteToLog("Event got caught!");
@ -67,14 +66,13 @@ namespace syscon::usb
else if ((total_entries = QueryVendorProduct(VENDOR_SONY, PRODUCT_DUALSHOCK4_2X)) != 0) else if ((total_entries = QueryVendorProduct(VENDOR_SONY, PRODUCT_DUALSHOCK4_2X)) != 0)
handler::Insert(std::make_unique<Dualshock4Controller>(std::make_unique<SwitchUSBDevice>(interfaces, total_entries))); handler::Insert(std::make_unique<Dualshock4Controller>(std::make_unique<SwitchUSBDevice>(interfaces, total_entries)));
} }
} } while (is_usb_event_thread_running);
} }
void UsbInterfaceChangeThreadFunc(void *arg) void UsbInterfaceChangeThreadFunc(void *arg)
{ {
WriteToLog("Starting USB Interface Change Thread!"); WriteToLog("Starting USB Interface Change Thread!");
while (is_usb_interface_change_thread_running) do {
{
if (R_SUCCEEDED(eventWait(usbHsGetInterfaceStateChangeEvent(), UINT64_MAX))) if (R_SUCCEEDED(eventWait(usbHsGetInterfaceStateChangeEvent(), UINT64_MAX)))
{ {
s32 total_entries; 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) s32 QueryInterfaces(u8 iclass, u8 isubclass, u8 iprotocol)