ThreadSchedule 1.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
profiles.hpp File Reference

High-level thread configuration profiles and helpers. More...

#include "concepts.hpp"
#include "scheduler_policy.hpp"
#include "thread_pool.hpp"
#include "thread_registry.hpp"
#include <optional>
#include <string>
Include dependency graph for profiles.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  threadschedule::is_thread_like< ThreadWrapper >
struct  threadschedule::is_thread_like< ThreadWrapperView >
struct  threadschedule::ThreadProfile
 Declarative profile bundling scheduling intent for a thread. More...

Functions

auto threadschedule::profiles::realtime () -> ThreadProfile
 Highest priority profile. Uses FIFO on Linux (if permitted), falls back to OTHER on Windows.
auto threadschedule::profiles::low_latency () -> ThreadProfile
 Low-latency interactive profile using RR scheduling.
auto threadschedule::profiles::throughput () -> ThreadProfile
 Throughput-oriented profile favoring batch scheduling.
auto threadschedule::profiles::background () -> ThreadProfile
 Background profile for very low priority work.
template<typename ThreadLike, std::enable_if_t< is_thread_like_v< ThreadLike >, int > = 0>
auto threadschedule::apply_profile (ThreadLike &t, ThreadProfile const &p) -> expected< void, std::error_code >
 Apply a profile to a thread wrapper or view.
auto threadschedule::apply_profile (ThreadControlBlock &t, ThreadProfile const &p) -> expected< void, std::error_code >
 Apply a profile to a ThreadControlBlock directly.
auto threadschedule::apply_profile (RegisteredThreadInfo &t, ThreadProfile const &p) -> expected< void, std::error_code >
 Apply a profile to a registered thread via its info record.
auto threadschedule::apply_profile (ThreadPool &pool, ThreadProfile const &p) -> expected< void, std::error_code >
 Apply a profile to every worker in a ThreadPool.
auto threadschedule::apply_profile (HighPerformancePool &pool, ThreadProfile const &p) -> expected< void, std::error_code >
 Apply a profile to every worker in a HighPerformancePool.
auto threadschedule::apply_profile (ThreadRegistry &reg, Tid tid, ThreadProfile const &p) -> expected< void, std::error_code >
 Apply a profile to a registry-managed thread identified by TID.

Detailed Description

High-level thread configuration profiles and helpers.

Provides simple presets (e.g. realtime, low_latency, throughput, background) and utility functions to apply them to single threads, thread pools, or registry-managed threads. Profiles abstract low-level flags like policy, priority, and optional CPU affinity into a single intent.

Definition in file profiles.hpp.

Function Documentation

◆ apply_profile() [1/6]

auto threadschedule::apply_profile ( HighPerformancePool & pool,
ThreadProfile const & p ) -> expected<void, std::error_code>
inline

Apply a profile to every worker in a HighPerformancePool.

Uses "hp" as the thread name prefix passed to HighPerformancePool::configure_threads().

Parameters
poolHigh-performance pool to configure.
pProfile to apply.
Returns
Empty expected on success, or operation_not_permitted.

Definition at line 209 of file profiles.hpp.

◆ apply_profile() [2/6]

auto threadschedule::apply_profile ( RegisteredThreadInfo & t,
ThreadProfile const & p ) -> expected<void, std::error_code>
inline

Apply a profile to a registered thread via its info record.

Dereferences t.control and delegates to the ThreadControlBlock overload.

Warning
Undefined behaviour if t.control is nullptr.
Parameters
tRegistered thread info whose control pointer is dereferenced.
pProfile to apply.
Returns
Empty expected on success, or operation_not_permitted.

Definition at line 168 of file profiles.hpp.

◆ apply_profile() [3/6]

auto threadschedule::apply_profile ( ThreadControlBlock & t,
ThreadProfile const & p ) -> expected<void, std::error_code>
inline

Apply a profile to a ThreadControlBlock directly.

Parameters
tControl block whose underlying thread will be reconfigured.
pProfile to apply.
Returns
Empty expected on success, or operation_not_permitted.

Definition at line 141 of file profiles.hpp.

◆ apply_profile() [4/6]

template<typename ThreadLike, std::enable_if_t< is_thread_like_v< ThreadLike >, int > = 0>
auto threadschedule::apply_profile ( ThreadLike & t,
ThreadProfile const & p ) -> expected<void, std::error_code>
inline

Apply a profile to a thread wrapper or view.

SFINAE-constrained: only participates in overload resolution when is_thread_like_v<ThreadLike> is true (ThreadWrapper, JThreadWrapper, PThreadWrapper, and their views).

Template Parameters
ThreadLikeA type satisfying the is_thread_like trait.
Parameters
tThread wrapper or view to configure.
pProfile to apply.
Returns
Empty expected on success, or operation_not_permitted.

Definition at line 119 of file profiles.hpp.

◆ apply_profile() [5/6]

auto threadschedule::apply_profile ( ThreadPool & pool,
ThreadProfile const & p ) -> expected<void, std::error_code>
inline

Apply a profile to every worker in a ThreadPool.

Uses "pool" as the thread name prefix passed to ThreadPool::configure_threads().

Parameters
poolThread pool to configure.
pProfile to apply.
Returns
Empty expected on success, or operation_not_permitted.

Definition at line 183 of file profiles.hpp.

◆ apply_profile() [6/6]

auto threadschedule::apply_profile ( ThreadRegistry & reg,
Tid tid,
ThreadProfile const & p ) -> expected<void, std::error_code>
inline

Apply a profile to a registry-managed thread identified by TID.

Parameters
regThread registry that owns the thread.
tidThread identifier within the registry.
pProfile to apply.
Returns
Empty expected on success, or operation_not_permitted.

Definition at line 232 of file profiles.hpp.

◆ background()

auto threadschedule::profiles::background ( ) -> ThreadProfile
inline

Background profile for very low priority work.

Definition at line 100 of file profiles.hpp.

◆ low_latency()

auto threadschedule::profiles::low_latency ( ) -> ThreadProfile
inline

Low-latency interactive profile using RR scheduling.

Definition at line 84 of file profiles.hpp.

◆ realtime()

auto threadschedule::profiles::realtime ( ) -> ThreadProfile
inline

Highest priority profile. Uses FIFO on Linux (if permitted), falls back to OTHER on Windows.

Definition at line 70 of file profiles.hpp.

◆ throughput()

auto threadschedule::profiles::throughput ( ) -> ThreadProfile
inline

Throughput-oriented profile favoring batch scheduling.

Definition at line 92 of file profiles.hpp.