Added the thread safe TSQueue and using it in mainwindow to replace the adhoc queue implementation.
This commit is contained in:
parent
c551d982c6
commit
83064ab86b
10 changed files with 253 additions and 27 deletions
34
tsqueue.cpp
Normal file
34
tsqueue.cpp
Normal 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();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue