Changed to our own Queue
This commit is contained in:
parent
1453d81a9d
commit
8dab865cb6
|
@ -6,8 +6,8 @@
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
|
|
||||||
#include "IPostBox.h"
|
#include "IPostBox.h"
|
||||||
#include <queue>
|
|
||||||
#include "../../Misc/Thread/OysterMutex.h"
|
#include "../../Misc/Thread/OysterMutex.h"
|
||||||
|
#include "../../Misc/ThreadSafeQueue.h"
|
||||||
|
|
||||||
namespace Oyster
|
namespace Oyster
|
||||||
{
|
{
|
||||||
|
@ -25,8 +25,7 @@ namespace Oyster
|
||||||
virtual bool IsFull();
|
virtual bool IsFull();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::queue<T> messages;
|
Oyster::Queue::ThreadSafeQueue<T> messages;
|
||||||
OysterMutex mutex;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -44,27 +43,23 @@ namespace Oyster
|
||||||
template <class T>
|
template <class T>
|
||||||
void PostBox<T>::PostMessage(T& message)
|
void PostBox<T>::PostMessage(T& message)
|
||||||
{
|
{
|
||||||
mutex.LockMutex();
|
messages.Push(message);
|
||||||
messages.push(message);
|
|
||||||
mutex.UnlockMutex();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void PostBox<T>::FetchMessage(T& message)
|
void PostBox<T>::FetchMessage(T& message)
|
||||||
{
|
{
|
||||||
mutex.LockMutex();
|
|
||||||
if(IsFull())
|
if(IsFull())
|
||||||
{
|
{
|
||||||
message = messages.front();
|
message = messages.Front();
|
||||||
messages.pop();
|
messages.Pop();
|
||||||
}
|
}
|
||||||
mutex.UnlockMutex();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
bool PostBox<T>::IsFull()
|
bool PostBox<T>::IsFull()
|
||||||
{
|
{
|
||||||
return !messages.empty();
|
return !messages.IsEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ int main()
|
||||||
|
|
||||||
//test queue
|
//test queue
|
||||||
//-----------------------------------------
|
//-----------------------------------------
|
||||||
Oyster::Queue::IQueue<int> *test = new Oyster::Queue::ThreadSafeQueue<int>();
|
/*Oyster::Queue::IQueue<int> *test = new Oyster::Queue::ThreadSafeQueue<int>();
|
||||||
Oyster::Queue::IQueue<int> *test2 = new Oyster::Queue::ThreadSafeQueue<int>();
|
Oyster::Queue::IQueue<int> *test2 = new Oyster::Queue::ThreadSafeQueue<int>();
|
||||||
|
|
||||||
for(int i = 0; i < 100; i++)
|
for(int i = 0; i < 100; i++)
|
||||||
|
@ -91,8 +91,8 @@ int main()
|
||||||
cout << test->Front() << " " << test2->Front() <<endl;
|
cout << test->Front() << " " << test2->Front() <<endl;
|
||||||
|
|
||||||
delete test;
|
delete test;
|
||||||
delete test2;
|
delete test2;*/
|
||||||
//chat(client);
|
chat(client);
|
||||||
|
|
||||||
ShutdownWinSock();
|
ShutdownWinSock();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue