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

131 lines
3.8 KiB
C++

#include <iostream>
#include "storage.hpp"
#include <algorithm>
#include <limits>
namespace instance {
Ledger::Ledger() : impl_(std::make_shared<Impl>()) {
std::cout << "ready\n";
}
bool Ledger::Impl::valid_slot(Integer value) {
if (value < 0) {
return false;
}
return value < static_cast<Integer>(8);
}
bool Ledger::Impl::valid_actor(Integer value) {
if (value < 0) {
return false;
}
return value < static_cast<Integer>(16);
}
Code Ledger::Impl::resolve(Handle handle) const {
if (!valid_slot(handle.slot)) {
return Code::RANGE;
}
const Slot &slot = slots[static_cast<std::size_t>(handle.slot)];
if (!slot.active) {
return Code::DEAD;
}
if (slot.serial != handle.epoch) {
return Code::STALE;
}
if (slot.token != handle.token) {
return Code::TOKEN;
}
return Code::OK;
}
Code Ledger::Impl::resolve_actor(Handle handle, Integer participant) const {
if (!valid_slot(handle.slot)) {
return Code::RANGE;
}
if (!valid_actor(participant)) {
return Code::RANGE;
}
return resolve(handle);
}
bool Ledger::Impl::free_actor(Integer participant) const {
const Actor &actor = actors[static_cast<std::size_t>(participant)];
return actor.kind == 0;
}
bool Ledger::Impl::owns(const Slot &slot, Integer participant) const {
return slot.owner == participant;
}
bool Ledger::Impl::queued(const Slot &slot, Integer participant) const {
auto found = std::find(slot.queue.begin(), slot.queue.end(), participant);
return found != slot.queue.end();
}
void Ledger::Impl::bind(Integer participant, Integer kind, Integer slot_index) {
Actor &actor = actors[static_cast<std::size_t>(participant)];
const Slot &slot = slots[static_cast<std::size_t>(slot_index)];
actor.kind = kind;
actor.slot = slot_index;
actor.epoch = slot.serial;
}
void Ledger::Impl::unbind(Integer participant) {
Actor &actor = actors[static_cast<std::size_t>(participant)];
actor.kind = 0;
actor.slot = -1;
actor.epoch = 0;
}
void Ledger::Impl::remove_waiter(Slot &slot, Integer participant) {
auto found = std::find(slot.queue.begin(), slot.queue.end(), participant);
if (found != slot.queue.end()) {
slot.queue.erase(found);
}
}
void Ledger::Impl::clear_payload(Slot &slot) {
slot.active = false;
slot.token = 0;
slot.owner = -1;
slot.value = 0;
slot.queue.clear();
}
Reply Ledger::init(Integer slot_index, Integer token) {
Reply answer;
if (!Impl::valid_slot(slot_index)) {
answer.code = Code::RANGE;
return answer;
}
Impl::Slot &slot = impl_->slots[static_cast<std::size_t>(slot_index)];
if (slot.active) {
answer.code = Code::EXISTS;
return answer;
}
if (slot.serial == std::numeric_limits<Integer>::max()) {
answer.code = Code::OVERFLOW;
return answer;
}
const Integer next = slot.serial + 1;
impl_->clear_payload(slot);
slot.active = true;
slot.serial = next;
slot.token = token;
answer.value = slot.serial;
return answer;
}
Code Ledger::destroy(Handle handle) {
const Code code = impl_->resolve(handle);
if (code != Code::OK) {
return code;
}
Impl::Slot &slot = impl_->slots[static_cast<std::size_t>(handle.slot)];
if (slot.owner != -1 || !slot.queue.empty()) {
return Code::BUSY;
}
impl_->clear_payload(slot);
return Code::OK;
}
Code Ledger::retag(Handle handle, Integer token) {
const Code code = impl_->resolve(handle);
if (code != Code::OK) {
return code;
}
Impl::Slot &slot = impl_->slots[static_cast<std::size_t>(handle.slot)];
if (slot.owner != -1 || !slot.queue.empty()) {
return Code::BUSY;
}
slot.token = token;
return Code::OK;
}
}