Block-Flow: implement opening a new Epoch
..this is the most simple case, where no Epochs are opened yet ..add diagnostics to inspect alloc count and deadlines ..add accessors for the first/last underlying Extent
This commit is contained in:
parent
180c6b8d84
commit
946f7c17f7
5 changed files with 120 additions and 29 deletions
|
|
@ -57,7 +57,7 @@
|
|||
//#include "lib/symbol.hpp"
|
||||
#include "lib/time/timevalue.hpp"
|
||||
#include "lib/nocopy.hpp"
|
||||
//#include "lib/util.hpp"
|
||||
#include "lib/util.hpp"
|
||||
|
||||
//#include <string>
|
||||
#include <utility>
|
||||
|
|
@ -66,16 +66,22 @@
|
|||
namespace vault{
|
||||
namespace gear {
|
||||
|
||||
// using util::isnil;
|
||||
using util::isnil;
|
||||
// using std::string;
|
||||
using lib::time::Time;
|
||||
using lib::time::TimeVar;
|
||||
using lib::time::Duration;
|
||||
using lib::time::FrameRate;
|
||||
|
||||
namespace {// hard-wired parametrisation
|
||||
const size_t EPOCH_SIZ = 100;
|
||||
const size_t ACTIVITIES_PER_FRAME = 10;
|
||||
const size_t FRAMES_PER_EPOCH = EPOCH_SIZ/ACTIVITIES_PER_FRAME;
|
||||
const size_t INITIAL_FRAMES = 50;
|
||||
const size_t INITIAL_ALLOC = 1 + (INITIAL_FRAMES * ACTIVITIES_PER_FRAME) / EPOCH_SIZ;
|
||||
|
||||
const Duration INITIAL_EPOCH_STEP{FRAMES_PER_EPOCH * FrameRate{50}.duration()};
|
||||
|
||||
/** raw allocator to provide a sequence of Extents to place Activity records */
|
||||
using Allocator = mem::ExtentFamily<Activity, EPOCH_SIZ>;
|
||||
}
|
||||
|
|
@ -124,6 +130,12 @@ namespace gear {
|
|||
}
|
||||
// default copyable
|
||||
|
||||
Instant&
|
||||
deadline()
|
||||
{
|
||||
return data_.condition.dead;
|
||||
}
|
||||
|
||||
bool
|
||||
hasFreeSlot()
|
||||
{ // see C++ § 5.9 : comparison of pointers within same array
|
||||
|
|
@ -167,12 +179,21 @@ namespace gear {
|
|||
: util::NonCopyable
|
||||
{
|
||||
Allocator alloc_;
|
||||
TimeVar epochStep_;
|
||||
|
||||
public:
|
||||
BlockFlow()
|
||||
: alloc_{INITIAL_ALLOC}
|
||||
, epochStep_{INITIAL_EPOCH_STEP}
|
||||
{ }
|
||||
|
||||
Duration
|
||||
currEpochStep() const
|
||||
{
|
||||
return Duration{epochStep_};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Local handle to allow allocating a collection of Activities,
|
||||
* all sharing a common deadline. Internally, these records are
|
||||
|
|
@ -185,6 +206,10 @@ namespace gear {
|
|||
Allocator::iterator extent;
|
||||
|
||||
public:
|
||||
AllocatorHandle(Allocator::iterator slot)
|
||||
: extent{slot}
|
||||
{ }
|
||||
|
||||
template<typename...ARGS>
|
||||
Activity&
|
||||
create (ARGS&& ...args)
|
||||
|
|
@ -196,8 +221,7 @@ namespace gear {
|
|||
Epoch&
|
||||
currEpoch()
|
||||
{
|
||||
REQUIRE (bool(extent));
|
||||
return static_cast<Epoch&> (*extent);
|
||||
return asEpoch(extent);
|
||||
}
|
||||
|
||||
void*
|
||||
|
|
@ -217,7 +241,17 @@ namespace gear {
|
|||
AllocatorHandle
|
||||
until (Time deadline)
|
||||
{
|
||||
UNIMPLEMENTED ("search through existing Epochs to locate the latest one to support given deadline");
|
||||
if (isnil (alloc_))
|
||||
{//just create new Epoch one epochStep ahead
|
||||
alloc_.openNew();
|
||||
Epoch& newEpoch = Epoch::implantInto (alloc_.first());
|
||||
newEpoch.gate().deadline() = deadline + Time{epochStep_};
|
||||
return AllocatorHandle{alloc_.begin()};
|
||||
}
|
||||
else
|
||||
{
|
||||
UNIMPLEMENTED ("search through existing Epochs to locate the latest one to support given deadline");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -227,7 +261,20 @@ namespace gear {
|
|||
}
|
||||
|
||||
private:
|
||||
///////////////////
|
||||
/** @internal use a raw allocator Extent as Epoch (unchecked cast) */
|
||||
static Epoch&
|
||||
asEpoch (Allocator::iterator slot)
|
||||
{
|
||||
REQUIRE (bool(slot));
|
||||
return asEpoch (*slot);
|
||||
}
|
||||
|
||||
static Epoch&
|
||||
asEpoch (Allocator::Extent& extent)
|
||||
{
|
||||
return static_cast<Epoch&> (extent);
|
||||
}
|
||||
|
||||
|
||||
/// „backdoor“ to watch internals from tests
|
||||
friend class FlowDiagnostic;
|
||||
|
|
@ -251,8 +298,8 @@ namespace gear {
|
|||
: flow_{theFlow}
|
||||
{ }
|
||||
|
||||
// size_t first() { return exFam_.start_; }
|
||||
// size_t last() { return exFam_.after_; }
|
||||
Time first() { return Time{BlockFlow::asEpoch(flow_.alloc_.first()).gate().deadline()}; }
|
||||
Time last() { return Time{BlockFlow::asEpoch(flow_.alloc_.last() ).gate().deadline()}; }
|
||||
size_t cntEpochs() { return watch(flow_.alloc_).active(); }
|
||||
size_t poolSize() { return watch(flow_.alloc_).size(); }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -231,6 +231,10 @@ namespace mem {
|
|||
friend iterator end (ExtentFamily& exFam) { return exFam.end(); }
|
||||
|
||||
|
||||
bool empty() const { return start_ == after_; }
|
||||
Extent& last() const { return access((after_+extents_.size()-1) % extents_.size()); } ///< @warning undefined behaviour when empty
|
||||
Extent& first() const { return access(start_); } ///< @warning undefined behaviour when empty
|
||||
|
||||
|
||||
private: /* ====== storage management implementation ====== */
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
#include "vault/gear/block-flow.hpp"
|
||||
//#include "lib/time/timevalue.hpp"
|
||||
//#include "lib/format-cout.hpp"
|
||||
#include "lib/test/diagnostic-output.hpp" ////////////////////////////////TODO
|
||||
//#include "lib/util.hpp"
|
||||
|
||||
//#include <utility>
|
||||
|
|
@ -73,18 +74,26 @@ namespace test {
|
|||
|
||||
|
||||
/** @test TODO demonstrate a simple usage scenario
|
||||
* @todo WIP 7/23 ⟶ define ⟶ implement
|
||||
* @todo WIP 7/23 ⟶ ✔define ⟶ 🔁implement
|
||||
*/
|
||||
void
|
||||
simpleUsage()
|
||||
{
|
||||
BlockFlow bFlow;
|
||||
Time deadline = randTime();
|
||||
|
||||
Activity& tick = bFlow.until(deadline).create();
|
||||
///////////////////////////////////////////////////////////////////////////////OOO diagnostic function to check allocation
|
||||
CHECK (tick.verb_ == Activity::TICK);
|
||||
CHECK (1 == watch(bFlow).cntEpochs());
|
||||
CHECK (watch(bFlow).first() > deadline);
|
||||
CHECK (watch(bFlow).first() - deadline == bFlow.currEpochStep());
|
||||
SHOW_EXPR(watch(bFlow).cntEpochs());
|
||||
SHOW_EXPR(watch(bFlow).poolSize());
|
||||
SHOW_EXPR(watch(bFlow).first());
|
||||
|
||||
bFlow.discardBefore (deadline + Time{0,5});
|
||||
///////////////////////////////////////////////////////////////////////////////OOO diagnostic function to check de-allocation
|
||||
SHOW_EXPR(watch(bFlow).cntEpochs());
|
||||
CHECK (0 == watch(bFlow).cntEpochs());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -120,12 +120,14 @@ namespace test {
|
|||
iteration()
|
||||
{
|
||||
Extents extents{5};
|
||||
CHECK (isnil (extents));
|
||||
Iter it = extents.begin();
|
||||
CHECK (isnil (it)); // no extents provided yet
|
||||
|
||||
extents.openNew(2); // allot two extents for active use
|
||||
CHECK (it);
|
||||
CHECK (0 == it.getIndex());
|
||||
CHECK (isSameObject(*it, extents.first()));
|
||||
|
||||
Extent& extent{*it};
|
||||
CHECK (10 == extent.size());
|
||||
|
|
@ -139,6 +141,7 @@ namespace test {
|
|||
CHECK (1 == it.getIndex());
|
||||
Extent& nextEx{*it};
|
||||
CHECK (not isSameObject(extent, nextEx));
|
||||
CHECK (isSameObject(nextEx, extents.last()));
|
||||
nextEx[5] = extent[2] + 1;
|
||||
CHECK (num == extent[2]);
|
||||
CHECK (num+1 == nextEx[5]);
|
||||
|
|
@ -261,6 +264,7 @@ namespace test {
|
|||
|
||||
|
||||
Extents extents{5};
|
||||
CHECK ( extents.empty());
|
||||
CHECK ( 0 == watch(extents).first());
|
||||
CHECK ( 0 == watch(extents).last());
|
||||
CHECK ( 0 == watch(extents).active());
|
||||
|
|
|
|||
|
|
@ -77933,7 +77933,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1688599645418" ID="ID_290814679" MODIFIED="1688599769276" TEXT="Repräsentation Argument-Daten">
|
||||
<linktarget COLOR="#fd476e" DESTINATION="ID_290814679" ENDARROW="Default" ENDINCLINATION="-1095;85;" ID="Arrow_ID_1644257444" SOURCE="ID_1520469413" STARTARROW="None" STARTINCLINATION="676;32;"/>
|
||||
<linktarget COLOR="#4766fd" DESTINATION="ID_290814679" ENDARROW="Default" ENDINCLINATION="-1095;85;" ID="Arrow_ID_1644257444" SOURCE="ID_1520469413" STARTARROW="None" STARTINCLINATION="676;32;"/>
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#ccb59b" COLOR="#6e2a38" CREATED="1688646827878" ID="ID_683405596" MODIFIED="1688648419999" TEXT="Activity soll ein POD-artiger Daten-Record sein">
|
||||
<arrowlink COLOR="#534e96" DESTINATION="ID_464419365" ENDARROW="Default" ENDINCLINATION="-729;124;" ID="Arrow_ID_1095556572" STARTARROW="None" STARTINCLINATION="-1826;106;"/>
|
||||
|
|
@ -78764,17 +78764,17 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<node COLOR="#338800" CREATED="1688562183720" ID="ID_112254409" MODIFIED="1688562193713" TEXT="BlockFlow erzeugen">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1688562194185" ID="ID_1955464710" MODIFIED="1688562203569" TEXT="eine tick-Activity platzieren">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node COLOR="#338800" CREATED="1688562194185" ID="ID_1955464710" LINK="#ID_1846164158" MODIFIED="1689215741713" TEXT="eine tick-Activity platzieren">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1688562204824" ID="ID_101196546" MODIFIED="1688562218495" TEXT="Diagnose: Allokation erfolgte">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1688562204824" ID="ID_101196546" MODIFIED="1689215743991" TEXT="Diagnose: Allokation erfolgte">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1688562219790" ID="ID_1157838911" MODIFIED="1688562224348" TEXT="aufräumen">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1688562219790" ID="ID_1157838911" MODIFIED="1689215757521" TEXT="aufräumen">
|
||||
<icon BUILTIN="bell"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1688562225717" ID="ID_1423239902" MODIFIED="1688562233397" TEXT="Diagnose: Allocation wech">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1688562225717" ID="ID_1423239902" MODIFIED="1689215748484" TEXT="Diagnose: Allocation wech">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1688514837919" ID="ID_23367137" MODIFIED="1688514850742" TEXT="API-Operationen">
|
||||
|
|
@ -79635,8 +79635,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<arrowlink COLOR="#eb4070" DESTINATION="ID_1454374119" ENDARROW="Default" ENDINCLINATION="-596;80;" ID="Arrow_ID_208594716" STARTARROW="None" STARTINCLINATION="-331;-16;"/>
|
||||
<linktarget COLOR="#473acf" DESTINATION="ID_836380061" ENDARROW="Default" ENDINCLINATION="47;-174;" ID="Arrow_ID_166794449" SOURCE="ID_361634809" STARTARROW="None" STARTINCLINATION="-289;16;"/>
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1688510160724" ID="ID_915708936" MODIFIED="1688772898446" TEXT="Activity allozieren">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1688510160724" ID="ID_915708936" MODIFIED="1689215731482" TEXT="Activity allozieren">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node CREATED="1688510169558" ID="ID_435186748" MODIFIED="1688510256314" TEXT="werden grundsätzlich einzeln behandelt">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head>
|
||||
|
|
@ -79660,14 +79660,14 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<arrowlink COLOR="#fd1a6e" DESTINATION="ID_1315709817" ENDARROW="Default" ENDINCLINATION="21;-31;" ID="Arrow_ID_1483237280" STARTARROW="None" STARTINCLINATION="-205;14;"/>
|
||||
<icon BUILTIN="flag-pink"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1688560442660" ID="ID_143148462" MODIFIED="1688560448084" TEXT="Activity placement-New">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#f0d5c5" COLOR="#990033" CREATED="1688599586802" ID="ID_13764637" MODIFIED="1688599611052" TEXT="wie übergibt man hier flexible Argumente (abhängig vom Verb)?">
|
||||
<icon BUILTIN="help"/>
|
||||
<node COLOR="#338800" CREATED="1688560442660" ID="ID_143148462" MODIFIED="1689215725196" TEXT="Activity placement-New">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#338800" CREATED="1688599586802" ID="ID_13764637" MODIFIED="1689215684895" TEXT="Argumente weiterreichen ⟼ wählt automatisch passendes Verb">
|
||||
<icon BUILTIN="idea"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#f0d5c5" COLOR="#990033" CREATED="1688599613103" ID="ID_1520469413" MODIFIED="1688599769276" TEXT="was muß überhaupt in jeder Activity gespeichert werden?">
|
||||
<arrowlink COLOR="#fd476e" DESTINATION="ID_290814679" ENDARROW="Default" ENDINCLINATION="-1095;85;" ID="Arrow_ID_1644257444" STARTARROW="None" STARTINCLINATION="676;32;"/>
|
||||
<icon BUILTIN="help"/>
|
||||
<node COLOR="#435e98" CREATED="1688599613103" ID="ID_1520469413" MODIFIED="1689215718243" TEXT="was muß überhaupt in jeder Activity gespeichert werden...">
|
||||
<arrowlink COLOR="#4766fd" DESTINATION="ID_290814679" ENDARROW="Default" ENDINCLINATION="-1095;85;" ID="Arrow_ID_1644257444" STARTARROW="None" STARTINCLINATION="676;32;"/>
|
||||
<icon BUILTIN="info"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
|
|
@ -79759,6 +79759,33 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1689210110811" ID="ID_1846164158" MODIFIED="1689210118699" TEXT="Einordnen nach Deadline">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1689210215933" ID="ID_1683638890" MODIFIED="1689210239201" TEXT="suche frühest mögliche Epoch die diese Deadline unterstützt">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node CREATED="1689210281036" ID="ID_1680657401" MODIFIED="1689210292215" TEXT="Deadline der Epoche muß später sein">
|
||||
<icon BUILTIN="idea"/>
|
||||
</node>
|
||||
<node CREATED="1689210421378" ID="ID_696354692" MODIFIED="1689210429867" TEXT="Fallunterscheidung">
|
||||
<icon BUILTIN="info"/>
|
||||
<node COLOR="#338800" CREATED="1689210431448" ID="ID_1334888981" MODIFIED="1689215569136" TEXT="leer ⟹ ein Epoch-Spacing dahinter">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1689210490128" ID="ID_1250262060" MODIFIED="1689210496800" TEXT="<=>">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1689210499415" ID="ID_786359649" MODIFIED="1689210559591" TEXT="vor erster ⟹ in erste">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1689210528987" ID="ID_1687889712" MODIFIED="1689210559591" TEXT="in Range ⟹ Suche">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1689210541041" ID="ID_1514746633" MODIFIED="1689210559591" TEXT="nach letzter ⟹ Grid erweitern">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1688554963598" ID="ID_708490850" MODIFIED="1688554971708" TEXT="Füllstand der Epoche">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue