This has the odd quirk related to networkQueue()

This commit is contained in:
Kayne Ruse
2013-06-17 15:15:27 +10:00
parent 5b2fd80a61
commit 685ca94335
7 changed files with 63 additions and 22 deletions
+29 -2
View File
@@ -5,15 +5,22 @@
#include "SDL/SDL_thread.h"
#include <stdexcept>
#include <deque>
#include <iostream>
static SDL_sem* lock = SDL_CreateSemaphore(1);
static SDL_Thread* queueThread = nullptr;
static std::deque<Packet> queue;
int networkQueue(void*) {
static bool running = false;
static int networkQueue(void*) {
UDPNetworkUtility* netUtil = ServiceLocator<UDPNetworkUtility>::Get();
for(;;) {
//this line is the fix for the quirk
// std::cout << "thread running" << std::endl;
while(running) {
SDL_SemWait(lock);
while(netUtil->Receive()) {
Packet p;
@@ -23,6 +30,26 @@ int networkQueue(void*) {
SDL_SemPost(lock);
SDL_Delay(10);
}
return 0;
}
void BeginQueueThread() {
if (!(queueThread = SDL_CreateThread(networkQueue, nullptr))) {
throw(std::runtime_error("Failed to create the network thread"));
}
running = true;
}
void EndQueueThread() {
running = false;
SDL_WaitThread(queueThread, nullptr);
queueThread = nullptr;
}
void KillQueueThread() {
running = false;
SDL_KillThread(queueThread);
queueThread = nullptr;
}
Packet peekNetworkPacket() {