mirror of
https://github.com/SatDump/SatDump
synced 2026-08-13 17:47:30 -04:00
Some docs, some bitview
This commit is contained in:
parent
d65381dd86
commit
cee834f222
27 changed files with 753 additions and 720 deletions
58
src-core/utils/task_queue.cpp
Normal file
58
src-core/utils/task_queue.cpp
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#include "task_queue.h"
|
||||
|
||||
namespace satdump
|
||||
{
|
||||
TaskQueue::TaskQueue() {}
|
||||
|
||||
TaskQueue::~TaskQueue()
|
||||
{
|
||||
if (task_thread.joinable())
|
||||
task_thread.join();
|
||||
}
|
||||
|
||||
void TaskQueue::threadFunc()
|
||||
{
|
||||
recheck:
|
||||
queue_mtx.lock();
|
||||
bool queue_has_data = task_queue.size() > 0;
|
||||
queue_mtx.unlock();
|
||||
|
||||
if (queue_has_data)
|
||||
{
|
||||
queue_mtx.lock();
|
||||
auto task = task_queue.front();
|
||||
task_queue.pop();
|
||||
queue_mtx.unlock();
|
||||
|
||||
try
|
||||
{
|
||||
task();
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
// TODOREWORK?
|
||||
}
|
||||
|
||||
goto recheck;
|
||||
}
|
||||
|
||||
thread_exited = true;
|
||||
}
|
||||
|
||||
void TaskQueue::push(std::function<void()> task)
|
||||
{
|
||||
queue_mtx.lock();
|
||||
|
||||
task_queue.push(task);
|
||||
|
||||
if (thread_exited)
|
||||
{
|
||||
if (task_thread.joinable())
|
||||
task_thread.join();
|
||||
thread_exited = false;
|
||||
task_thread = std::thread(&TaskQueue::threadFunc, this);
|
||||
}
|
||||
|
||||
queue_mtx.unlock();
|
||||
}
|
||||
} // namespace satdump
|
||||
Loading…
Add table
Add a link
Reference in a new issue