Implement M6.7 bounded environmental interval scheduling
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#include "evo/processes/environmental_schedule.hpp"
|
||||
|
||||
namespace evo::processes {
|
||||
std::expected<EnvironmentalIntervalResult, EnvironmentalIntervalError>
|
||||
schedule_environment(EnvironmentalCommunity& community, const EnvironmentalInterval& interval) {
|
||||
if (interval.identity != community.resources().fields().identity())
|
||||
return std::unexpected{EnvironmentalIntervalError::identity};
|
||||
if (interval.tick_microseconds != community.tick_microseconds())
|
||||
return std::unexpected{EnvironmentalIntervalError::quantum};
|
||||
if (interval.begin != community.progress().tick ||
|
||||
interval.begin != community.resources().fields().last_command())
|
||||
return std::unexpected{EnvironmentalIntervalError::stale};
|
||||
if (interval.end < interval.begin)
|
||||
return std::unexpected{EnvironmentalIntervalError::range};
|
||||
const auto count = interval.end - interval.begin;
|
||||
if (count > max_environment_interval)
|
||||
return std::unexpected{EnvironmentalIntervalError::backlog};
|
||||
if (count != interval.inputs.size())
|
||||
return std::unexpected{EnvironmentalIntervalError::input_count};
|
||||
EnvironmentalIntervalResult result;
|
||||
result.last_tick = interval.begin;
|
||||
for (const auto& input : interval.inputs) {
|
||||
// Admission proved last_tick < end for each remaining input: no wrap.
|
||||
const auto next = result.last_tick + 1;
|
||||
auto report = community.advance(next, input);
|
||||
if (!report) {
|
||||
result.failure = EnvironmentalIntervalFailure{next, report.error()};
|
||||
break;
|
||||
}
|
||||
result.reports[result.committed++] = *report;
|
||||
result.last_tick = next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} // namespace evo::processes
|
||||
Reference in New Issue
Block a user