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

Policy that blocks for a limited time when queue is full. More...

#include <overflow_policies.h>

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

Public Types

using policy_tag = overflow_policy_tag
 

Public Member Functions

 overflow_timeout_policy (std::chrono::milliseconds timeout)
 Construct with timeout duration.
 
 overflow_timeout_policy ()
 Default constructor with 1 second timeout.
 
auto timeout () const noexcept -> std::chrono::milliseconds
 Get the configured timeout.
 
auto set_timeout (std::chrono::milliseconds timeout) noexcept -> void
 Set new timeout duration.
 
auto handle_overflow (std::unique_ptr< job > &&value) -> std::pair< common::VoidResult, std::unique_ptr< job > >
 Handle overflow by indicating need to wait with timeout.
 

Static Public Member Functions

static constexpr auto blocks () noexcept -> bool
 Check if this policy blocks on overflow.
 
static constexpr auto name () noexcept -> const char *
 Get a descriptive name for this policy.
 

Private Attributes

std::chrono::milliseconds timeout_
 

Detailed Description

Policy that blocks for a limited time when queue is full.

When the queue is full, the enqueue operation blocks for up to the configured timeout duration. If space doesn't become available within the timeout, the operation fails.

Use Cases

  • Bounded waits where indefinite blocking is unacceptable
  • Timeout-based flow control
  • Interactive systems with response time requirements
Warning
Requires sync policy with blocking wait support

Definition at line 262 of file overflow_policies.h.

Member Typedef Documentation

◆ policy_tag

Constructor & Destructor Documentation

◆ overflow_timeout_policy() [1/2]

kcenon::thread::policies::overflow_timeout_policy::overflow_timeout_policy ( std::chrono::milliseconds timeout)
inlineexplicit

Construct with timeout duration.

Parameters
timeoutMaximum time to wait for space

Definition at line 270 of file overflow_policies.h.

271 : timeout_(timeout) {}
auto timeout() const noexcept -> std::chrono::milliseconds
Get the configured timeout.

◆ overflow_timeout_policy() [2/2]

kcenon::thread::policies::overflow_timeout_policy::overflow_timeout_policy ( )
inline

Default constructor with 1 second timeout.

Definition at line 276 of file overflow_policies.h.

276: timeout_(std::chrono::seconds(1)) {}

Member Function Documentation

◆ blocks()

static constexpr auto kcenon::thread::policies::overflow_timeout_policy::blocks ( ) -> bool
inlinestaticnodiscardconstexprnoexcept

Check if this policy blocks on overflow.

Returns
true (blocks with timeout)

Definition at line 309 of file overflow_policies.h.

309 {
310 return true;
311 }

◆ handle_overflow()

auto kcenon::thread::policies::overflow_timeout_policy::handle_overflow ( std::unique_ptr< job > && value) -> std::pair<common::VoidResult, std::unique_ptr<job>>
inlinenodiscard

Handle overflow by indicating need to wait with timeout.

Parameters
valueThe job to be added
Returns
Result with job for retry

Definition at line 299 of file overflow_policies.h.

300 {
301 return {common::error_info{-123, "queue full, waiting with timeout", "thread_system"},
302 std::move(value)};
303 }

◆ name()

static constexpr auto kcenon::thread::policies::overflow_timeout_policy::name ( ) -> const char*
inlinestaticnodiscardconstexprnoexcept

Get a descriptive name for this policy.

Returns
Policy name string

Definition at line 317 of file overflow_policies.h.

317 {
318 return "overflow_timeout";
319 }

◆ set_timeout()

auto kcenon::thread::policies::overflow_timeout_policy::set_timeout ( std::chrono::milliseconds timeout) -> void
inlinenoexcept

Set new timeout duration.

Parameters
timeoutNew timeout value

Definition at line 290 of file overflow_policies.h.

290 {
292 }

References timeout(), and timeout_.

Here is the call graph for this function:

◆ timeout()

auto kcenon::thread::policies::overflow_timeout_policy::timeout ( ) const -> std::chrono::milliseconds
inlinenodiscardnoexcept

Get the configured timeout.

Returns
Timeout duration

Definition at line 282 of file overflow_policies.h.

282 {
283 return timeout_;
284 }

References timeout_.

Referenced by set_timeout().

Here is the caller graph for this function:

Member Data Documentation

◆ timeout_

std::chrono::milliseconds kcenon::thread::policies::overflow_timeout_policy::timeout_
private

Definition at line 322 of file overflow_policies.h.

Referenced by set_timeout(), and timeout().


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