ThreadSchedule 3.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
realtime_priority.hpp
Go to the documentation of this file.
1#pragma once
2
8#include "result.hpp"
9
10#include <stdexcept>
11
12namespace threadschedule
13{
14
19{
20public:
22 static constexpr int minimum = 1;
24 static constexpr int maximum = 99;
25
31 constexpr explicit realtime_priority(int value) : value_(checked(value)) {}
32
38 [[nodiscard]] static auto
40 {
41 if (value < minimum || value > maximum)
42 return unexpected(std::make_error_code(std::errc::invalid_argument));
43 return realtime_priority(unchecked_tag{}, value);
44 }
45
47 [[nodiscard]] constexpr auto
48 value() const noexcept -> int
49 {
50 return value_;
51 }
52
53 friend constexpr auto
55 {
56 return lhs.value_ == rhs.value_;
57 }
58 friend constexpr auto
60 {
61 return !(lhs == rhs);
62 }
63
64private:
65 struct unchecked_tag
66 {
67 };
68 constexpr realtime_priority(unchecked_tag, int value) noexcept : value_(value) {}
69
70 [[nodiscard]] static constexpr auto
71 checked(int value) -> int
72 {
73 if (value < minimum || value > maximum)
74 throw std::invalid_argument("realtime_priority must be in the range 1..99");
75 return value;
76 }
77
78 int value_;
79};
80
81} // namespace threadschedule
Strongly-typed realtime priority in the range $[1, 99]$.
friend constexpr auto operator!=(realtime_priority lhs, realtime_priority rhs) noexcept -> bool
constexpr auto value() const noexcept -> int
Return the wrapped realtime priority value.
constexpr realtime_priority(int value)
Construct and validate a realtime priority.
static constexpr int maximum
Highest accepted realtime priority value.
friend constexpr auto operator==(realtime_priority lhs, realtime_priority rhs) noexcept -> bool
static auto create(int value) noexcept -> result< realtime_priority >
Construct a realtime priority without exceptions.
static constexpr int minimum
Lowest accepted realtime priority value.
Error-returning result type used by the portable ThreadSchedule API.