2#ifndef _LOGIT_DETAIL_TASK_EXECUTOR_HPP_INCLUDED
3#define _LOGIT_DETAIL_TASK_EXECUTOR_HPP_INCLUDED
12#include <condition_variable>
21#if defined(__EMSCRIPTEN__)
32 void add_task(std::function<
void()> task) {
93 std::this_thread::yield();
94 std::this_thread::sleep_for(std::chrono::milliseconds(1));
136 std::function<void()> task;
std::mutex m_queue_mutex
Mutex to protect access to the task queue.
std::thread m_worker_thread
Worker thread for executing tasks.
void set_max_queue_size(std::size_t size)
Sets the maximum size of the task queue.
TaskExecutor(const TaskExecutor &)=delete
QueuePolicy m_overflow_policy
Policy for handling queue overflow.
TaskExecutor & operator=(const TaskExecutor &)=delete
std::condition_variable m_queue_condition
Condition variable to signal task availability.
void worker_function()
The worker thread function that processes tasks from the queue.
std::queue< std::function< void()> > m_tasks_queue
Queue holding tasks to be executed.
TaskExecutor & operator=(TaskExecutor &&)=delete
TaskExecutor()
Private constructor to enforce the singleton pattern.
bool m_stop_flag
Flag indicating if the worker thread should stop.
void shutdown()
Shuts down the TaskExecutor by stopping the worker thread.
TaskExecutor(TaskExecutor &&)=delete
void set_queue_policy(QueuePolicy policy)
Sets the behavior when the queue is full.
void add_task(std::function< void()> task)
Adds a task to the queue in a thread-safe manner.
void wait()
Waits for all tasks in the queue to be processed.
static TaskExecutor & get_instance()
Get the singleton instance of the TaskExecutor.
~TaskExecutor()
Destructor that stops the worker thread and cleans up resources.
std::size_t m_max_queue_size
Maximum number of tasks in the queue (0 for unlimited).
QueuePolicy
Queue overflow handling policy.
The primary namespace for the LogIt++ library.