summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorVampireFlower <monstercatspedup1@gmail.com>2026-09-18 08:25:45 -0600
committerVampireFlower <monstercatspedup1@gmail.com>2026-10-02 17:12:06 -0600
commit3ce096543c55fc12ca308f0300641c2f2b803993 (patch)
tree65905c87fdacab291a6e40a9bd1818922b374e84 /Source/Core
parentee018d00e60b9eb727489908a8daec5c537f44a8 (diff)
Optimize USB Gecko Emulation
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/HW/EXI/EXI_DeviceGecko.cpp23
-rw-r--r--Source/Core/Core/HW/EXI/EXI_DeviceGecko.h5
2 files changed, 19 insertions, 9 deletions
diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceGecko.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceGecko.cpp
index 06e90f83b0..d6a1e1494f 100644
--- a/Source/Core/Core/HW/EXI/EXI_DeviceGecko.cpp
+++ b/Source/Core/Core/HW/EXI/EXI_DeviceGecko.cpp
@@ -92,7 +92,6 @@ bool GeckoSockServer::GetAvailableSock()
if (!waiting_socks.empty())
{
- client = std::move(waiting_socks.front());
if (clientThread.joinable())
{
client_running.Clear();
@@ -101,6 +100,9 @@ bool GeckoSockServer::GetAvailableSock()
recv_fifo = std::deque<u8>();
send_fifo = std::deque<u8>();
}
+ client = std::move(waiting_socks.front());
+ client_running.Set();
+ client_connected.Set();
clientThread = std::thread(&GeckoSockServer::ClientThread, this);
client_count++;
waiting_socks.pop();
@@ -112,8 +114,6 @@ bool GeckoSockServer::GetAvailableSock()
void GeckoSockServer::ClientThread()
{
- client_running.Set();
-
Common::SetCurrentThreadName("Gecko Client");
client->setBlocking(false);
@@ -156,6 +156,7 @@ void GeckoSockServer::ClientThread()
}
client->disconnect();
+ client_connected.Clear();
}
CEXIGecko::CEXIGecko(Core::System& system) : IEXIDevice(system)
@@ -167,7 +168,7 @@ void CEXIGecko::ImmReadWrite(u32& _uData, u32 _uSize)
// We don't really care about _uSize
(void)_uSize;
- if (!client || client->getLocalPort() == 0)
+ if (!client_connected.IsSet())
GetAvailableSock();
switch (_uData >> 28)
@@ -188,11 +189,15 @@ void CEXIGecko::ImmReadWrite(u32& _uData, u32 _uSize)
// |= 0x08000000 if successful
case CMD_RECV:
{
- std::lock_guard lk(transfer_lock);
- if (!recv_fifo.empty())
+ if (m_recv_buffer.empty())
+ {
+ std::lock_guard lk(transfer_lock);
+ m_recv_buffer.swap(recv_fifo);
+ }
+ if (!m_recv_buffer.empty())
{
- _uData = 0x08000000 | (recv_fifo.front() << 16);
- recv_fifo.pop_front();
+ _uData = 0x08000000 | (m_recv_buffer.front() << 16);
+ m_recv_buffer.pop_front();
}
break;
}
@@ -218,7 +223,7 @@ void CEXIGecko::ImmReadWrite(u32& _uData, u32 _uSize)
case CMD_CHK_RX:
{
std::lock_guard lk(transfer_lock);
- _uData = recv_fifo.empty() ? 0 : 0x04000000;
+ _uData = m_recv_buffer.empty() && recv_fifo.empty() ? 0 : 0x04000000;
break;
}
diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceGecko.h b/Source/Core/Core/HW/EXI/EXI_DeviceGecko.h
index 6bed93b3a4..04ac9186b7 100644
--- a/Source/Core/Core/HW/EXI/EXI_DeviceGecko.h
+++ b/Source/Core/Core/HW/EXI/EXI_DeviceGecko.h
@@ -25,6 +25,8 @@ public:
// Client for this server object
std::unique_ptr<sf::TcpSocket> client;
+ // Set before starting the client thread; cleared after it closes the socket.
+ Common::Flag client_connected{false};
void ClientThread();
std::thread clientThread;
std::mutex transfer_lock;
@@ -66,5 +68,8 @@ private:
};
static const u32 ident = 0x04700000;
+
+ // Only accessed by the CPU thread. Refilled from recv_fifo under transfer_lock.
+ std::deque<u8> m_recv_buffer;
};
} // namespace ExpansionInterface