Fix a memleak. Probably/maybe improve USBGecko performance.

This commit is contained in:
Jordan Woyak 2013-02-17 00:19:42 -06:00
parent 206fdde933
commit 9ac2fbb0a5
2 changed files with 31 additions and 24 deletions

View File

@ -98,8 +98,8 @@ bool GeckoSockServer::GetAvailableSock(sf::SocketTCP &sock_to_fill)
client_running = false; client_running = false;
clientThread.join(); clientThread.join();
recv_fifo = std::queue<u8>(); recv_fifo = std::deque<u8>();
send_fifo = std::queue<u8>(); send_fifo = std::deque<u8>();
} }
clientThread = std::thread(std::mem_fun(&GeckoSockServer::ClientThread), this); clientThread = std::thread(std::mem_fun(&GeckoSockServer::ClientThread), this);
client_count++; client_count++;
@ -120,34 +120,39 @@ void GeckoSockServer::ClientThread()
while (client_running) while (client_running)
{ {
u8 data; bool did_nothing = true;
std::size_t got = 0;
{ {
std::lock_guard<std::mutex> lk(transfer_lock); std::lock_guard<std::mutex> lk(transfer_lock);
if (client.Receive((char*)&data, sizeof(data), got) // what's an ideal buffer size?
== sf::Socket::Disconnected) char data[128];
client_running = false; std::size_t got = 0;
if (got)
recv_fifo.push(data);
if (send_fifo.size()) if (client.Receive(&data[0], ARRAYSIZE(data), got) == sf::Socket::Disconnected)
client_running = false;
if (got != 0)
{ {
char* packet = new char[send_fifo.size()]; did_nothing = false;
int i = 0;
while(send_fifo.size()) recv_fifo.insert(recv_fifo.end(), &data[0], &data[got]);
{
packet[i++] = send_fifo.front();
send_fifo.pop();
} }
if (client.Send(packet, sizeof(u8)*i)
== sf::Socket::Disconnected) if (!send_fifo.empty())
{
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; client_running = false;
} }
} // unlock transfer } // unlock transfer
SLEEP(1); if (did_nothing)
Common::YieldCPU();
} }
client.Close(); client.Close();
@ -186,7 +191,7 @@ void CEXIGecko::ImmReadWrite(u32 &_uData, u32 _uSize)
if (!recv_fifo.empty()) if (!recv_fifo.empty())
{ {
_uData = 0x08000000 | (recv_fifo.front() << 16); _uData = 0x08000000 | (recv_fifo.front() << 16);
recv_fifo.pop(); recv_fifo.pop_front();
} }
break; break;
} }
@ -196,7 +201,7 @@ void CEXIGecko::ImmReadWrite(u32 &_uData, u32 _uSize)
case CMD_SEND: case CMD_SEND:
{ {
std::lock_guard<std::mutex> lk(transfer_lock); std::lock_guard<std::mutex> lk(transfer_lock);
send_fifo.push(_uData >> 20); send_fifo.push_back(_uData >> 20);
_uData = 0x04000000; _uData = 0x04000000;
break; break;
} }

View File

@ -20,6 +20,8 @@
#include "SFML/Network.hpp" #include "SFML/Network.hpp"
#include "Thread.h" #include "Thread.h"
#include <deque>
#include <queue> #include <queue>
class GeckoSockServer class GeckoSockServer
@ -36,8 +38,8 @@ public:
std::thread clientThread; std::thread clientThread;
std::mutex transfer_lock; std::mutex transfer_lock;
std::queue<u8> send_fifo; std::deque<u8> send_fifo;
std::queue<u8> recv_fifo; std::deque<u8> recv_fifo;
private: private:
static int client_count; static int client_count;