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;
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++;
@ -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)
client_running = false;
if (got)
recv_fifo.push(data);
// what's an ideal buffer size?
char data[128];
std::size_t got = 0;
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()];
int i = 0;
while(send_fifo.size())
{
packet[i++] = send_fifo.front();
send_fifo.pop();
did_nothing = false;
recv_fifo.insert(recv_fifo.end(), &data[0], &data[got]);
}
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;
}
} // unlock transfer
SLEEP(1);
if (did_nothing)
Common::YieldCPU();
}
client.Close();
@ -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;
}
@ -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;
}

View File

@ -20,6 +20,8 @@
#include "SFML/Network.hpp"
#include "Thread.h"
#include <deque>
#include <queue>
class GeckoSockServer
@ -36,8 +38,8 @@ public:
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;