Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
looper.hpp
Go to the documentation of this file.
1/*
2 LOOPER.hpp - steam dispatcher loop and timing control logic
3
4 Copyright (C)
5 2016, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12*/
13
14
40#ifndef STEAM_CONTROL_LOOPER_H
41#define STEAM_CONTROL_LOOPER_H
42
44#include "vault/real-clock.hpp"
45
46#include <functional>
47#include <chrono>
48
49
50
51namespace steam {
52namespace control {
53
54 using lib::time::Time;
58 using std::chrono::milliseconds;
59 using vault::RealClock;
60
82
83
84
105 class Looper
106 {
107 using Predicate = std::function<bool(void)>;
108
109 bool shutdown_ = false;
110 bool disabled_ = false;
111 bool inChange_ = false;
112 bool hasWork_ = false;
113 bool isDirty_ = false;
114
116
118
119
120 public:
121 template<class FUN>
125
126 // standard copy acceptable
127
128
129 /* == working state logic == */
130
131 bool isDying() const { return shutdown_; }
132 bool isDisabled() const { return disabled_ or isDying(); }
133 bool useTimeout() const { return isDirty_ and not isDisabled(); }
134 bool isWorking() const { return hasWork_ and not isDisabled(); }
135 bool idleBuild() const { return isDirty_ and not hasWork_; }
136 bool runBuild() const { return (idleBuild() or forceBuild()) and not isDisabled(); }
137 bool isIdle() const { return not (isWorking() or runBuild() or isDisabled()); }
138
139
140 /* == operation control == */
141
142 void
144 {
145 shutdown_ = true;
146 }
147
148 void
150 {
151 disabled_ = not yes;
152 }
153
164 void
166 {
167 inChange_ = false;
168 if (runBuild())
169 isDirty_ = false; // assume the builder has been triggered in the loop body
170 }
171
172 bool
174 {
175 return inChange_;
176 }
177
179 bool
181 {
185
187 { // schedule Builder run after timeout
189 isDirty_ = true;
190 }
191
192 return proceedImmediately;
193 }
194
196 bool
197 shallLoop() const
198 {
199 return not isDying();
200 }
201
202 milliseconds
204 {
205 if (not useTimeout())
206 return milliseconds::zero();
207 else
208 return milliseconds{
211 }
212
213
214 private:
215 static uint wakeTimeout_ms();
216 static uint slowdownFactor();
217
218 void startBuilderTimeout();
219 bool forceBuild() const;
220 };
221
222
223
235 inline uint
237 {
238 return STEAM_DISPATCHER_BUILDER_DELAY_ms;
239 }
240
241 inline uint
243 {
244 return STEAM_DISPATCHER_BUSY_SLOWDOWN_FACTOR;
245 }
246
247 inline void
252
256 inline bool
264
265
266
267}} // namespace steam::control
268#endif /*STEAM_CONTROL_LOOPER_H*/
Duration is the internal Lumiera time metric.
Offset measures a distance in time.
a mutable time value, behaving like a plain number, allowing copy and re-accessing
Lumiera's internal time value datatype.
static const Time NEVER
border condition marker value. NEVER >= any time value
Encapsulated control logic for the session thread loop.
Definition looper.hpp:106
void markStateProcessed()
invoking this function signals that all consequences of past state changes have been processed and ar...
Definition looper.hpp:165
std::function< bool(void)> Predicate
Definition looper.hpp:107
bool isDying() const
Definition looper.hpp:131
bool useTimeout() const
Definition looper.hpp:133
bool isDisabled() const
Definition looper.hpp:132
bool isWorking() const
Definition looper.hpp:134
Predicate hasCommandsPending_
Definition looper.hpp:117
bool isIdle() const
Definition looper.hpp:137
Looper(FUN determine_commands_are_waiting)
Definition looper.hpp:122
static uint wakeTimeout_ms()
Definition looper.hpp:236
bool forceBuild() const
Definition looper.hpp:257
bool runBuild() const
Definition looper.hpp:136
static uint slowdownFactor()
Definition looper.hpp:242
bool idleBuild() const
Definition looper.hpp:135
bool requireAction()
state fusion to control (timed) wait
Definition looper.hpp:180
milliseconds getTimeout() const
Definition looper.hpp:203
void enableProcessing(bool yes=true)
Definition looper.hpp:149
bool hasPendingChanges() const
< "check point"
Definition looper.hpp:173
bool shallLoop() const
state fusion to control looping
Definition looper.hpp:197
Convenience frontend to access the current raw system time.
static Time now()
unsigned int uint
Definition integral.hpp:29
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
const uint STEAM_DISPATCHER_BUILDER_DELAY_ms
Latency to trigger the Builder after processing command(s).
Definition looper.hpp:70
const uint STEAM_DISPATCHER_BUSY_SLOWDOWN_FACTOR
Factor to slow down the latency when the command queue is not empty.
Definition looper.hpp:80
Steam-Layer implementation namespace root.
Front-end for simplified access to the current wall clock time.
a family of time value like entities and their relationships.