diff --git a/src/vault/gear/scheduler-commutator.hpp b/src/vault/gear/scheduler-commutator.hpp index 51eb22810..bd574fcde 100644 --- a/src/vault/gear/scheduler-commutator.hpp +++ b/src/vault/gear/scheduler-commutator.hpp @@ -40,6 +40,8 @@ #include "vault/common.hpp" #include "lib/nocopy.hpp" #include "vault/gear/scheduler-invocation.hpp" +#include "lib/time/timevalue.hpp" + //#include "lib/symbol.hpp" //#include "lib/util.hpp" @@ -49,6 +51,7 @@ namespace vault{ namespace gear { + using lib::time::Time; // using util::isnil; // using std::string; @@ -72,7 +75,7 @@ namespace gear { doWork (SchedulerInvocation& layer1) { layer1.feedPriorisation(); - while (layer1.isDue (currentLevel())) + while (layer1.isDue (currentSchedulerTime())) { Activity* activity = layer1.pullHead(); if (isInternalWork (activity)) @@ -85,10 +88,10 @@ namespace gear { } } - size_t - currentLevel() const + Time + currentSchedulerTime() const { - UNIMPLEMENTED ("define waterlevel based on current time"); + UNIMPLEMENTED ("how to manage the current scheduler time"); } bool diff --git a/src/vault/gear/scheduler-invocation.hpp b/src/vault/gear/scheduler-invocation.hpp index ddf93bb31..620ed58ba 100644 --- a/src/vault/gear/scheduler-invocation.hpp +++ b/src/vault/gear/scheduler-invocation.hpp @@ -42,6 +42,7 @@ #include "lib/nocopy.hpp" //#include "lib/symbol.hpp" #include "vault/gear/activity.hpp" +#include "lib/time/timevalue.hpp" //#include "lib/util.hpp" //#include @@ -52,12 +53,13 @@ namespace vault{ namespace gear { - namespace error = lumiera::error; + using lib::time::Time; // using util::isnil; // using std::string; - using std::move; + namespace error = lumiera::error; + namespace {// Internal defaults const size_t INITIAL_CAPACITY = 128; } @@ -74,7 +76,7 @@ namespace gear { { struct ActOrder { - size_t waterlevel{0}; + int64_t waterlevel{0}; Activity* activity{nullptr}; /** @internal ordering function for time based scheduling @@ -95,7 +97,6 @@ namespace gear { PriorityQueue priority_; public: -// explicit SchedulerInvocation() : instruct_{INITIAL_CAPACITY} , priority_{} @@ -106,10 +107,9 @@ namespace gear { * Accept an Activity for time-bound execution */ void - instruct (Activity& activity) + instruct (Activity& activity, Time when) { - size_t waterLevel = 123; /////////////////////////////////////////////////////OOO derive water level from time window - bool success = instruct_.push (ActOrder{waterLevel, &activity}); + bool success = instruct_.push (ActOrder{waterLevel(when), &activity}); if (not success) throw error::Fatal{"Scheduler entrance: memory allocation failed"}; } @@ -128,6 +128,17 @@ namespace gear { } + /** + * Feed the given Activity directly into time prioritisation, + * effectively bypassing the thread dispatching entrance queue. + */ + void + feedPriorisation (Activity& activity, Time when) + { + priority_.push (ActOrder{waterLevel(when), &activity}); + } + + /** * @return `nullptr` if the queue is empty, else the Activity corresponding * to the currently most urgent element (without dequeuing it). @@ -155,10 +166,17 @@ namespace gear { /** Determine if there is work to do right now */ bool - isDue (size_t level) const + isDue (Time now) const { return not priority_.empty() - and priority_.top().waterlevel <= level; + and priority_.top().waterlevel <= waterLevel(now); + } + + private: + static int64_t + waterLevel (Time time) + { + return _raw(time); } }; diff --git a/tests/vault/gear/scheduler-invocation-test.cpp b/tests/vault/gear/scheduler-invocation-test.cpp index b48ee6d26..6aa35ea07 100644 --- a/tests/vault/gear/scheduler-invocation-test.cpp +++ b/tests/vault/gear/scheduler-invocation-test.cpp @@ -74,10 +74,11 @@ namespace test { { SchedulerInvocation sched; Activity activity; + Time when{1,2,3}; CHECK (not sched.peekHead()); - sched.instruct (activity); + sched.instruct (activity, when); sched.feedPriorisation(); CHECK (sched.peekHead()); diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index d95bb304d..1c3c3dc9d 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -80345,8 +80345,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
wenn es zur Ausführung kommt: when ≡ now

- - + @@ -81731,6 +81730,22 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + + + + + + + @@ -81805,8 +81820,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
...es handelt sich offensichtlich bei Layer-1 um eine low-Level-Einrichtung und um ein internes API, das nicht gegen Mißbrauch gewappnet sein muß

- - +
@@ -85875,7 +85889,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- +