From 196696a8d01c83a81f5a282e6d65bf5302515f0a Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 21 Dec 2016 03:56:56 +0100 Subject: [PATCH] Looper: draft possible implementation seemingly a quite simple "trap door" mechanism is sufficient --- src/proc/control/looper.hpp | 21 ++++++++++++++----- src/proc/control/proc-dispatcher.cpp | 7 +------ .../proc/control/dispatcher-looper-test.cpp | 2 ++ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/proc/control/looper.hpp b/src/proc/control/looper.hpp index 3f03669c6..7a73ee9e8 100644 --- a/src/proc/control/looper.hpp +++ b/src/proc/control/looper.hpp @@ -82,6 +82,7 @@ namespace control { bool shutdown_ = false; bool disabled_ = false; + uint dirty_ = false; Predicate hasCommandsPending_; public: @@ -98,7 +99,7 @@ namespace control { bool isDying() const { return shutdown_; } bool isDisabled() const { return disabled_ or isDying(); } bool isWorking() const { return hasCommandsPending_() and not isDisabled(); } - bool runBuild() const { return false; } + bool runBuild() const { return (dirty_ and not hasCommandsPending_()) or forceBuild(); } bool isIdle() const { return not (isWorking() or runBuild() or isDisabled()); } @@ -118,12 +119,14 @@ namespace control { /** invoking this function signals * that all consequences of past state changes - * have been processed and duly resolved. + * have been processed and are duly resolved. */ void markStateProcessed() { - UNIMPLEMENTED("state transition logic"); + if (runBuild()) + --dirty_; + ENSURE (dirty_ <= 2); } bool @@ -136,8 +139,11 @@ namespace control { bool requireAction() { + if (isWorking()) + dirty_ = 2; + return isWorking() - or runBuild() + or forceBuild() or isDying(); } @@ -162,6 +168,11 @@ namespace control { private: static uint establishWakeTimeout(); + + bool forceBuild() const + { + return false; + } }; ////////////////TODO 12/16 currently just fleshing out the API.... @@ -177,7 +188,7 @@ namespace control { * 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 */ - uint + uint inline Looper::establishWakeTimeout() { return PROC_DISPATCHER_BUILDER_DELAY_ms; diff --git a/src/proc/control/proc-dispatcher.cpp b/src/proc/control/proc-dispatcher.cpp index fe003036f..39dd4ae65 100644 --- a/src/proc/control/proc-dispatcher.cpp +++ b/src/proc/control/proc-dispatcher.cpp @@ -47,12 +47,8 @@ #include "proc/control/session-command-service.hpp" #include "proc/mobject/session.hpp" #include "backend/thread-wrapper.hpp" -//#include "proc/mobject/mobject-ref.hpp" -//#include "proc/mobject/mobject.hpp" -//#include "proc/mobject/placement.hpp" #include -//using boost::str; using backend::ThreadJoinable; using lib::Sync; @@ -71,7 +67,6 @@ namespace control { { bool canDispatch_{false}; bool blocked_ {false}; - bool mustHalt_ {false}; /////////////////TODO this flag shall be relocated into the Looper! unique_ptr commandService_; @@ -146,7 +141,7 @@ namespace control { { Lock sync(this); commandService_.reset(); // closes Session interface - mustHalt_ = true; + looper_.triggerShutdown(); UNIMPLEMENTED("*must* notify loop thread"); /////////////////TODO really? YES!!! //////////////////////////////////////////TODO notify!!!! } diff --git a/tests/core/proc/control/dispatcher-looper-test.cpp b/tests/core/proc/control/dispatcher-looper-test.cpp index 3f23b7146..31ed3392c 100644 --- a/tests/core/proc/control/dispatcher-looper-test.cpp +++ b/tests/core/proc/control/dispatcher-looper-test.cpp @@ -168,6 +168,8 @@ namespace test { CHECK (looper.shallLoop()); setup.has_commands_in_queue = false; + looper.markStateProcessed(); + looper.markStateProcessed(); CHECK (not looper.requireAction()); CHECK (not looper.isWorking());