should fix any concerns brought by the last commit:

GBAConnectionWaiter should take less cpu time, be threadsafe, and exit properly.
thanks to sl1nk3 and skidau

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5112 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Shawn Hoffman 2010-02-23 01:18:57 +00:00
parent a4e9bf3fd2
commit 141ee0e485
3 changed files with 32 additions and 10 deletions

View File

@ -25,6 +25,7 @@
#include "VideoInterface.h" #include "VideoInterface.h"
#include "SI.h" #include "SI.h"
#include "SI_DeviceGBA.h"
namespace SerialInterface namespace SerialInterface
{ {
@ -265,6 +266,7 @@ void Shutdown()
{ {
for (int i = 0; i < NUMBER_OF_CHANNELS; i++) for (int i = 0; i < NUMBER_OF_CHANNELS; i++)
RemoveDevice(i); RemoveDevice(i);
GBAConnectionWaiter_Shutdown();
} }
void Read32(u32& _uReturnValue, const u32 _iAddress) void Read32(u32& _uReturnValue, const u32 _iAddress)

View File

@ -24,11 +24,15 @@
static Common::Thread *connectionThread = NULL; static Common::Thread *connectionThread = NULL;
static std::queue<sf::SocketTCP> waiting_socks; static std::queue<sf::SocketTCP> waiting_socks;
static Common::CriticalSection cs_gba;
volatile bool server_running;
// --- GameBoy Advance "Link Cable" --- // --- GameBoy Advance "Link Cable" ---
THREAD_RETURN ConnectionWaiter(void*) THREAD_RETURN GBAConnectionWaiter(void*)
{ {
server_running = true;
Common::SetCurrentThreadName("GBA Connection Waiter"); Common::SetCurrentThreadName("GBA Connection Waiter");
sf::SocketTCP server; sf::SocketTCP server;
@ -37,34 +41,48 @@ THREAD_RETURN ConnectionWaiter(void*)
server.SetBlocking(false); server.SetBlocking(false);
for (;;) sf::SocketTCP new_client;
while (server_running)
{ {
sf::SocketTCP new_client;
if (server.Accept(new_client) == sf::Socket::Done) if (server.Accept(new_client) == sf::Socket::Done)
{ {
cs_gba.Enter();
waiting_socks.push(new_client); waiting_socks.push(new_client);
PanicAlert("Connected"); cs_gba.Leave();
} }
SLEEP(1);
} }
server.Close(); server.Close();
return 0; return 0;
} }
void GBAConnectionWaiter_Shutdown()
{
server_running = false;
if (connectionThread)
connectionThread->WaitForDeath();
}
bool GetAvailableSock(sf::SocketTCP& sock_to_fill) bool GetAvailableSock(sf::SocketTCP& sock_to_fill)
{ {
if (waiting_socks.size() > 0) bool sock_filled = false;
cs_gba.Enter();
if (waiting_socks.size())
{ {
sock_to_fill = waiting_socks.front(); sock_to_fill = waiting_socks.front();
waiting_socks.pop(); waiting_socks.pop();
return true; sock_filled = true;
} }
return false; cs_gba.Leave();
return sock_filled;
} }
GBASockServer::GBASockServer() GBASockServer::GBASockServer()
{ {
if (!connectionThread) if (!connectionThread)
connectionThread = new Common::Thread(ConnectionWaiter, (void*)0); connectionThread = new Common::Thread(GBAConnectionWaiter, (void*)0);
} }
GBASockServer::~GBASockServer() GBASockServer::~GBASockServer()

View File

@ -22,6 +22,8 @@
// GameBoy Advance "Link Cable" // GameBoy Advance "Link Cable"
void GBAConnectionWaiter_Shutdown();
class GBASockServer : public sf::SocketTCP class GBASockServer : public sf::SocketTCP
{ {
public: public: