Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix a memleak. Probably/maybe improve USBGecko performance.
  • Loading branch information
jordan-woyak committed Feb 17, 2013
1 parent 206fdde commit 9ac2fbb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
47 changes: 26 additions & 21 deletions Source/Core/Core/Src/HW/EXI_DeviceGecko.cpp
Expand Up @@ -98,8 +98,8 @@ bool GeckoSockServer::GetAvailableSock(sf::SocketTCP &sock_to_fill)
client_running = false;
clientThread.join();

recv_fifo = std::queue<u8>();
send_fifo = std::queue<u8>();
recv_fifo = std::deque<u8>();
send_fifo = std::deque<u8>();
}
clientThread = std::thread(std::mem_fun(&GeckoSockServer::ClientThread), this);
client_count++;
Expand All @@ -120,34 +120,39 @@ void GeckoSockServer::ClientThread()

while (client_running)
{
u8 data;
std::size_t got = 0;
bool did_nothing = true;

{
std::lock_guard<std::mutex> lk(transfer_lock);

if (client.Receive((char*)&data, sizeof(data), got)
== sf::Socket::Disconnected)
// what's an ideal buffer size?
char data[128];
std::size_t got = 0;

if (client.Receive(&data[0], ARRAYSIZE(data), got) == sf::Socket::Disconnected)
client_running = false;
if (got)
recv_fifo.push(data);

if (got != 0)
{
did_nothing = false;

recv_fifo.insert(recv_fifo.end(), &data[0], &data[got]);
}

if (send_fifo.size())
if (!send_fifo.empty())
{
char* packet = new char[send_fifo.size()];
int i = 0;
while(send_fifo.size())
{
packet[i++] = send_fifo.front();
send_fifo.pop();
}
if (client.Send(packet, sizeof(u8)*i)
== sf::Socket::Disconnected)
did_nothing = false;

std::vector<char> packet(send_fifo.begin(), send_fifo.end());
send_fifo.clear();

if (client.Send(&packet[0], packet.size()) == sf::Socket::Disconnected)
client_running = false;
}
} // unlock transfer

SLEEP(1);
if (did_nothing)
Common::YieldCPU();
}

client.Close();
Expand Down Expand Up @@ -186,7 +191,7 @@ void CEXIGecko::ImmReadWrite(u32 &_uData, u32 _uSize)
if (!recv_fifo.empty())
{
_uData = 0x08000000 | (recv_fifo.front() << 16);
recv_fifo.pop();
recv_fifo.pop_front();
}
break;
}
Expand All @@ -196,7 +201,7 @@ void CEXIGecko::ImmReadWrite(u32 &_uData, u32 _uSize)
case CMD_SEND:
{
std::lock_guard<std::mutex> lk(transfer_lock);
send_fifo.push(_uData >> 20);
send_fifo.push_back(_uData >> 20);
_uData = 0x04000000;
break;
}
Expand Down
6 changes: 4 additions & 2 deletions Source/Core/Core/Src/HW/EXI_DeviceGecko.h
Expand Up @@ -20,6 +20,8 @@

#include "SFML/Network.hpp"
#include "Thread.h"

#include <deque>
#include <queue>

class GeckoSockServer
Expand All @@ -36,8 +38,8 @@ class GeckoSockServer
std::thread clientThread;
std::mutex transfer_lock;

std::queue<u8> send_fifo;
std::queue<u8> recv_fifo;
std::deque<u8> send_fifo;
std::deque<u8> recv_fifo;

private:
static int client_count;
Expand Down

0 comments on commit 9ac2fbb

Please sign in to comment.