Scheduler: implement and verify postDispatch

This commit is contained in:
Fischlurch 2023-10-18 16:39:08 +02:00
parent 666546856f
commit 93fcebb331
3 changed files with 33 additions and 16 deletions

View file

@ -40,6 +40,7 @@
#include "vault/common.hpp"
#include "vault/gear/activity.hpp"
#include "vault/gear/scheduler-invocation.hpp"
#include "vault/gear/activity-lang.hpp"
#include "lib/time/timevalue.hpp"
#include "lib/nocopy.hpp"
@ -183,7 +184,17 @@ namespace gear {
,EXE& executionCtx
,SchedulerInvocation& layer1)
{
UNIMPLEMENTED ("core function: maybe perform activity");
if (!chain) return activity::WAIT;
Time now = executionCtx.getSchedTime();
if (decideDispatchNow (when, now))
return ActivityLang::dispatchChain (*chain, executionCtx);
else
if (holdsGroomingToken(std::this_thread::get_id()))
layer1.feedPrioritisation (*chain, when);
else
layer1.instruct (*chain, when);
return activity::PASS;
}
};

View file

@ -51,6 +51,7 @@ namespace test {
// using lib::time::FrameRate;
// using lib::time::Offset;
using lib::time::Time;
using lib::time::FSecs;
using std::atomic_bool;
using lib::ThreadHookable;
using lib::thread::ThreadWrapper;
@ -341,10 +342,9 @@ namespace test {
SchedulerInvocation queue;
SchedulerCommutator sched;
Time t1{10,0};
Time t2{20,0};
Time t3{30,0};
Time now{t2};
Time now = detector.executionCtx.getSchedTime();
Time past {Time::ZERO};
Time future{now+now};
// no one holds the GroomingToken
___ensureGroomingTokenReleased(sched);
@ -356,12 +356,14 @@ namespace test {
CHECK (not sched.holdsGroomingToken (myself));
// Activity immediately dispatched when on time and GroomingToken can be acquired
CHECK (activity::PASS == sched.postDispatch (&activity, t1, detector.executionCtx, queue));
CHECK (activity::PASS == sched.postDispatch (&activity, past, detector.executionCtx, queue));
CHECK (detector.verifyInvocation("testActivity").timeArg(now)); // was invoked immediately
CHECK ( sched.holdsGroomingToken (myself));
CHECK ( queue.empty());
detector.incrementSeq(); // mark this point in the log
// future Activity is enqueued by short-circuit directly into the PriorityQueue if possible
CHECK (activity::PASS == sched.postDispatch (&activity, t3, detector.executionCtx, queue));
CHECK (activity::PASS == sched.postDispatch (&activity, future, detector.executionCtx, queue));
CHECK ( sched.holdsGroomingToken (myself));
CHECK (not queue.empty());
CHECK (isSameObject (activity, *queue.peekHead())); // appears at Head, implying it's in Priority-Queue
@ -372,17 +374,18 @@ namespace test {
CHECK (queue.empty());
// ...but GroomingToken is not acquired explicitly; Activity is just placed into the Instruct-Queue
CHECK (activity::PASS == sched.postDispatch (&activity, t3, detector.executionCtx, queue));
CHECK (activity::PASS == sched.postDispatch (&activity, future, detector.executionCtx, queue));
CHECK (not sched.holdsGroomingToken (myself));
CHECK (not queue.peekHead()); // not appearing at Head this time,
CHECK (not queue.empty()); // rather waiting in the Instruct-Queue
blockGroomingToken(sched);
CHECK (activity::PASS == sched.postDispatch (&activity, t2, detector.executionCtx, queue));
CHECK (activity::PASS == sched.postDispatch (&activity, now, detector.executionCtx, queue));
CHECK (not sched.holdsGroomingToken (myself));
CHECK (not queue.peekHead()); // was enqueued, not executed
unblockGroomingToken();
cout << detector.showLog()<<endl; // HINT: use this for investigation...
}

View file

@ -85061,8 +85061,8 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1697553556862" ID="ID_239855477" MODIFIED="1697553563674" TEXT="PostDispatch">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1697553556862" ID="ID_239855477" MODIFIED="1697639869887" TEXT="PostDispatch">
<icon BUILTIN="pencil"/>
<node CREATED="1697553564965" ID="ID_280879756" MODIFIED="1697553576815" TEXT="der &#xbb;POST-Eingang&#xab;">
<icon BUILTIN="ksmiletris"/>
</node>
@ -85121,7 +85121,7 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
</html></richcontent>
</node>
</node>
<node CREATED="1697628889224" ID="ID_1337049621" MODIFIED="1697630748734" TEXT="&#x27f9; erwartetes Verhalten">
<node BACKGROUND_COLOR="#c8c0b6" CREATED="1697628889224" ID="ID_1337049621" MODIFIED="1697639849001" TEXT="&#x27f9; erwartetes Verhalten">
<arrowlink COLOR="#9ca0a6" DESTINATION="ID_1032090324" ENDARROW="Default" ENDINCLINATION="-719;-92;" ID="Arrow_ID_1412557043" STARTARROW="None" STARTINCLINATION="-335;509;"/>
<node CREATED="1697628930257" ID="ID_412159967" MODIFIED="1697628991437" TEXT="Entscheidung &#xfc;ber Dispatch | Enqueue"/>
<node CREATED="1697629037716" ID="ID_661469490" MODIFIED="1697629194450" TEXT="Dispatch &#x2014;&#x27f6; activate Chain"/>
@ -86349,10 +86349,10 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<node CREATED="1697630618833" ID="ID_1032090324" MODIFIED="1697630748734" TEXT="Szenarien">
<linktarget COLOR="#9ca0a6" DESTINATION="ID_1032090324" ENDARROW="Default" ENDINCLINATION="-719;-92;" ID="Arrow_ID_1412557043" SOURCE="ID_1337049621" STARTARROW="None" STARTINCLINATION="-335;509;"/>
<icon BUILTIN="list"/>
<node CREATED="1697630760771" ID="ID_1390673717" MODIFIED="1697630771920" TEXT="keine Activity &#x27f9; kein Effekt"/>
<node CREATED="1697630796057" ID="ID_118687407" MODIFIED="1697630817180" TEXT="Activity in time &#x27f9; Aktivierung"/>
<node CREATED="1697630849573" ID="ID_508584323" MODIFIED="1697630936514" TEXT="Activity planned &#x27f9; Priority-Queue"/>
<node CREATED="1697630940709" ID="ID_338527854" MODIFIED="1697630968190" TEXT="kein Grooming &#x27f9; Instruct-Queue"/>
<node COLOR="#435e98" CREATED="1697630760771" ID="ID_1390673717" MODIFIED="1697639813983" TEXT="keine Activity &#x27f9; kein Effekt"/>
<node COLOR="#435e98" CREATED="1697630796057" ID="ID_118687407" MODIFIED="1697639813982" TEXT="Activity in time &#x27f9; Aktivierung"/>
<node COLOR="#435e98" CREATED="1697630849573" ID="ID_508584323" MODIFIED="1697639813982" TEXT="Activity planned &#x27f9; Priority-Queue"/>
<node COLOR="#435e98" CREATED="1697630940709" ID="ID_338527854" MODIFIED="1697639813981" TEXT="kein Grooming &#x27f9; Instruct-Queue"/>
</node>
<node CREATED="1697631061046" ID="ID_1383947254" MODIFIED="1697636526674" TEXT="Instrumentierung">
<icon BUILTIN="info"/>
@ -86365,6 +86365,9 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1697636534920" ID="ID_148488011" MODIFIED="1697636539419" TEXT="Match auf Event-Log">
<icon BUILTIN="flag-yellow"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1697639822205" ID="ID_182534070" MODIFIED="1697639828532" TEXT="Queue-Zustand pr&#xfc;fen">
<icon BUILTIN="flag-yellow"/>
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1697560591659" ID="ID_1581648425" MODIFIED="1697560620823" TEXT="integratedWorkCycle">