ThreadSchedule 3.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
scheduling.hpp
Go to the documentation of this file.
1#pragma once
2
8#include <cstdint>
9
10#include "nice_value.hpp"
11#include "realtime_priority.hpp"
12
13namespace threadschedule
14{
15
16namespace detail
17{
18struct scheduling_config_access;
19}
20
24enum class scheduling_intent : std::uint8_t
25{
29 normal,
39 nice
40};
41
43enum class priority_level : std::int8_t
44{
45 lowest = 19,
46 low = 5,
47 normal = 0,
48 high = -5,
49 highest = -20
50};
51
56{
57public:
61 [[nodiscard]] constexpr auto
62 intent() const noexcept -> scheduling_intent
63 {
64 return intent_;
65 }
66
71 [[nodiscard]] constexpr auto
72 priority_value() const noexcept -> int
73 {
74 return priority_;
75 }
76
77private:
79 constexpr scheduling_config(scheduling_intent intent, int priority) noexcept : intent_(intent), priority_(priority) {}
80
81 scheduling_intent intent_;
82 int priority_;
83};
84
85namespace detail
86{
87struct scheduling_config_access
88{
89 [[nodiscard]] static constexpr auto
90 make(scheduling_intent intent, int priority = 0) noexcept -> scheduling_config
91 {
92 return scheduling_config(intent, priority);
93 }
94};
95} // namespace detail
96
98namespace schedule
99{
101[[nodiscard]] constexpr auto
103{
104 return detail::scheduling_config_access::make(scheduling_intent::background);
105}
106
108[[nodiscard]] constexpr auto
110{
111 return detail::scheduling_config_access::make(scheduling_intent::normal);
112}
113
115[[nodiscard]] constexpr auto
117{
118 return detail::scheduling_config_access::make(scheduling_intent::interactive);
119}
120
122[[nodiscard]] constexpr auto
124{
125 return detail::scheduling_config_access::make(scheduling_intent::low_latency);
126}
127
132[[nodiscard]] constexpr auto
134{
135 return detail::scheduling_config_access::make(scheduling_intent::realtime_fifo, priority.value());
136}
137
142[[nodiscard]] constexpr auto
144{
145 return detail::scheduling_config_access::make(scheduling_intent::realtime_round_robin, priority.value());
146}
147
152[[nodiscard]] constexpr auto
154{
155 return detail::scheduling_config_access::make(scheduling_intent::nice, value.value());
156}
157
162[[nodiscard]] constexpr auto
164{
165 return nice(nice_value{ static_cast<int>(level) });
166}
167} // namespace schedule
168
169} // namespace threadschedule
Strongly-typed nice value in the POSIX range $[-20, 19]$.
Strongly-typed realtime priority in the range $[1, 99]$.
Immutable scheduling request passed to thread creation/configuration APIs.
friend struct detail::scheduling_config_access
constexpr auto intent() const noexcept -> scheduling_intent
Return the requested scheduling intent.
constexpr auto priority_value() const noexcept -> int
Return the numeric priority payload for the selected intent.
constexpr auto background() noexcept -> scheduling_config
Request background scheduling.
constexpr auto interactive() noexcept -> scheduling_config
Request interactive scheduling.
constexpr auto realtime_rr(realtime_priority priority) noexcept -> scheduling_config
Request realtime round-robin scheduling.
constexpr auto normal() noexcept -> scheduling_config
Request default scheduling.
constexpr auto priority(priority_level level) noexcept -> scheduling_config
Request scheduling via portable priority level presets.
constexpr auto low_latency() noexcept -> scheduling_config
Request low-latency scheduling.
priority_level
Portable non-realtime priority levels.
scheduling_intent
Portable scheduling intents that map to platform-specific behavior.
@ nice
Apply an explicit nice-level priority value.
@ low_latency
Favor low-latency execution where possible.
@ background
Prefer throughput and lower CPU contention over responsiveness.
@ realtime_fifo
Request POSIX FIFO realtime scheduling.
@ realtime_round_robin
Request POSIX round-robin realtime scheduling.
@ interactive
Favor responsiveness for user-facing work.
@ normal
Default scheduler behavior with balanced responsiveness.
Validated POSIX nice priority wrapper.
Validated realtime priority wrapper.