distortos  v0.5.0
object-oriented C++ RTOS for microcontrollers
RoundRobinQuantum.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_ROUNDROBINQUANTUM_HPP_
13 #define INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_ROUNDROBINQUANTUM_HPP_
14 
15 #include "distortos/TickClock.hpp"
16 
17 namespace distortos
18 {
19 
20 namespace internal
21 {
22 
25 {
26 public:
27 
29  using Representation = uint8_t;
30 
32  using Duration = std::chrono::duration<Representation, TickClock::period>;
33 
38  constexpr static Duration getInitial()
39  {
41  }
42 
49  constexpr RoundRobinQuantum() :
51  {
52 
53  }
54 
64  void decrement()
65  {
66  if (isZero() == false)
67  --quantum_;
68  }
69 
76  Duration get() const
77  {
78  return quantum_;
79  }
80 
87  bool isZero() const
88  {
89  return quantum_ == Duration{0};
90  }
91 
98  void reset()
99  {
100  quantum_ = getInitial();
101  }
102 
103 private:
104 
105  static_assert(CONFIG_TICK_FREQUENCY > 0, "CONFIG_TICK_FREQUENCY must be positive and non-zero!");
106  static_assert(CONFIG_ROUND_ROBIN_FREQUENCY > 0, "CONFIG_ROUND_ROBIN_FREQUENCY must be positive and non-zero!");
107 
109  constexpr static auto quantumRawInitializer_ = (CONFIG_TICK_FREQUENCY + CONFIG_ROUND_ROBIN_FREQUENCY / 2) /
110  CONFIG_ROUND_ROBIN_FREQUENCY;
111 
112  static_assert(quantumRawInitializer_ > 0 || quantumRawInitializer_ <= UINT8_MAX,
113  "CONFIG_TICK_FREQUENCY and CONFIG_ROUND_ROBIN_FREQUENCY values produce invalid round-robin quantum!");
114 
117 };
118 
119 } // namespace internal
120 
121 } // namespace distortos
122 
123 #endif // INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_ROUNDROBINQUANTUM_HPP_
RoundRobinQuantum class is a quantum of time for round-robin scheduling.
Definition: RoundRobinQuantum.hpp:24
bool isZero() const
Convenience function to test whether the quantum is already at 0.
Definition: RoundRobinQuantum.hpp:87
constexpr RoundRobinQuantum()
RoundRobinQuantum&#39;s constructor.
Definition: RoundRobinQuantum.hpp:49
TickClock class header.
uint8_t Representation
type of quantum counter
Definition: RoundRobinQuantum.hpp:29
static constexpr Duration getInitial()
Definition: RoundRobinQuantum.hpp:38
Top-level namespace of distortos project.
static constexpr auto quantumRawInitializer_
raw initializer value for round-robin quantum, calculated with rounding to nearest ...
Definition: RoundRobinQuantum.hpp:109
void decrement()
Decrements round-robin&#39;s quantum.
Definition: RoundRobinQuantum.hpp:64
void reset()
Resets value of round-robin&#39;s quantum.
Definition: RoundRobinQuantum.hpp:98
Duration quantum_
round-robin quantum
Definition: RoundRobinQuantum.hpp:113
std::chrono::duration< Representation, TickClock::period > Duration
duration type used for quantum
Definition: RoundRobinQuantum.hpp:32