Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
kcenon::thread::policies::dynamic_bounded_policy Class Reference

Policy with dynamically adjustable size limit. More...

#include <bound_policies.h>

Collaboration diagram for kcenon::thread::policies::dynamic_bounded_policy:
Collaboration graph

Public Types

using policy_tag = bound_policy_tag
 

Public Member Functions

constexpr dynamic_bounded_policy (std::optional< std::size_t > max=std::nullopt) noexcept
 Construct with optional max size.
 
constexpr auto is_full (std::size_t current_size) const noexcept -> bool
 Check if queue is at capacity.
 
constexpr auto max_size () const noexcept -> std::optional< std::size_t >
 Get maximum size.
 
constexpr auto is_bounded () const noexcept -> bool
 Check if this is currently bounded.
 
constexpr auto remaining_capacity (std::size_t current_size) const noexcept -> std::size_t
 Get remaining capacity.
 
auto set_max_size (std::size_t new_max) noexcept -> void
 Set new maximum size.
 
auto set_unbounded () noexcept -> void
 Remove size limit (become unbounded)
 

Private Attributes

std::optional< std::size_t > max_size_
 

Detailed Description

Policy with dynamically adjustable size limit.

Similar to bounded_policy but allows runtime changes to the limit and can be switched to unbounded mode.

Usage

// Later:
bound.set_max_size(2000); // Increase limit
bound.set_unbounded(); // Remove limit entirely
Policy with dynamically adjustable size limit.

Definition at line 177 of file bound_policies.h.

Member Typedef Documentation

◆ policy_tag

Constructor & Destructor Documentation

◆ dynamic_bounded_policy()

kcenon::thread::policies::dynamic_bounded_policy::dynamic_bounded_policy ( std::optional< std::size_t > max = std::nullopt)
inlineexplicitconstexprnoexcept

Construct with optional max size.

Parameters
maxOptional maximum size (nullopt for unbounded)

Definition at line 185 of file bound_policies.h.

187 : max_size_(max) {}

Member Function Documentation

◆ is_bounded()

auto kcenon::thread::policies::dynamic_bounded_policy::is_bounded ( ) const -> bool
inlinenodiscardconstexprnoexcept

Check if this is currently bounded.

Returns
true if max size is set

Definition at line 213 of file bound_policies.h.

213 {
214 return max_size_.has_value();
215 }

References max_size_.

◆ is_full()

auto kcenon::thread::policies::dynamic_bounded_policy::is_full ( std::size_t current_size) const -> bool
inlinenodiscardconstexprnoexcept

Check if queue is at capacity.

Parameters
current_sizeCurrent queue size
Returns
true if bounded and at or above max size

Definition at line 194 of file bound_policies.h.

194 {
195 if (!max_size_.has_value()) {
196 return false;
197 }
198 return current_size >= max_size_.value();
199 }

References max_size_.

◆ max_size()

auto kcenon::thread::policies::dynamic_bounded_policy::max_size ( ) const -> std::optional<std::size_t>
inlinenodiscardconstexprnoexcept

Get maximum size.

Returns
The configured maximum size, or nullopt if unbounded

Definition at line 205 of file bound_policies.h.

205 {
206 return max_size_;
207 }

References max_size_.

◆ remaining_capacity()

auto kcenon::thread::policies::dynamic_bounded_policy::remaining_capacity ( std::size_t current_size) const -> std::size_t
inlinenodiscardconstexprnoexcept

Get remaining capacity.

Parameters
current_sizeCurrent queue size
Returns
Number of items that can still be added

Definition at line 222 of file bound_policies.h.

222 {
223 if (!max_size_.has_value()) {
224 return std::numeric_limits<std::size_t>::max();
225 }
226 if (current_size >= max_size_.value()) {
227 return 0;
228 }
229 return max_size_.value() - current_size;
230 }

References max_size_.

◆ set_max_size()

auto kcenon::thread::policies::dynamic_bounded_policy::set_max_size ( std::size_t new_max) -> void
inlinenoexcept

Set new maximum size.

Parameters
new_maxNew maximum size

Definition at line 236 of file bound_policies.h.

236 {
237 max_size_ = new_max;
238 }

References max_size_.

◆ set_unbounded()

auto kcenon::thread::policies::dynamic_bounded_policy::set_unbounded ( ) -> void
inlinenoexcept

Remove size limit (become unbounded)

Definition at line 243 of file bound_policies.h.

243 {
244 max_size_ = std::nullopt;
245 }

References max_size_.

Member Data Documentation

◆ max_size_

std::optional<std::size_t> kcenon::thread::policies::dynamic_bounded_policy::max_size_
private

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