Select Git revision
PatchGraph.cs
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
QueueDispatcher.cpp 1.17 KiB
#include "QueueDispatcher.h"
namespace Utility
{
QueueDispatcher::QueueDispatcher()
{
m_manual = true;
}
QueueDispatcher::~QueueDispatcher()
{
// Stop execution
set_manual();
}
void QueueDispatcher::set_manual()
{
m_manual = true;
if (t_execution.joinable())
{
t_execution.join();
}
}
bool QueueDispatcher::execute_one()
{
if (m_manual)
{
if (auto action = m_queue.pop())
{
action.get().set_value();
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
void QueueDispatcher::set_automatic()
{
m_manual = false;
// Execute in new thread
t_execution = std::thread(std::bind(&QueueDispatcher::execute_loop, this));
}
void QueueDispatcher::execute_loop()
{
while (!m_manual)
{
if (auto action = m_queue.waitfor_and_pop(100))
{
action.get().set_value();
}
}
}
}