Removed Multithreading, simplifying the server

Networking and multithreading working at the same time is really fucking
hard. It's better to just have the one thread, and not worry about speed
at this stage.
This commit is contained in:
Kayne Ruse
2013-12-01 15:21:00 +11:00
parent 6ccc874583
commit 1e0ed350fc
5 changed files with 23 additions and 257 deletions
-68
View File
@@ -1,68 +0,0 @@
#ifndef THREADSAFEQUEUE_HPP_
#define THREADSAFEQUEUE_HPP_
#include "SDL/SDL_thread.h"
#include <deque>
#include <stdexcept>
/* This container is a thread safe reimplementation of std::queue.
*/
template<typename T, class Container = std::deque<T>>
class ThreadSafeQueue {
public:
ThreadSafeQueue() {
lock = SDL_CreateSemaphore(1);
if (!lock) {
throw(std::runtime_error("Failed to create ThreadSafeQueue::lock"));
}
}
~ThreadSafeQueue() {
SDL_DestroySemaphore(lock);
}
T PushBack(T t) {
SDL_SemWait(lock);
container.push_back(t);
SDL_SemPost(lock);
return t;
}
T PeekFront() {
T t;
SDL_SemWait(lock);
if (container.size() > 0) {
t = container[0];
}
SDL_SemPost(lock);
return t;
}
T PopFront() {
T t;
SDL_SemWait(lock);
if (container.size() > 0) {
t = container[0];
container.pop_front();
}
SDL_SemPost(lock);
return t;
}
int Size() {
//can't be sure if std::deque::size() is thread safe
int ret;
SDL_SemWait(lock);
ret = container.size();
SDL_SemPost(lock);
return ret;
}
private:
Container container;
SDL_sem* lock;
};
#endif