Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
kcenon::thread::aged_priority< P > Struct Template Reference

Priority with aging support. More...

#include <priority_aging_config.h>

Inheritance diagram for kcenon::thread::aged_priority< P >:
Inheritance graph
Collaboration diagram for kcenon::thread::aged_priority< P >:
Collaboration graph

Public Member Functions

auto effective_priority () const -> P
 Calculates the effective priority including boost.
 
auto wait_time () const -> std::chrono::milliseconds
 Calculates the time this job has been waiting.
 
auto apply_boost (int boost_amount, int max_boost) -> void
 Applies a boost to the priority.
 
auto reset_boost () -> void
 Resets the boost to zero.
 
auto is_max_boosted (int max_boost) const -> bool
 Checks if this job has reached max boost.
 

Public Attributes

base_priority
 The original priority level of the job.
 
int boost {0}
 The current priority boost value.
 
std::chrono::steady_clock::time_point enqueue_time
 The time when the job was enqueued.
 

Detailed Description

template<typename P>
struct kcenon::thread::aged_priority< P >

Priority with aging support.

This structure wraps a base priority value with aging information, including the current boost level and enqueue time. It provides methods to calculate the effective priority and wait time.

Template Parameters
PThe base priority type (typically an enum or integral type).

Example Usage

job_types::Background, // base_priority
0, // initial boost
std::chrono::steady_clock::now() // enqueue_time
};
// Apply boost
ap.apply_boost(1, 3); // boost by 1, max 3
// Get effective priority
auto effective = ap.effective_priority();
@ Background
Background job for low-type maintenance tasks.
Priority with aging support.
auto apply_boost(int boost_amount, int max_boost) -> void
Applies a boost to the priority.

Definition at line 174 of file priority_aging_config.h.

Member Function Documentation

◆ apply_boost()

template<typename P >
auto kcenon::thread::aged_priority< P >::apply_boost ( int boost_amount,
int max_boost ) -> void
inline

Applies a boost to the priority.

Parameters
boost_amountThe amount to boost.
max_boostThe maximum allowed boost.

Definition at line 233 of file priority_aging_config.h.

234 {
235 boost += boost_amount;
236 if (boost > max_boost)
237 {
238 boost = max_boost;
239 }
240 }
int boost
The current priority boost value.

References kcenon::thread::aged_priority< P >::boost.

◆ effective_priority()

template<typename P >
auto kcenon::thread::aged_priority< P >::effective_priority ( ) const -> P
inlinenodiscard

Calculates the effective priority including boost.

For enum types, the boost is subtracted from the enum value (lower enum value = higher priority). For integral types, the boost is added.

Returns
The effective priority value.

Definition at line 204 of file priority_aging_config.h.

205 {
206 // For enum types, lower values typically mean higher priority
207 // Subtracting boost moves toward higher priority (lower enum value)
208 auto base_value = static_cast<int>(base_priority);
209 auto boosted_value = base_value - boost;
210 // Clamp to valid range (minimum 0)
211 boosted_value = (boosted_value < 0) ? 0 : boosted_value;
212 return static_cast<P>(boosted_value);
213 }
P base_priority
The original priority level of the job.

References kcenon::thread::aged_priority< P >::base_priority, and kcenon::thread::aged_priority< P >::boost.

◆ is_max_boosted()

template<typename P >
auto kcenon::thread::aged_priority< P >::is_max_boosted ( int max_boost) const -> bool
inlinenodiscard

Checks if this job has reached max boost.

Parameters
max_boostThe maximum allowed boost.
Returns
true if boost equals max_boost.

Definition at line 256 of file priority_aging_config.h.

257 {
258 return boost >= max_boost;
259 }

References kcenon::thread::aged_priority< P >::boost.

Referenced by kcenon::thread::aging_typed_job_t< job_type >::is_max_boosted().

Here is the caller graph for this function:

◆ reset_boost()

template<typename P >
auto kcenon::thread::aged_priority< P >::reset_boost ( ) -> void
inline

Resets the boost to zero.

Definition at line 245 of file priority_aging_config.h.

246 {
247 boost = 0;
248 }

References kcenon::thread::aged_priority< P >::boost.

◆ wait_time()

template<typename P >
auto kcenon::thread::aged_priority< P >::wait_time ( ) const -> std::chrono::milliseconds
inlinenodiscard

Calculates the time this job has been waiting.

Returns
The wait time since enqueue.

Definition at line 220 of file priority_aging_config.h.

221 {
222 return std::chrono::duration_cast<std::chrono::milliseconds>(
223 std::chrono::steady_clock::now() - enqueue_time
224 );
225 }
std::chrono::steady_clock::time_point enqueue_time
The time when the job was enqueued.

References kcenon::thread::aged_priority< P >::enqueue_time.

Member Data Documentation

◆ base_priority

template<typename P >
P kcenon::thread::aged_priority< P >::base_priority

The original priority level of the job.

Definition at line 179 of file priority_aging_config.h.

Referenced by kcenon::thread::aged_priority< P >::effective_priority().

◆ boost

template<typename P >
int kcenon::thread::aged_priority< P >::boost {0}

The current priority boost value.

This value is added to the base priority to get the effective priority.

Definition at line 186 of file priority_aging_config.h.

186{0};

Referenced by kcenon::thread::aged_priority< P >::apply_boost(), kcenon::thread::aged_priority< P >::effective_priority(), kcenon::thread::aged_priority< P >::is_max_boosted(), and kcenon::thread::aged_priority< P >::reset_boost().

◆ enqueue_time

template<typename P >
std::chrono::steady_clock::time_point kcenon::thread::aged_priority< P >::enqueue_time

The time when the job was enqueued.

Used to calculate wait time for aging purposes.

Definition at line 193 of file priority_aging_config.h.

Referenced by kcenon::thread::aged_priority< P >::wait_time().


The documentation for this struct was generated from the following file: