Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
aging_typed_job.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
12#pragma once
13
14#include "typed_job.h"
16
17#include <functional>
18#include <string>
19
20namespace kcenon::thread
21{
54 template <typename job_type>
55 class aging_typed_job_t : public typed_job_t<job_type>
56 {
57 public:
59
68 std::function<common::VoidResult()> work,
69 const std::string& name = "aging_job");
70
75
76 // Non-copyable
79
80 // Movable
81 aging_typed_job_t(aging_typed_job_t&&) noexcept = default;
82 auto operator=(aging_typed_job_t&&) noexcept -> aging_typed_job_t& = default;
83
89 [[nodiscard]] auto do_work() -> common::VoidResult override;
90
96 [[nodiscard]] auto get_aged_priority() const -> const aged_priority<job_type>&;
97
103 [[nodiscard]] auto get_aged_priority() -> aged_priority<job_type>&;
104
112 auto apply_boost(int boost_amount) -> void;
113
117 auto reset_boost() -> void;
118
124 auto set_max_boost(int max) -> void;
125
131 [[nodiscard]] auto get_max_boost() const -> int;
132
138 [[nodiscard]] auto is_max_boosted() const -> bool;
139
145 [[nodiscard]] auto effective_priority() const -> job_type;
146
152 [[nodiscard]] auto wait_time() const -> std::chrono::milliseconds;
153
159 [[nodiscard]] auto to_job_info() const -> job_info;
160
161 private:
164 std::function<common::VoidResult()> work_;
165 };
166
172
173} // namespace kcenon::thread
A typed job with priority aging support.
std::function< common::VoidResult()> work_
auto get_aged_priority() const -> const aged_priority< job_type > &
Gets the aged priority information.
auto do_work() -> common::VoidResult override
Executes the job's work function.
aging_typed_job_t(const aging_typed_job_t &)=delete
auto effective_priority() const -> job_type
Gets the effective priority after applying boost.
aged_priority< job_type > aged_priority_
auto set_max_boost(int max) -> void
Sets the maximum allowed boost.
auto to_job_info() const -> job_info
Creates job_info for starvation callbacks.
auto operator=(const aging_typed_job_t &) -> aging_typed_job_t &=delete
auto reset_boost() -> void
Resets the priority boost to zero.
auto is_max_boosted() const -> bool
Checks if this job has reached maximum boost.
aging_typed_job_t(job_type priority, std::function< common::VoidResult()> work, const std::string &name="aging_job")
Constructs a new aging typed job.
auto get_max_boost() const -> int
Gets the maximum allowed boost.
~aging_typed_job_t() override
Destroys the aging typed job.
aging_typed_job_t(aging_typed_job_t &&) noexcept=default
auto apply_boost(int boost_amount) -> void
Applies a priority boost to this job.
auto wait_time() const -> std::chrono::milliseconds
Gets the time this job has been waiting.
Typed job template.
Definition typed_job.h:31
auto priority() const -> job_type
Retrieves the priority level of this job.
Definition typed_job.h:55
Core threading foundation of the thread system library.
Definition thread_impl.h:17
STL namespace.
Configuration for priority aging and starvation prevention.
Priority with aging support.
Information about a job for starvation callback.
Base typed job carrying a specific priority level.