pgLab/tsqueue.cpp

34 lines
622 B
C++

#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();
}