Last active
December 18, 2015 13:29
-
-
Save Ratstail91/5790773 to your computer and use it in GitHub Desktop.
I want to push a network packet onto the deque in networkQueue(), and pop the first packet in getPacket()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "network_queue.hpp" | |
#include "service_locator.hpp" | |
#include "udp_network_utility.hpp" | |
#include "SDL/SDL_thread.h" | |
#include <deque> | |
static SDL_sem* lock = SDL_CreateSemaphore(1); | |
static std::deque<Packet> queue; | |
int networkQueue(void*) { | |
UDPNetworkUtility* netUtil = ServiceLocator<UDPNetworkUtility>::Get(); | |
Packet p; | |
for(;;) { | |
SDL_SemWait(lock); | |
while(netUtil->Receive()) { | |
memcpy(&p, netUtil->GetInData(), sizeof(Packet)); | |
queue.push_back(p); | |
} | |
SDL_SemPost(lock); | |
SDL_Delay(10); | |
} | |
} | |
Packet popNetworkPacket() { | |
Packet p; | |
SDL_SemWait(lock); | |
if (queue.size() > 0) { | |
Packet p = queue[0]; | |
queue.pop_front(); | |
} | |
SDL_SemPost(lock); | |
return p; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment