LogIt++
|
A thread-safe task executor that processes tasks in a dedicated worker thread. More...
#include <TaskExecutor.hpp>
Public Member Functions | |
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 Public Member Functions | |
static TaskExecutor & | get_instance () |
Get the singleton instance of the TaskExecutor. | |
Private Member Functions | |
void | worker_function () |
The worker thread function that processes tasks from the queue. | |
TaskExecutor () | |
Private constructor to enforce the singleton pattern. | |
~TaskExecutor () | |
Destructor that stops the worker thread and cleans up resources. | |
TaskExecutor (const TaskExecutor &)=delete | |
TaskExecutor & | operator= (const TaskExecutor &)=delete |
TaskExecutor (TaskExecutor &&)=delete | |
TaskExecutor & | operator= (TaskExecutor &&)=delete |
Private Attributes | |
std::queue< std::function< void()> > | m_tasks_queue |
Queue holding tasks to be executed. | |
std::mutex | m_queue_mutex |
Mutex to protect access to the task queue. | |
std::condition_variable | m_queue_condition |
Condition variable to signal task availability. | |
std::thread | m_worker_thread |
Worker thread for executing tasks. | |
bool | m_stop_flag |
Flag indicating if the worker thread should stop. | |
A thread-safe task executor that processes tasks in a dedicated worker thread.
This class provides a mechanism for queuing tasks (functions or lambdas) and executing them asynchronously in a background thread. It follows the singleton design pattern.
Definition at line 20 of file TaskExecutor.hpp.
|
inlineprivate |
Private constructor to enforce the singleton pattern.
Definition at line 75 of file TaskExecutor.hpp.
|
inlineprivate |
Destructor that stops the worker thread and cleans up resources.
Definition at line 80 of file TaskExecutor.hpp.
|
privatedelete |
|
privatedelete |
|
inline |
Adds a task to the queue in a thread-safe manner.
task | A function or lambda with no arguments to be executed asynchronously. |
Definition at line 31 of file TaskExecutor.hpp.
|
inlinestatic |
Get the singleton instance of the TaskExecutor.
TaskExecutor
. Definition at line 24 of file TaskExecutor.hpp.
|
privatedelete |
|
privatedelete |
|
inline |
Waits for all tasks in the queue to be processed.
Definition at line 39 of file TaskExecutor.hpp.
|
inlineprivate |
The worker thread function that processes tasks from the queue.
Definition at line 57 of file TaskExecutor.hpp.
|
private |
Condition variable to signal task availability.
Definition at line 52 of file TaskExecutor.hpp.
|
mutableprivate |
Mutex to protect access to the task queue.
Definition at line 51 of file TaskExecutor.hpp.
|
private |
Flag indicating if the worker thread should stop.
Definition at line 54 of file TaskExecutor.hpp.
|
private |
Queue holding tasks to be executed.
Definition at line 50 of file TaskExecutor.hpp.
|
private |
Worker thread for executing tasks.
Definition at line 53 of file TaskExecutor.hpp.