Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
Looper Class Reference

#include "steam/control/looper.hpp"

Description

Encapsulated control logic for the session thread loop.

This helper component was factored out from the loop body for sake of clarity and to allow unit testing of the logic in isolation. It is based on logical relations together with the following assumptions

  • Looper::shallLoop controls the loop's while condition
  • at the begin of the loop the thread possibly enters a blocking wait state; the wake-up condition is provided by Looper::requireAction.
  • then, in the actual loop body, depending on the predicates calculated here, either the builder run is triggered, or a single command is dispatched from the queue to work on the session.
  • after returning from these active operations, at the end of the loop, the state evaluation is updated by Looper::markStateProcessed
Warning
the Looper is not threadsafe, since it is intended to be run exclusively from the Session working thread.
See also
DispatcherLoop::run()

Definition at line 105 of file looper.hpp.

Public Member Functions

template<class FUN >
 Looper (FUN determine_commands_are_waiting)
 
bool isDying () const
 
bool isDisabled () const
 
bool useTimeout () const
 
bool isWorking () const
 
bool idleBuild () const
 
bool runBuild () const
 
bool isIdle () const
 
void triggerShutdown ()
 
void enableProcessing (bool yes=true)
 
void markStateProcessed ()
 invoking this function signals that all consequences of past state changes have been processed and are duly resolved.
 
bool hasPendingChanges () const
 < "check point"
 
bool requireAction ()
 state fusion to control (timed) wait
 
bool shallLoop () const
 state fusion to control looping
 
milliseconds getTimeout () const
 

Private Types

using Predicate = std::function< bool(void)>
 

Private Member Functions

void startBuilderTimeout ()
 
bool forceBuild () const
 

Static Private Member Functions

static uint wakeTimeout_ms ()
 
static uint slowdownFactor ()
 

Private Attributes

bool shutdown_ = false
 
bool disabled_ = false
 
bool inChange_ = false
 
bool hasWork_ = false
 
bool isDirty_ = false
 
TimeVar gotDirty_ = Time::NEVER
 
Predicate hasCommandsPending_
 

Constructor & Destructor Documentation

◆ Looper()

template<class FUN >
Looper ( FUN  determine_commands_are_waiting)
inline

Definition at line 122 of file looper.hpp.

Member Typedef Documentation

◆ Predicate

using Predicate = std::function<bool(void)>
private

Definition at line 107 of file looper.hpp.

Member Function Documentation

◆ isDying()

bool isDying ( ) const
inline

Definition at line 131 of file looper.hpp.

References Looper::shutdown_.

Referenced by Looper::isDisabled(), Looper::requireAction(), DispatcherLoop::runSessionThread(), and Looper::shallLoop().

+ Here is the caller graph for this function:

◆ isDisabled()

bool isDisabled ( ) const
inline

Definition at line 132 of file looper.hpp.

References Looper::disabled_, and Looper::isDying().

Referenced by Looper::isIdle(), Looper::isWorking(), Looper::runBuild(), DispatcherLoop::updateState(), and Looper::useTimeout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ useTimeout()

bool useTimeout ( ) const
inline

Definition at line 133 of file looper.hpp.

References Looper::isDirty_, and Looper::isDisabled().

Referenced by Looper::getTimeout(), and Looper::requireAction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isWorking()

bool isWorking ( ) const
inline

Definition at line 134 of file looper.hpp.

References Looper::hasWork_, and Looper::isDisabled().

Referenced by Looper::getTimeout(), Looper::isIdle(), Looper::requireAction(), and DispatcherLoop::runSessionThread().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ idleBuild()

bool idleBuild ( ) const
inline

Definition at line 135 of file looper.hpp.

References Looper::hasWork_, and Looper::isDirty_.

Referenced by Looper::runBuild().

+ Here is the caller graph for this function:

◆ runBuild()

bool runBuild ( ) const
inline

Definition at line 136 of file looper.hpp.

References Looper::forceBuild(), Looper::idleBuild(), and Looper::isDisabled().

Referenced by Looper::isIdle(), Looper::markStateProcessed(), and DispatcherLoop::runSessionThread().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isIdle()

bool isIdle ( ) const
inline

Definition at line 137 of file looper.hpp.

References Looper::isDisabled(), Looper::isWorking(), and Looper::runBuild().

+ Here is the call graph for this function:

◆ triggerShutdown()

void triggerShutdown ( )
inline

Definition at line 143 of file looper.hpp.

References Looper::shutdown_.

Referenced by DispatcherLoop::requestStop().

+ Here is the caller graph for this function:

◆ enableProcessing()

void enableProcessing ( bool  yes = true)
inline

Definition at line 149 of file looper.hpp.

References Looper::disabled_.

