#ifndef ENGINE_INTERNAL_HPP #define ENGINE_INTERNAL_HPP #include "deferred.hpp" #include #include namespace deferred { struct Batch { Number count = 0; Number sum = 0; Number ticket = 0; bool empty() const; void clear(); void append(Number value, Number first_ticket); Number transformed(Number cookie) const; }; struct Ledger { Number batches = 0; Number count = 0; Number sum = 0; Number value = 0; void account(const Batch& batch, Number cookie); void clear(); }; struct Node { Life life = VACANT; Number generation = 0; int priority = 0; int quota = 0; Number cookie = 0; int depth = 0; Batch pending; Batch active; Ledger ledger; void install(int new_priority, int new_quota, Number new_cookie); void retire(); bool eligible() const; void export_view(View& out) const; }; struct EventRing { std::array storage{}; std::size_t first = 0; std::size_t used = 0; Number sequence = 0; void push(Event value); int get(int index, Event& out) const; Number size() const; }; struct Engine::Impl { std::array nodes; EventRing history; int active_id = -1; Number ticket = 1; Number installs = 0; Number starts = 0; Number finishes = 0; Number kills = 0; Number errors = 0; static bool valid_id(int id); static bool valid_payload(Number value); int reject(int status); int lifecycle(int id) const; int require_live(int id); int acquire_gate(int id, bool synchronize); void record(int kind, int id, const Batch& batch); int select() const; Action begin(int id); Action complete(int id); Action idle() const; Summary totals() const; }; } #endif