From 99a38dce32c009f141e60d8aaca7a74dfddf05d8 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 12 Feb 2021 07:03:55 -0800 Subject: [PATCH] htc: fix event wait loops for rpc clients --- .../htc/server/rpc/htc_htcmisc_rpc_server.cpp | 16 +++++++--------- .../source/htc/server/rpc/htc_rpc_client.cpp | 16 +++++++--------- .../source/htcfs/htcfs_client_impl.cpp | 2 +- .../source/htcs/impl/htcs_monitor.cpp | 5 ++++- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/libraries/libstratosphere/source/htc/server/rpc/htc_htcmisc_rpc_server.cpp b/libraries/libstratosphere/source/htc/server/rpc/htc_htcmisc_rpc_server.cpp index d0bd22eff..05948a064 100644 --- a/libraries/libstratosphere/source/htc/server/rpc/htc_htcmisc_rpc_server.cpp +++ b/libraries/libstratosphere/source/htc/server/rpc/htc_htcmisc_rpc_server.cpp @@ -84,21 +84,19 @@ namespace ams::htc::server::rpc { if (os::TryWaitEvent(event)) { return 1; } - if (m_driver->GetChannelState(m_channel_id) == state) { - return 0; - } /* Wait. */ - while (true) { + while (m_driver->GetChannelState(m_channel_id) != state) { const auto idx = os::WaitAny(m_driver->GetChannelStateEvent(m_channel_id), event); - if (idx == 0) { - if (m_driver->GetChannelState(m_channel_id) == state) { - return 0; - } - } else { + if (idx != 0) { return idx; } + + /* Clear the channel state event. */ + os::ClearEvent(m_driver->GetChannelStateEvent(m_channel_id)); } + + return 0; } Result HtcmiscRpcServer::ReceiveThread() { diff --git a/libraries/libstratosphere/source/htc/server/rpc/htc_rpc_client.cpp b/libraries/libstratosphere/source/htc/server/rpc/htc_rpc_client.cpp index 00cb9b352..b0250db4a 100644 --- a/libraries/libstratosphere/source/htc/server/rpc/htc_rpc_client.cpp +++ b/libraries/libstratosphere/source/htc/server/rpc/htc_rpc_client.cpp @@ -184,21 +184,19 @@ namespace ams::htc::server::rpc { if (os::TryWaitEvent(event)) { return 1; } - if (m_driver->GetChannelState(m_channel_id) == state) { - return 0; - } /* Wait. */ - while (true) { + while (m_driver->GetChannelState(m_channel_id) != state) { const auto idx = os::WaitAny(m_driver->GetChannelStateEvent(m_channel_id), event); - if (idx == 0) { - if (m_driver->GetChannelState(m_channel_id) == state) { - return 0; - } - } else { + if (idx != 0) { return idx; } + + /* Clear the channel state event. */ + os::ClearEvent(m_driver->GetChannelStateEvent(m_channel_id)); } + + return 0; } Result RpcClient::ReceiveThread() { diff --git a/libraries/libstratosphere/source/htcfs/htcfs_client_impl.cpp b/libraries/libstratosphere/source/htcfs/htcfs_client_impl.cpp index b7ff385be..7d75464fb 100644 --- a/libraries/libstratosphere/source/htcfs/htcfs_client_impl.cpp +++ b/libraries/libstratosphere/source/htcfs/htcfs_client_impl.cpp @@ -147,7 +147,7 @@ namespace ams::htcfs { } /* Clear the channel state event. */ - os::ClearEvent(channel_state_event);; + os::ClearEvent(channel_state_event); } return idx; } diff --git a/libraries/libstratosphere/source/htcs/impl/htcs_monitor.cpp b/libraries/libstratosphere/source/htcs/impl/htcs_monitor.cpp index cd949983b..7c9423c3c 100644 --- a/libraries/libstratosphere/source/htcs/impl/htcs_monitor.cpp +++ b/libraries/libstratosphere/source/htcs/impl/htcs_monitor.cpp @@ -77,7 +77,10 @@ namespace ams::htcs::impl { } /* Start the rpc client. */ - if (R_FAILED(m_rpc_client->Start())) { + const Result start_result = m_rpc_client->Start(); + if (R_FAILED(start_result)) { + /* DEBUG */ + R_ABORT_UNLESS(start_result); continue; }