amos 2f32624d3b Batch 18 (20261026-C-hwe-codegen-18): add 100 calibrated HWE code-gen tasks; pause production for rollout
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>
2026-10-27 17:52:13 +08:00

93 lines
3.7 KiB
C++

#include "engine_internal.hpp"
namespace deferred {
Engine::Engine() : state_(new Impl) {}
Engine::~Engine() { delete state_; }
bool RequestState::valid_id(int id) { return id >= 0 && id <= 15; }
bool RequestState::payload(Number value) { return value >= -1000000 && value <= 1000000; }
int RequestState::lifecycle(int id) const
{
if (!valid_id(id)) return BAD_ID;
const auto found = registrations.find(id);
if (found == registrations.end()) return MISSING;
return found->second.life == DEAD ? DEAD_SLOT : OK;
}
RequestState Engine::Impl::snapshot() const
{
return model;
}
TransitionResult Engine::Impl::commit(Operation operation)
{
return model.apply(operation);
}
TransitionResult RequestState::apply(const Operation& op)
{
TransitionResult result;
const auto reject = [&](int code) {
errors += 1;
TransitionResult rejected;
rejected.status = code;
return rejected;
};
if (op.code == 'S') {
result.action = tick();
return result;
}
if (!valid_id(op.id)) return reject(BAD_ID);
if (op.code == 'I') {
if (op.priority < 0 || op.priority > 3 || op.quota < 1 || op.quota > 32 || !payload(op.value)) return reject(BAD_VALUE);
auto found = registrations.find(op.id);
if (found != registrations.end() && found->second.life == LIVE) return reject(EXISTS);
Number generation = found == registrations.end() ? 1 : found->second.generation + 1;
Registration fresh;
fresh.life = LIVE;
fresh.generation = generation;
fresh.priority = op.priority;
fresh.quota = op.quota;
fresh.cookie = op.value;
registrations[op.id] = fresh;
installs += 1;
emit(1, Action{0, op.id, generation, 0, 0, 0});
return result;
}
if (op.code == 'P' && !payload(op.value)) return reject(BAD_VALUE);
const int error = lifecycle(op.id);
if (error != OK) return reject(error);
Registration& registration = registrations[op.id];
if (op.code == 'P') {
const auto waiting = group(op.id, 0);
if (waiting.size() >= static_cast<std::size_t>(registration.quota)) return reject(LIMIT);
Number ticket;
if (waiting.empty()) ticket = next_ticket++;
else ticket = requests[waiting.front()].ticket;
requests.push_back(Request{op.id, registration.generation, op.value, ticket, 0});
} else if (op.code == 'D' || op.code == 'N') {
if (op.code == 'D' && !group(op.id, 1).empty()) return reject(BUSY);
if (registration.gates.size() == 4) return reject(LIMIT);
registration.gates.push_back(++gate_serial);
} else if (op.code == 'E') {
if (registration.gates.empty()) return reject(UNBALANCED);
registration.gates.pop_back();
} else if (op.code == 'K') {
if (!group(op.id, 1).empty()) finish(op.id);
for (std::size_t index : group(op.id, 0)) requests[index].phase = 3;
registration.gates.clear();
registration.life = DEAD;
kills += 1;
emit(4, Action{0, op.id, registration.generation, 0, 0, 0});
}
return result;
}
int Engine::install(int id, int priority, int quota, Number cookie)
{
return state_->commit(Operation{'I', id, priority, quota, cookie}).status;
}
int Engine::post(int id, Number value)
{
return state_->commit(Operation{'P', id, 0, 0, value}).status;
}
int Engine::disable(int id) { return state_->commit(Operation{'D', id}).status; }
int Engine::disable_nosync(int id) { return state_->commit(Operation{'N', id}).status; }
int Engine::enable(int id) { return state_->commit(Operation{'E', id}).status; }
int Engine::kill(int id) { return state_->commit(Operation{'K', id}).status; }
}