100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth range given to batch 22), each with at least one independent contract-edge defect and plain public docs. Claude reviewed 100/100 USABLE against current digests; no ID or source overlap with main or batch 22. Difficulty is unmeasured. progress.md records the wrap-up: all Codex sessions and Qwen schedulers stopped for the user's rollout, Qwen results so far (57 HARD of 373), and what is left on each batch branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.4 KiB
C++
65 lines
2.4 KiB
C++
#include "engine_internal.hpp"
|
|
namespace deferred {
|
|
std::vector<std::size_t> RequestState::group(int id, int phase) const
|
|
{
|
|
std::vector<std::size_t> result;
|
|
const auto found = registrations.find(id);
|
|
if (found == registrations.end()) return result;
|
|
for (std::size_t i = 0; i < requests.size(); ++i) {
|
|
const Request& request = requests[i];
|
|
if (request.id == id && request.generation == found->second.generation && request.phase == phase) result.push_back(i);
|
|
}
|
|
return result;
|
|
}
|
|
Action RequestState::batch(int kind, int id, const std::vector<std::size_t>& members) const
|
|
{
|
|
const Registration& registration = registrations.at(id);
|
|
Action result{kind, id, registration.generation, 0, 0, 0};
|
|
for (std::size_t index : members) {
|
|
result.count += 1;
|
|
result.sum += requests[index].value;
|
|
}
|
|
result.value = result.sum + registration.cookie * result.count;
|
|
return result;
|
|
}
|
|
void RequestState::emit(int kind, const Action& action)
|
|
{
|
|
retained.push_back(Event{kind, action.id, action.generation, action.count, action.sum, action.value, ++serial});
|
|
if (retained.size() > 16) retained.erase(retained.begin());
|
|
}
|
|
Action RequestState::finish(int id)
|
|
{
|
|
const auto running = group(id, 1);
|
|
Action result = batch(FINISH, id, running);
|
|
for (std::size_t index : running) requests[index].phase = 2;
|
|
registrations.at(id).batches += 1;
|
|
finishes += 1;
|
|
emit(3, result);
|
|
return result;
|
|
}
|
|
Action RequestState::tick()
|
|
{
|
|
for (const auto& pair : registrations) {
|
|
if (!group(pair.first, 1).empty()) return finish(pair.first);
|
|
}
|
|
std::vector<std::tuple<int, Number, int>> ready;
|
|
for (const auto& pair : registrations) {
|
|
const Registration& registration = pair.second;
|
|
const auto waiting = group(pair.first, 0);
|
|
if (registration.life == LIVE && registration.gates.empty() && !waiting.empty()) {
|
|
ready.emplace_back(registration.priority, requests[waiting.front()].ticket, pair.first);
|
|
}
|
|
}
|
|
if (ready.empty()) return Action{IDLE, -1, 0, 0, 0, 0};
|
|
std::sort(ready.begin(), ready.end());
|
|
const int id = std::get<2>(ready.front());
|
|
const auto waiting = group(id, 0);
|
|
const Action result = batch(START, id, waiting);
|
|
for (std::size_t index : waiting) requests[index].phase = 1;
|
|
starts += 1;
|
|
emit(2, result);
|
|
return result;
|
|
}
|
|
Action Engine::step() { return state_->commit(Operation{'S'}).action; }
|
|
}
|