![]() |
LogIt++
Header-only, macro-first C++ logging library
|
Per-instance single-thread executor for isolated async logging. More...
#include <SingleThreadExecutor.hpp>
Public Member Functions | |
| SingleThreadExecutor () | |
| Construct and immediately start the worker thread. | |
| ~SingleThreadExecutor () | |
| Destructor drains and joins the worker thread. | |
| SingleThreadExecutor (const SingleThreadExecutor &)=delete | |
| SingleThreadExecutor & | operator= (const SingleThreadExecutor &)=delete |
| SingleThreadExecutor (SingleThreadExecutor &&)=delete | |
| SingleThreadExecutor & | operator= (SingleThreadExecutor &&)=delete |
| void | add_task (std::function< void()> task) |
| Enqueue a task for asynchronous execution. | |
| void | wait () |
| Block until the queue is empty and no active tasks remain. | |
| void | shutdown () |
| Stop accepting new tasks, drain remaining, and join the worker thread. | |
| void | set_max_queue_size (std::size_t size) |
| Change the maximum queue size (0 disables the limit). | |
| void | set_queue_policy (QueuePolicy policy) |
| Change the queue overflow policy. | |
| std::size_t | dropped_tasks () const noexcept |
| Return the number of tasks dropped by the overflow policy. | |
| void | reset_dropped_tasks () noexcept |
| Reset the drop counter to zero. | |
Private Member Functions | |
| void | worker_loop () |
Private Attributes | |
| std::deque< std::function< void()> > | m_queue |
| std::mutex | m_mutex |
| std::condition_variable | m_cv |
| std::thread | m_worker |
| std::atomic< bool > | m_stop |
| std::atomic< bool > | m_shutdown_done |
| std::size_t | m_max_queue_size |
| QueuePolicy | m_overflow_policy |
| std::atomic< std::size_t > | m_dropped_tasks |
| std::atomic< std::size_t > | m_active_tasks |
Per-instance single-thread executor for isolated async logging.
Provides the same public API as TaskExecutor so loggers can use either executor interchangeably. Unlike the global TaskExecutor singleton, each native instance owns its own worker thread, providing isolation between loggers.
Lifecycle guarantees (native builds):
Single-threaded Emscripten builds use a per-instance cooperative queue drained through the browser event loop instead of a worker thread. See docs/TaskExecutor.md for full semantics.
Definition at line 41 of file SingleThreadExecutor.hpp.
|
inline |
Construct and immediately start the worker thread.
Definition at line 44 of file SingleThreadExecutor.hpp.
|
inline |
Destructor drains and joins the worker thread.
Definition at line 56 of file SingleThreadExecutor.hpp.
|
delete |
|
delete |
|
inline |
Enqueue a task for asynchronous execution.
Definition at line 66 of file SingleThreadExecutor.hpp.
|
inlinenoexcept |
Return the number of tasks dropped by the overflow policy.
Definition at line 153 of file SingleThreadExecutor.hpp.
|
delete |
|
delete |
|
inlinenoexcept |
Reset the drop counter to zero.
Definition at line 158 of file SingleThreadExecutor.hpp.
|
inline |
Change the maximum queue size (0 disables the limit).
No-op if shutdown() has already been called.
Definition at line 134 of file SingleThreadExecutor.hpp.
|
inline |
Change the queue overflow policy.
No-op if shutdown() has already been called.
Definition at line 146 of file SingleThreadExecutor.hpp.
|
inline |
Stop accepting new tasks, drain remaining, and join the worker thread.
After shutdown() returns, add_task() is a no-op and the worker thread has been joined (native) or the queue has been drained (Emscripten). Safe to call multiple times; subsequent calls are no-ops.
Definition at line 113 of file SingleThreadExecutor.hpp.
|
inline |
Block until the queue is empty and no active tasks remain.
Returns once every task that was already accepted by add_task() has completed. Does not prevent new tasks from arriving while waiting.
Definition at line 100 of file SingleThreadExecutor.hpp.
|
inlineprivate |
Definition at line 174 of file SingleThreadExecutor.hpp.
|
private |
Definition at line 172 of file SingleThreadExecutor.hpp.
|
private |
Definition at line 165 of file SingleThreadExecutor.hpp.
|
private |
Definition at line 171 of file SingleThreadExecutor.hpp.
|
private |
Definition at line 169 of file SingleThreadExecutor.hpp.
|
mutableprivate |
Definition at line 164 of file SingleThreadExecutor.hpp.
|
private |
Definition at line 170 of file SingleThreadExecutor.hpp.
|
private |
Definition at line 163 of file SingleThreadExecutor.hpp.
|
private |
Definition at line 168 of file SingleThreadExecutor.hpp.
|
private |
Definition at line 167 of file SingleThreadExecutor.hpp.
|
private |
Definition at line 166 of file SingleThreadExecutor.hpp.