diff options
| author | Shawn Hoffman <godisgovernment@gmail.com> | 2010-02-23 01:18:57 +0000 |
|---|---|---|
| committer | Shawn Hoffman <godisgovernment@gmail.com> | 2010-02-23 01:18:57 +0000 |
| commit | 141ee0e4855137cc3152d9547a2b2fac123adcb8 (patch) | |
| tree | 927153ab57142ca2f91200564e63a1ffcb624703 /Source/Core | |
| parent | a4e9bf3fd2b70fc0e190d0746aaaf7a83a5edea4 (diff) | |
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
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/Core/Src/HW/SI.cpp | 2 | ||||
| -rw-r--r-- | Source/Core/Core/Src/HW/SI_DeviceGBA.cpp | 38 | ||||
| -rw-r--r-- | Source/Core/Core/Src/HW/SI_DeviceGBA.h | 2 |
3 files changed, 32 insertions, 10 deletions
diff --git a/Source/Core/Core/Src/HW/SI.cpp b/Source/Core/Core/Src/HW/SI.cpp index 9932700f50..db3dffb49e 100644 --- a/Source/Core/Core/Src/HW/SI.cpp +++ b/Source/Core/Core/Src/HW/SI.cpp @@ -25,6 +25,7 @@ #include "VideoInterface.h" #include "SI.h" +#include "SI_DeviceGBA.h" namespace SerialInterface { @@ -265,6 +266,7 @@ void Shutdown() { for (int i = 0; i < NUMBER_OF_CHANNELS; i++) RemoveDevice(i); + GBAConnectionWaiter_Shutdown(); } void Read32(u32& _uReturnValue, const u32 _iAddress) diff --git a/Source/Core/Core/Src/HW/SI_DeviceGBA.cpp b/Source/Core/Core/Src/HW/SI_DeviceGBA.cpp index c46702afd3..e98bbab668 100644 --- a/Source/Core/Core/Src/HW/SI_DeviceGBA.cpp +++ b/Source/Core/Core/Src/HW/SI_DeviceGBA.cpp @@ -24,47 +24,65 @@ static Common::Thread *connectionThread = NULL; static std::queue<sf::SocketTCP> waiting_socks; +static Common::CriticalSection cs_gba; +volatile bool server_running; // --- GameBoy Advance "Link Cable" --- -THREAD_RETURN ConnectionWaiter(void*) +THREAD_RETURN GBAConnectionWaiter(void*) { + server_running = true; + Common::SetCurrentThreadName("GBA Connection Waiter"); sf::SocketTCP server; if (!server.Listen(0xd6ba)) return 0; - + server.SetBlocking(false); - - for (;;) + + sf::SocketTCP new_client; + while (server_running) { - sf::SocketTCP new_client; if (server.Accept(new_client) == sf::Socket::Done) { + cs_gba.Enter(); waiting_socks.push(new_client); - PanicAlert("Connected"); + cs_gba.Leave(); } + SLEEP(1); } server.Close(); return 0; } +void GBAConnectionWaiter_Shutdown() +{ + server_running = false; + if (connectionThread) + connectionThread->WaitForDeath(); +} + 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(); waiting_socks.pop(); - return true; + sock_filled = true; } - return false; + cs_gba.Leave(); + + return sock_filled; } GBASockServer::GBASockServer() { if (!connectionThread) - connectionThread = new Common::Thread(ConnectionWaiter, (void*)0); + connectionThread = new Common::Thread(GBAConnectionWaiter, (void*)0); } GBASockServer::~GBASockServer() diff --git a/Source/Core/Core/Src/HW/SI_DeviceGBA.h b/Source/Core/Core/Src/HW/SI_DeviceGBA.h index 41cde2587c..395cb1be10 100644 --- a/Source/Core/Core/Src/HW/SI_DeviceGBA.h +++ b/Source/Core/Core/Src/HW/SI_DeviceGBA.h @@ -22,6 +22,8 @@ // GameBoy Advance "Link Cable" +void GBAConnectionWaiter_Shutdown(); + class GBASockServer : public sf::SocketTCP { public: |
