15#ifndef NUMAPP_SCHEDULER_HPP_
16#define NUMAPP_SCHEDULER_HPP_
18#include <system_error>
48[[nodiscard]] std::error_code
Apply(pid_t thread, IdleScheduler
const& scheduler)
noexcept;
90[[nodiscard]] std::error_code
Apply(pid_t thread, Scheduler
const& scheduler)
noexcept;
113[[nodiscard]] std::error_code
Apply(IdleScheduler
const& scheduler)
noexcept;
152[[nodiscard]] std::error_code
Apply(Scheduler
const& scheduler)
noexcept;
169 IdleScheduler()
noexcept =
default;
170 explicit constexpr IdleScheduler(IdleScheduler&&)
noexcept =
default;
171 explicit constexpr IdleScheduler(IdleScheduler
const&)
noexcept =
default;
172 constexpr IdleScheduler& operator=(IdleScheduler&&)
noexcept =
default;
173 constexpr IdleScheduler& operator=(IdleScheduler
const&)
noexcept =
default;
175 [[nodiscard]]
constexpr bool operator==(IdleScheduler
const& rhs)
const {
178 [[nodiscard]]
bool operator!=(IdleScheduler
const& rhs)
const {
185 [[nodiscard]] std::error_code
Apply() const noexcept;
197std::ostream& operator<<(std::ostream& os, IdleScheduler const& scheduler);
247 [[nodiscard]]
bool operator==(
StaticScheduler const& rhs) const noexcept {
248 return m_policy == rhs.m_policy && m_prio == rhs.m_prio;
250 [[nodiscard]]
bool operator!=(
StaticScheduler const& rhs)
const noexcept {
251 return !(*
this == rhs);
356 return m_policy == rhs.m_policy && m_priority == rhs.m_priority;
360 return !(*
this == rhs);
457 Scheduler(Scheduler&&)
noexcept =
default;
458 Scheduler(Scheduler
const&) =
default;
460 Scheduler& operator=(Scheduler&& rhs)
noexcept =
default;
461 Scheduler& operator=(Scheduler
const&)
noexcept =
default;
463 [[nodiscard]]
bool operator==(Scheduler
const& rhs)
const noexcept {
464 return m_scheduler == rhs.m_scheduler;
466 [[nodiscard]]
bool operator!=(Scheduler
const& rhs)
const noexcept {
467 return !(*
this == rhs);
479 return std::holds_alternative<T>(m_scheduler);
491 return std::get<T>(m_scheduler);
533std::ostream& operator<<(std::ostream& os, Scheduler const& scheduler);
Normal non-realtime scheduler that use dynamic priority (nice value).
@ Batch
For "batch" style execution of processes.
@ Other
The standard round-robin time-sharing policy.
constexpr Policy GetPolicy() const noexcept
DynamicScheduler(Policy policy=Policy::Other, int nice=0)
std::error_code SetNice(int value) noexcept
Set dynamic nice value (dynamic priority) of thread.
std::error_code SetPolicy(Policy policy) noexcept
Set policy.
int GetNice() const noexcept
Get dynamic nice value.
std::ostream & operator<<(std::ostream &os, DynamicScheduler const &scheduler)
Formats scheduler and inserts it to os.
std::ostream & operator<<(std::ostream &os, DynamicScheduler const &policy)
Formats policy and inserts it to os.
Represents SCHED_IDLE scheduler policy.
std::error_code Apply() const noexcept
Apply policy to calling thread.
std::ostream & operator<<(std::ostream &os, IdleScheduler const &scheduler)
Formats scheduler and inserts it to os.
A sum-type of all supported schedulers.
SchedulerVariant const & Get() const noexcept
Get the underlying scheduler.
static Scheduler MakeFromActive()
Return active scheduler policy for this thread.
constexpr T GetScheduler() const
Get the held scheduler.
constexpr bool HoldsScheduler() const noexcept
Query the held scheduler.
static Scheduler MakeFromActive(pid_t pid)
Return active scheduler policy for thread with pid.
Static priority scheduler (real-time).
std::ostream & operator<<(std::ostream &os, StaticScheduler const &scheduler)
Formats scheduler and inserts it to os.
constexpr int GetPriority() const noexcept
Get static priority.
StaticScheduler(Policy policy, int priority)
Create with provided policy and priority.
@ Fifo
A first-in, first-out "real-time" policy.
@ Rr
A roound-robin, "real-time" policy.
std::error_code SetPriority(int priority)
Set static priority 0 - 99.
constexpr Policy GetPolicy() const noexcept
std::error_code SetPolicy(Policy policy) noexcept
Set policy.
std::error_code Apply(pid_t thread, IdleScheduler const &scheduler) noexcept
Apply idle scheduler to specified thread.
std::variant< DynamicScheduler, StaticScheduler, IdleScheduler > SchedulerVariant
Variant of possible schedulers.
std::error_code Apply(StaticScheduler const &scheduler) noexcept
Apply static scheduler to this thread.
std::error_code Apply(pid_t thread, DynamicScheduler const &scheduler) noexcept
Apply dynamic scheduler to specified thread.
std::error_code Apply(Scheduler const &scheduler) noexcept
Apply variadic scheduler to this thread.
std::error_code Apply(DynamicScheduler const &scheduler) noexcept
Apply dynamic scheduler to this thread.
std::error_code Apply(IdleScheduler const &scheduler) noexcept
Apply idle scheduler to this thread.
std::error_code Apply(pid_t thread, Scheduler const &scheduler) noexcept
Apply variadic scheduler to specified thread.
std::error_code Apply(pid_t thread, StaticScheduler const &scheduler) noexcept
Apply static scheduler to specified thread.