Added the thread safe TSQueue and using it in mainwindow to replace the adhoc queue implementation.

This commit is contained in:
Eelke Klein 2017-01-03 07:22:36 +01:00
parent c551d982c6
commit 83064ab86b
10 changed files with 253 additions and 27 deletions

34
tsqueue.cpp Normal file
View file

@ -0,0 +1,34 @@
#include "tsqueue.h"
TSQueue::TSQueue()
: newData(Win32Event::Reset::Manual, Win32Event::Initial::Clear)
{}
void TSQueue::add(t_Callable callable)
{
std::lock_guard<std::mutex> g(m);
futureQueue.push_back(std::move(callable));
newData.Set();
}
bool TSQueue::empty()
{
std::lock_guard<std::mutex> g(m);
return futureQueue.empty();
}
TSQueue::t_Callable TSQueue::pop()
{
std::lock_guard<std::mutex> g(m);
auto f = std::move(futureQueue.front());
futureQueue.pop_front();
if (futureQueue.empty()) {
newData.Reset();
}
return f;
}
HANDLE TSQueue::getNewDataEventHandle()
{
return newData.GetHandle();
}