Referenced by DispatcherLoop::activateCommandProecssing(), and DispatcherLoop::deactivateCommandProecssing().

+ Here is the caller graph for this function:

◆ markStateProcessed()

void markStateProcessed ( )
inline

invoking this function signals that all consequences of past state changes have been processed and are duly resolved.

Remarks
the implementation actually does not need to watch out for command processing state directly, only the managing of builder runs requires active state transitions here. When the conditions for triggering the Builder are met, control flow typically just has emptied the command queue. Thus we need to let one invocation pass by; the next loop iteration will begin after waking up from a short sleep and trigger the build, so the following (second) invocation can clear the builder dirty state.

Definition at line 165 of file looper.hpp.

References Looper::inChange_, Looper::isDirty_, and Looper::runBuild().

Referenced by DispatcherLoop::updateState().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasPendingChanges()

bool hasPendingChanges ( ) const
inline

< "check point"

Definition at line 173 of file looper.hpp.

References Looper::inChange_.

Referenced by DispatcherLoop::isStateSynched().

+ Here is the caller graph for this function:

◆ requireAction()

bool requireAction ( )
inline

state fusion to control (timed) wait

Definition at line 180 of file looper.hpp.

References Looper::forceBuild(), Looper::hasCommandsPending_, Looper::hasWork_, Looper::inChange_, Looper::isDirty_, Looper::isDying(), Looper::isWorking(), Looper::startBuilderTimeout(), and Looper::useTimeout().

+ Here is the call graph for this function:

◆ shallLoop()

bool shallLoop ( ) const
inline

state fusion to control looping

Definition at line 197 of file looper.hpp.

References Looper::isDying().

Referenced by DispatcherLoop::runSessionThread().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTimeout()

milliseconds getTimeout ( ) const
inline

Definition at line 203 of file looper.hpp.

References Looper::isDirty_, Looper::isWorking(), Looper::slowdownFactor(), Looper::useTimeout(), and Looper::wakeTimeout_ms().

Referenced by DispatcherLoop::awaitAction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ wakeTimeout_ms()

uint wakeTimeout_ms ( )
inlinestaticprivate

establish the typical timeout for idle sleep. When the SteamDispatcher has no work to do, it needs to wake up regularly for a checkpoint, to determine if the Builder needs to be triggered or the shutdown-flag be checked. So the period established here defines some kind of minimal reaction especially for the builder, so to ensure that further commands trickling in get a chance to be enqueued before the builder run effectively blocks command processing. Add to this the typical average running time of the builder, to get the reaction period visible to the user as update response delay within the UI.

Todo:
find a way how to retrieve this value from application config! ////////////////////TICKET #1052 : access application configuration

Definition at line 236 of file looper.hpp.

Referenced by Looper::forceBuild(), and Looper::getTimeout().

+ Here is the caller graph for this function:

◆ slowdownFactor()

uint slowdownFactor ( )
inlinestaticprivate

Definition at line 242 of file looper.hpp.

Referenced by Looper::forceBuild(), and Looper::getTimeout().

+ Here is the caller graph for this function:

◆ startBuilderTimeout()

void startBuilderTimeout ( )
inlineprivate

Definition at line 248 of file looper.hpp.

References Looper::gotDirty_, and RealClock::now().

Referenced by Looper::requireAction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ forceBuild()

bool forceBuild ( ) const
inlineprivate

logic to enforce a builder run, once some extended time period has been passed.

Definition at line 257 of file looper.hpp.

References Looper::gotDirty_, Looper::isDirty_, RealClock::now(), Looper::slowdownFactor(), and Looper::wakeTimeout_ms().

Referenced by Looper::requireAction(), and Looper::runBuild().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ shutdown_

bool shutdown_ = false
private

Definition at line 109 of file looper.hpp.

Referenced by Looper::isDying(), and Looper::triggerShutdown().

◆ disabled_

bool disabled_ = false
private

Definition at line 110 of file looper.hpp.

Referenced by Looper::enableProcessing(), and Looper::isDisabled().

◆ inChange_

bool inChange_ = false
private

◆ hasWork_

bool hasWork_ = false
private

Definition at line 112 of file looper.hpp.

Referenced by Looper::idleBuild(), Looper::isWorking(), and Looper::requireAction().

◆ isDirty_

◆ gotDirty_

TimeVar gotDirty_ = Time::NEVER
private

Definition at line 115 of file looper.hpp.

Referenced by Looper::forceBuild(), and Looper::startBuilderTimeout().

◆ hasCommandsPending_

Predicate hasCommandsPending_
private

Definition at line 117 of file looper.hpp.

Referenced by Looper::requireAction().

+ Collaboration diagram for Looper:

The documentation for this class was generated from the following file: