2#ifndef _LOGIT_TASK_EXECUTOR_HPP_INCLUDED
3#define _LOGIT_TASK_EXECUTOR_HPP_INCLUDED
11#include <condition_variable>
44 std::this_thread::yield();
45 std::this_thread::sleep_for(std::chrono::milliseconds(1));
59 std::function<void()> task;
A thread-safe task executor that processes tasks in a dedicated worker thread.
void add_task(std::function< void()> task)
Adds a task to the queue in a thread-safe manner.
std::mutex m_queue_mutex
Mutex to protect access to the task queue.
~TaskExecutor()
Destructor that stops the worker thread and cleans up resources.
TaskExecutor(TaskExecutor &&)=delete
bool m_stop_flag
Flag indicating if the worker thread should stop.
TaskExecutor(const TaskExecutor &)=delete
std::queue< std::function< void()> > m_tasks_queue
Queue holding tasks to be executed.
TaskExecutor & operator=(TaskExecutor &&)=delete
void wait()
Waits for all tasks in the queue to be processed.
TaskExecutor & operator=(const TaskExecutor &)=delete
std::thread m_worker_thread
Worker thread for executing tasks.
void worker_function()
The worker thread function that processes tasks from the queue.
static TaskExecutor & get_instance()
Get the singleton instance of the TaskExecutor.
std::condition_variable m_queue_condition
Condition variable to signal task availability.
TaskExecutor()
Private constructor to enforce the singleton pattern.
The primary namespace for the LogIt++ library.