27#include <shared_mutex>
28#include <condition_variable>
29#include <unordered_map>
87 template <
typename job_type = job_types>
206 -> common::VoidResult;
232 [[nodiscard]] auto
enqueue(
std::unique_ptr<
job>&& value) -> common::VoidResult;
241 -> common::VoidResult;
250 template<typename DerivedJob, typename =
std::enable_if_t<
std::is_base_of_v<
typed_job_t<job_type>, DerivedJob>>>
251 [[nodiscard]] auto
enqueue(
std::unique_ptr<DerivedJob>&& value) -> common::VoidResult
263 -> common::VoidResult;
270 [[nodiscard]]
auto dequeue() -> common::Result<std::unique_ptr<job>>;
278 [[nodiscard]]
auto dequeue(
const std::vector<job_type>& types)
279 -> common::Result<std::unique_ptr<typed_job_t<job_type>>>;
288 -> common::Result<std::unique_ptr<typed_job_t<job_type>>>;
293 auto clear() -> void;
301 [[nodiscard]]
auto empty(
const std::vector<job_type>& types)
const -> bool;
328 [[nodiscard]] auto
size() const ->
std::
size_t;
339 std::unordered_map<job_type, std::unique_ptr<queue_type>>
job_queues_;
362 [[nodiscard]]
auto calculate_boost(std::chrono::milliseconds wait_time)
const -> int;
378 std::chrono::milliseconds max_wait,
379 std::chrono::milliseconds total_wait,
380 std::size_t job_count) -> void;
397 -> std::optional<std::unique_ptr<typed_job_t<job_type>>>;
Typed job with priority aging support to prevent starvation.
Bound policies for queue capacity: unbounded or fixed-size.
A typed job queue with priority aging support, based on policy_queue.
auto get_or_create_queue(const job_type &type) -> queue_type *
Get or create a queue for the specified type.
auto get_aging_stats() const -> aging_stats
Gets aging statistics.
priority_aging_config config_
std::chrono::steady_clock::time_point stats_start_time_
aging_typed_job_queue_t(aging_typed_job_queue_t &&)=delete
auto try_dequeue_from_priority(const job_type &priority) -> std::optional< std::unique_ptr< typed_job_t< job_type > > >
Attempts to dequeue a single job from the queue for a given priority.
std::unordered_map< job_type, std::unique_ptr< queue_type > > job_queues_
~aging_typed_job_queue_t()
Destroys the aging typed job queue.
std::shared_mutex queues_mutex_
auto enqueue_batch(std::vector< std::unique_ptr< typed_job_t< job_type > > > &&jobs) -> common::VoidResult
Enqueues a batch of jobs.
auto unregister_aging_job(aging_typed_job_t< job_type > *job) -> void
Unregisters an aging job from tracking.
auto aging_loop() -> void
The main aging loop running in the background thread.
auto stop() -> void
Stops accepting new jobs and marks the queue as stopped.
auto calculate_boost(std::chrono::milliseconds wait_time) const -> int
Calculates the priority boost for a given wait time.
auto reset_aging_stats() -> void
Resets the aging statistics.
aging_typed_job_queue_t(priority_aging_config config={})
Constructs an aging typed job queue.
auto size() const -> std::size_t
Gets the total number of jobs in all queues.
auto apply_aging() -> std::size_t
Manually applies aging to all queued jobs.
auto dequeue() -> common::Result< std::unique_ptr< job > >
Dequeues the next available job.
auto to_string() const -> std::string
Returns a string representation of the queue.
auto set_aging_config(priority_aging_config config) -> void
Sets the aging configuration.
auto is_aging_running() const -> bool
Checks if aging is currently running.
auto get_starving_jobs() const -> std::vector< job_info >
Gets jobs that are approaching starvation.
std::atomic< bool > stopped_
auto check_starvation() -> void
Checks for starving jobs and invokes callbacks.
std::vector< aging_typed_job_t< job_type > * > aging_jobs_
auto operator=(aging_typed_job_queue_t &&) -> aging_typed_job_queue_t &=delete
std::unique_ptr< std::thread > aging_thread_
auto empty(const std::vector< job_type > &types) const -> bool
Checks if there are no jobs in any of the specified priority queues.
auto register_aging_job(aging_typed_job_t< job_type > *job) -> void
Registers an aging job for tracking.
auto update_stats(std::size_t boosts_applied, std::chrono::milliseconds max_wait, std::chrono::milliseconds total_wait, std::size_t job_count) -> void
Updates statistics after applying aging.
auto enqueue(std::unique_ptr< aging_typed_job_t< job_type > > &&value) -> common::VoidResult
Enqueues an aging typed job.
aging_typed_job_queue_t(const aging_typed_job_queue_t &)=delete
auto stop_aging() -> void
Stops the background aging thread.
auto start_aging() -> void
Starts the background aging thread.
std::condition_variable aging_cv_
auto get_aging_config() const -> const priority_aging_config &
Gets the current aging configuration.
auto operator=(const aging_typed_job_queue_t &) -> aging_typed_job_queue_t &=delete
auto clear() -> void
Removes all jobs from all priority queues.
std::atomic< bool > aging_running_
A typed job with priority aging support.
Represents a unit of work (task) to be executed, typically by a job queue.
Synchronization policy using mutex and condition variable.
Policy that rejects new items when queue is full.
Policy that allows unlimited queue size.
Policy-based queue template.
A fallback span implementation for C++17 and earlier compilers.
Job type definitions for the typed thread pool.
Polyfill for std::span on pre-C++20 compilers.
Core threading foundation of the thread system library.
@ priority
Priority-based scheduling.
Policy-based job queue template with customizable sync, bound, and overflow.
Configuration for priority aging and starvation prevention.
Statistics about priority aging behavior.
std::size_t jobs_reached_max_boost
std::chrono::milliseconds avg_wait_time
std::size_t total_boosts_applied
std::chrono::milliseconds max_wait_time
std::size_t starvation_alerts
Information about a job for starvation callback.
Configuration for priority aging behavior.
Synchronization policies: mutex-based or spinlock-based.
Base typed job carrying a specific priority level.