35#include <condition_variable>
62 class job_queue :
public std::enable_shared_from_this<job_queue>,
76 explicit job_queue(std::optional<std::size_t> max_size = std::nullopt);
91 [[nodiscard]]
auto get_ptr(
void) -> std::shared_ptr<job_queue>;
101 [[nodiscard]]
auto is_stopped()
const -> bool;
114 auto schedule(std::unique_ptr<job>&& value) -> common::VoidResult
override {
return enqueue(std::move(value)); }
129 [[nodiscard]]
virtual auto enqueue(std::unique_ptr<job>&& value) -> common::VoidResult;
148 template<
typename JobType,
typename = std::enable_if_t<std::is_base_of_v<job, JobType>>>
149 [[nodiscard]]
auto enqueue(std::unique_ptr<JobType>&& value) -> common::VoidResult
151 return enqueue(std::unique_ptr<job>(std::move(value)));
159 [[nodiscard]]
virtual auto enqueue_batch(std::vector<std::unique_ptr<job>>&& jobs) -> common::VoidResult;
169 [[nodiscard]]
virtual auto dequeue(
void) -> common::Result<std::unique_ptr<job>>;
179 [[nodiscard]]
virtual auto try_dequeue(
void) -> common::Result<std::unique_ptr<job>>;
189 [[nodiscard]]
virtual auto dequeue_batch(
void) -> std::deque<std::unique_ptr<job>>;
212 -> std::deque<std::unique_ptr<job>>;
221 virtual auto clear(
void) -> void;
229 [[nodiscard]]
auto empty(
void)
const -> bool;
237 [[nodiscard]]
auto size(
void)
const -> std::size_t;
264 auto
stop(
void) ->
void;
273 [[nodiscard]] virtual auto
to_string(
void) const ->
std::
string;
290 .atomic_empty_check =
true,
293 .supports_batch =
true,
294 .supports_blocking_wait =
true,
295 .supports_stop =
true
307 [[nodiscard]]
auto is_bounded() const ->
bool;
325 [[nodiscard]] auto
is_full() const ->
bool;
Specialized job class that encapsulates user-defined callbacks.
A thread-safe job queue for managing and dispatching work items.
auto schedule(std::unique_ptr< job > &&value) -> common::VoidResult override
scheduler_interface implementation: schedule a job
auto empty(void) const -> bool
Checks if the queue is currently empty.
virtual auto dequeue_batch(void) -> std::deque< std::unique_ptr< job > >
Dequeues all remaining jobs from the queue without processing them.
auto is_full() const -> bool
Check if queue is at capacity.
virtual ~job_queue(void)
Virtual destructor. Cleans up resources used by the job_queue.
auto stop(void) -> void
Signals the queue to stop waiting for new jobs (e.g., during shutdown).
std::atomic_bool notify_
If true, threads waiting for new jobs are notified when a new job is enqueued. If false,...
auto get_max_size() const -> std::optional< std::size_t >
Get the maximum queue size.
std::mutex mutex_
Mutex to protect access to the underlying queue_ container and related state.
auto set_notify(bool notify) -> void
Sets the 'notify' flag for this queue.
auto size(void) const -> std::size_t
Returns the current number of jobs in the queue.
auto get_memory_stats() const -> memory_stats
Get memory footprint statistics for debugging and monitoring.
virtual auto clear(void) -> void
Removes all jobs currently in the queue without processing them.
virtual auto try_dequeue(void) -> common::Result< std::unique_ptr< job > >
Attempts to dequeue a job from the queue without blocking.
virtual auto to_string(void) const -> std::string
Returns a string representation of this job_queue.
std::atomic< std::size_t > atomic_size_
Atomic size counter for lock-free read-only queries.
std::deque< std::unique_ptr< job > > queue_
The underlying container storing the jobs in FIFO order.
auto is_bounded() const -> bool
Check if queue has a size limit.
job_queue(std::optional< std::size_t > max_size=std::nullopt)
Constructs a new, empty job_queue.
auto get_ptr(void) -> std::shared_ptr< job_queue >
Obtains a std::shared_ptr that points to this queue instance.
std::condition_variable condition_
Condition variable used to signal worker threads.
virtual auto enqueue(std::unique_ptr< job > &&value) -> common::VoidResult
Enqueues a new job into the queue.
auto set_max_size(std::optional< std::size_t > max_size) -> void
Set maximum queue size.
auto get_next_job() -> common::Result< std::unique_ptr< job > > override
scheduler_interface implementation: get next job
virtual auto inspect_pending_jobs(std::size_t limit=100) const -> std::vector< diagnostics::job_info >
Inspects pending jobs in the queue without removing them.
virtual auto dequeue_batch_limited(std::size_t max_count) -> std::deque< std::unique_ptr< job > >
Dequeues up to N jobs in a single operation (micro-batching).
std::atomic_bool stop_
Indicates whether the queue has been signaled to stop.
auto is_stopped() const -> bool
Checks if the queue is in a "stopped" state.
virtual auto dequeue(void) -> common::Result< std::unique_ptr< job > >
Dequeues a job from the queue in FIFO order (blocking operation).
auto get_capabilities() const -> queue_capabilities override
Returns capabilities of this job_queue implementation.
std::optional< std::size_t > max_size_
Optional maximum queue size.
auto enqueue(std::unique_ptr< JobType > &&value) -> common::VoidResult
Type-safe enqueue for job subclasses.
virtual auto enqueue_batch(std::vector< std::unique_ptr< job > > &&jobs) -> common::VoidResult
Enqueues a batch of jobs into the queue.
Represents a unit of work (task) to be executed, typically by a job queue.
Mixin interface for queue capability introspection.
Scheduler interface for queuing and retrieving jobs.
Error codes and utilities for the thread system.
String encoding conversion, Base64 encoding/decoding utilities.
Base job class for schedulable work units in the thread system.
Job information snapshot for diagnostics and monitoring.
Core threading foundation of the thread system library.
Mixin interface for queue capability introspection.
Abstract scheduler interface for queuing and retrieving jobs.
Information about a job for starvation callback.
Get memory footprint statistics for the queue.
std::size_t queue_size_bytes
std::size_t node_overhead_bytes
std::size_t pending_job_count
Runtime-queryable queue capabilities descriptor.