![]() |
LogIt++
Header-only, macro-first C++ logging library
|
Thread-safe task executor backed by a dedicated worker thread. More...
#include <TaskExecutor.hpp>
Public Member Functions | |
| void | add_task (std::function< void()> task) |
| Enqueue a task for asynchronous execution. | |
| void | wait () |
| Block until the queue is empty or a shutdown is requested. | |
| void | shutdown () |
| Stop the worker thread and drain outstanding tasks. | |
| void | set_max_queue_size (std::size_t size) |
Update the maximum queue size (0 disables the limit). | |
| void | set_queue_policy (QueuePolicy policy) |
| Change the overflow policy for newly submitted tasks. | |
| std::size_t | dropped_tasks () const noexcept |
| Return the number of tasks dropped by the overflow policy. | |
| void | reset_dropped_tasks () noexcept |
| Reset the overflow counter to zero. | |
Static Public Member Functions | |
| static TaskExecutor & | get_instance () |
| Returns the global executor instance. | |
Private Member Functions | |
| void | worker_function () |
| TaskExecutor () | |
| ~TaskExecutor () | |
| TaskExecutor (const TaskExecutor &)=delete | |
| TaskExecutor & | operator= (const TaskExecutor &)=delete |
| TaskExecutor (TaskExecutor &&)=delete | |
| TaskExecutor & | operator= (TaskExecutor &&)=delete |
Private Attributes | |
| std::mutex | m_lifecycle_mutex |
| Serializes shutdown with lifecycle-changing operations. | |
| std::deque< std::function< void()> > | m_tasks_queue |
| std::mutex | m_queue_mutex |
| std::condition_variable | m_queue_condition |
| std::thread | m_worker_thread |
| std::atomic< bool > | m_stop_flag |
| std::size_t | m_max_queue_size |
| std::atomic< QueuePolicy > | m_overflow_policy |
| std::atomic< std::size_t > | m_dropped_tasks |
| std::atomic< std::size_t > | m_active_tasks |
Thread-safe task executor backed by a dedicated worker thread.
The full design, including backpressure semantics and hot resizing, is described in docs/TaskExecutor.md.
Definition at line 171 of file TaskExecutor.hpp.
|
inlineprivate |
Definition at line 548 of file TaskExecutor.hpp.
|
inlineprivate |
Definition at line 570 of file TaskExecutor.hpp.
|
privatedelete |
|
privatedelete |
|
inline |
Enqueue a task for asynchronous execution.
QueuePolicy::DropOldest drops the incoming task when LOGIT_USE_MPSC_RING is defined. See docs/TaskExecutor.md for the rationale. Definition at line 186 of file TaskExecutor.hpp.
|
inlinenoexcept |
Return the number of tasks dropped by the overflow policy.
Definition at line 389 of file TaskExecutor.hpp.
|
inlinestatic |
Returns the global executor instance.
Definition at line 177 of file TaskExecutor.hpp.
|
privatedelete |
|
privatedelete |
|
inlinenoexcept |
Reset the overflow counter to zero.
Definition at line 393 of file TaskExecutor.hpp.
|
inline |
Update the maximum queue size (0 disables the limit).
On MPSC builds this performs the "hot" resize described in docs/TaskExecutor.md.
Definition at line 318 of file TaskExecutor.hpp.
|
inline |
Change the overflow policy for newly submitted tasks.
Definition at line 381 of file TaskExecutor.hpp.
|
inline |
Stop the worker thread and drain outstanding tasks.
Definition at line 292 of file TaskExecutor.hpp.
|
inline |
Block until the queue is empty or a shutdown is requested.
Definition at line 273 of file TaskExecutor.hpp.
|
inlineprivate |
Definition at line 431 of file TaskExecutor.hpp.
|
private |
Definition at line 408 of file TaskExecutor.hpp.
|
private |
Definition at line 407 of file TaskExecutor.hpp.
|
mutableprivate |
Serializes shutdown with lifecycle-changing operations.
Definition at line 398 of file TaskExecutor.hpp.
|
private |
Definition at line 405 of file TaskExecutor.hpp.
|
private |
Definition at line 406 of file TaskExecutor.hpp.
|
private |
Definition at line 402 of file TaskExecutor.hpp.
|
mutableprivate |
Definition at line 401 of file TaskExecutor.hpp.
|
private |
Definition at line 404 of file TaskExecutor.hpp.
|
private |
Definition at line 400 of file TaskExecutor.hpp.
|
private |
Definition at line 403 of file TaskExecutor.hpp.