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

Policy that limits queue size to a maximum. More...

#include <bound_policies.h>

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

Public Types

using policy_tag = bound_policy_tag
 

Public Member Functions

constexpr bounded_policy (std::size_t max) noexcept
 Construct bounded policy with 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 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.
 

Static Public Member Functions

static constexpr auto is_bounded () noexcept -> bool
 Check if this is a bounded policy.
 

Private Attributes

std::size_t max_size_
 

Detailed Description

Policy that limits queue size to a maximum.

This policy enforces a maximum queue size. When the queue is full, enqueue operations may fail or block depending on the overflow policy.

Thread Safety

  • Thread-safe for concurrent access
  • Size checks are based on provided current_size parameter

Usage

bounded_policy bound(1000); // Max 1000 items
Policy that limits queue size to a maximum.
Policy-based queue template.

Definition at line 99 of file bound_policies.h.

Member Typedef Documentation

◆ policy_tag

Constructor & Destructor Documentation

◆ bounded_policy()

kcenon::thread::policies::bounded_policy::bounded_policy ( std::size_t max)
inlineexplicitconstexprnoexcept

Construct bounded policy with max size.

Parameters
maxMaximum queue size

Definition at line 107 of file bound_policies.h.

Member Function Documentation

◆ is_bounded()

static constexpr auto kcenon::thread::policies::bounded_policy::is_bounded ( ) -> bool
inlinestaticnodiscardconstexprnoexcept

Check if this is a bounded policy.

Returns
true

Definition at line 131 of file bound_policies.h.

131 {
132 return true;
133 }

◆ is_full()

auto kcenon::thread::policies::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 at or above max size

Definition at line 115 of file bound_policies.h.

115 {
116 return current_size >= max_size_;
117 }

References max_size_.

◆ max_size()

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

Get maximum size.

Returns
The configured maximum size

Definition at line 123 of file bound_policies.h.

123 {
124 return max_size_;
125 }

References max_size_.

◆ remaining_capacity()

auto kcenon::thread::policies::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 140 of file bound_policies.h.

140 {
141 if (current_size >= max_size_) {
142 return 0;
143 }
144 return max_size_ - current_size;
145 }

References max_size_.

◆ set_max_size()

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

Set new maximum size.

Parameters
new_maxNew maximum size
Note
If new max is smaller than current size, queue becomes over-capacity. Overflow handling depends on the overflow policy.

Definition at line 154 of file bound_policies.h.

154 {
155 max_size_ = new_max;
156 }

References max_size_.

Member Data Documentation

◆ max_size_

std::size_t kcenon::thread::policies::bounded_policy::max_size_
private

Definition at line 159 of file bound_policies.h.

Referenced by is_full(), max_size(), remaining_capacity(), and set_max_size().


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