34#if __cplusplus >= 202002L || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
118 if (!t.set_scheduling_policy(p.policy, p.priority).has_value())
120 if (p.affinity.has_value())
122 if (!t.set_affinity(*p.affinity).has_value())
127 return unexpected(std::make_error_code(std::errc::operation_not_permitted));
133template <
typename PoolType>
138 if (!pool.configure_threads(name_prefix, p.policy, p.priority).has_value())
140 if (p.affinity.has_value())
142 if (!pool.set_affinity(*p.affinity).has_value())
147 return unexpected(std::make_error_code(std::errc::operation_not_permitted));
160template <
typename ThreadLike, std::enable_if_t<is_thread_like_v<ThreadLike>,
int> = 0>
212 if (!reg.set_scheduling_policy(tid, p.policy, p.priority).has_value())
214 if (p.affinity.has_value())
216 if (!reg.set_affinity(tid, *p.affinity).has_value())
221 return unexpected(std::make_error_code(std::errc::operation_not_permitted));
239template <
typename ThreadLike, std::enable_if_t<is_thread_like_v<ThreadLike>,
int> = 0>
242 std::vector<std::error_code> results;
243 auto policy_result = t.set_scheduling_policy(p.policy, p.priority);
244 results.push_back(policy_result.has_value() ? std::error_code{} : policy_result.error());
245 if (p.affinity.has_value())
247 auto aff_result = t.set_affinity(*p.affinity);
248 results.push_back(aff_result.has_value() ? std::error_code{} : aff_result.error());
259 std::vector<std::error_code> results;
260 auto policy_result = t.set_scheduling_policy(p.policy, p.priority);
261 results.push_back(policy_result.has_value() ? std::error_code{} : policy_result.error());
262 if (p.affinity.has_value())
264 auto aff_result = t.set_affinity(*p.affinity);
265 results.push_back(aff_result.has_value() ? std::error_code{} : aff_result.error());
Per-thread control handle for OS-level scheduling operations.
Value-semantic wrapper for a thread scheduling priority.
static constexpr auto normal() noexcept -> ThreadPriority
static constexpr auto highest() noexcept -> ThreadPriority
static constexpr auto lowest() noexcept -> ThreadPriority
Central registry of threads indexed by OS-level thread ID (Tid).
Non-owning view over an externally managed std::thread.
Owning wrapper around std::thread with RAII join-on-destroy semantics.
A result type that holds either a value of type T or an error of type E.
Exception thrown by expected::value() when the object is in the error state.
C++20 concepts, type traits, and SFINAE helpers for the threading library.
auto apply_profile_to(T &t, ThreadProfile const &p) -> expected< void, std::error_code >
Apply policy + optional affinity to any type exposing set_scheduling_policy() and set_affinity().
auto apply_profile_to_pool(PoolType &pool, std::string const &name_prefix, ThreadProfile const &p) -> expected< void, std::error_code >
Apply configure_threads + optional affinity to any pool type.
auto throughput() -> ThreadProfile
Throughput-oriented profile favoring batch scheduling.
auto background() -> ThreadProfile
Background profile for very low priority work.
auto low_latency() -> ThreadProfile
Low-latency interactive profile using RR scheduling.
auto realtime() -> ThreadProfile
Highest priority profile. Uses FIFO on Linux (if permitted), falls back to OTHER on Windows.
SchedulingPolicy
Enumeration of available thread scheduling policies.
@ OTHER
Standard round-robin time-sharing.
@ BATCH
For batch style execution.
@ IDLE
For very low priority background tasks.
@ FIFO
First in, first out.
auto apply_profile_detailed(ThreadLike &t, ThreadProfile const &p) -> std::vector< std::error_code >
Apply a profile and return per-step error codes.
ThreadPoolBase< IndefiniteWait > ThreadPool
General-purpose thread pool with indefinite blocking wait.
auto apply_profile(ThreadLike &t, ThreadProfile const &p) -> expected< void, std::error_code >
Apply a profile to a thread wrapper or view.
ThreadWrapperView JThreadWrapperView
ThreadPoolBase< PollingWait<> > FastThreadPool
Thread pool with 10 ms polling wait for lower wake-up latency.
ThreadWrapper JThreadWrapper
Owning wrapper around std::jthread with cooperative cancellation (C++20).
Scheduling policies, thread priority, and CPU affinity types.
Snapshot of metadata for a single registered thread.
Declarative profile bundling scheduling intent for a thread.
std::optional< ThreadAffinity > affinity
Type trait that identifies thread-like types.
Thread pools: HighPerformancePool, ThreadPoolBase, LightweightPoolT, and GlobalPool.
Process-wide thread registry, control blocks, and composite registry.