32#include <condition_variable>
175 [[nodiscard]]
bool is_running() const noexcept;
189 [[nodiscard]] std::
size_t capacity() const noexcept;
198#if LOGGER_HAS_JTHREAD
230#if LOGGER_HAS_JTHREAD
Standalone async worker with jthread compatibility.
compat_jthread worker_thread_
Background worker thread.
const std::size_t queue_size_
Maximum queue capacity.
void worker_loop(simple_stop_source &stop)
Worker thread main loop (fallback version)
std::size_t pending_count() const
Get the current queue size.
void drain_queue()
Process all remaining tasks in the queue.
void start()
Start the worker thread.
~async_worker()
Destructor - ensures graceful shutdown.
async_worker & operator=(async_worker &&)=delete
async_worker(const async_worker &)=delete
void flush()
Flush all pending tasks.
std::atomic< bool > running_
Worker state flag.
async_worker & operator=(const async_worker &)=delete
void stop()
Stop the worker thread gracefully.
std::queue< task_type > queue_
Task queue.
std::atomic< std::uint64_t > dropped_count_
Overflow counter.
std::size_t capacity() const noexcept
Get the queue capacity.
std::mutex queue_mutex_
Protects queue_ access.
async_worker(async_worker &&)=delete
std::uint64_t dropped_count() const noexcept
Get the number of dropped tasks due to queue overflow.
std::condition_variable queue_cv_
Signals new tasks or stop (fallback)
bool is_running() const noexcept
Check if the worker is currently running.
bool enqueue(task_type task)
Enqueue a task for async processing.
async_worker(std::size_t queue_size=8192)
Constructor with configurable queue size.
Wrapper for std::jthread or std::thread with manual stop mechanism.
Simple stop source for environments without std::stop_token.
Compatibility header for std::jthread and std::stop_token kcenon.
std::function< void()> task_type
Task type for async worker.