14#include "scheduler_policy.hpp"
15#include "thread_pool.hpp"
16#include "thread_registry.hpp"
20namespace threadschedule
33#if __cplusplus >= 202002L || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
40struct is_thread_like<JThreadWrapperView> : std::true_type
59 SchedulingPolicy policy;
61 std::optional<ThreadAffinity> affinity;
74 SchedulingPolicy::OTHER,
76 SchedulingPolicy::FIFO,
78 ThreadPriority::highest(), std::nullopt};
94 return ThreadProfile{
"throughput", SchedulingPolicy::BATCH, ThreadPriority::normal(), std::nullopt};
102 return ThreadProfile{
"background", SchedulingPolicy::IDLE, ThreadPriority::lowest(), std::nullopt};
118template <
typename ThreadLike, std::enable_if_t<is_thread_like_v<ThreadLike>,
int> = 0>
122 if (!t.set_scheduling_policy(p.policy, p.priority).has_value())
124 if (p.affinity.has_value())
126 if (!t.set_affinity(*p.affinity).has_value())
131 return unexpected(std::make_error_code(std::errc::operation_not_permitted));
144 if (!t.set_scheduling_policy(p.policy, p.priority).has_value())
146 if (p.affinity.has_value())
148 if (!t.set_affinity(*p.affinity).has_value())
153 return unexpected(std::make_error_code(std::errc::operation_not_permitted));
187 if (!pool.configure_threads(
"pool", p.policy, p.priority))
189 if (p.affinity.has_value())
191 if (!pool.set_affinity(*p.affinity))
196 return unexpected(std::make_error_code(std::errc::operation_not_permitted));
212 if (!pool.configure_threads(
"hp", p.policy, p.priority).has_value())
214 if (p.affinity.has_value())
216 if (!pool.set_affinity(*p.affinity).has_value())
221 return unexpected(std::make_error_code(std::errc::operation_not_permitted));
235 if (!reg.set_scheduling_policy(tid, p.policy, p.priority).has_value())
237 if (p.affinity.has_value())
239 if (!reg.set_affinity(tid, *p.affinity).has_value())
244 return unexpected(std::make_error_code(std::errc::operation_not_permitted));
Per-thread control handle for OS-level scheduling operations.
Simple, general-purpose thread pool.
Value-semantic wrapper for a thread scheduling priority.
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(ThreadLike &t, ThreadProfile const &p) -> expected< void, std::error_code >
Apply a profile to a thread wrapper or view.
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.
Snapshot of metadata for a single registered thread.
Declarative profile bundling scheduling intent for a thread.
Type trait that identifies thread-like types.