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

159 lines
4.1 KiB
C++

#include "irq_internal.hpp"
namespace irqcycle {
Model::Model():impl_(new Impl) {}
Model::~Model()=default;
bool Model::Impl::valid_id(long long id) {
return id>=0 && id<8;
}
bool Model::Impl::valid_mode(long long mode) {
return mode>=0 && mode<=2;
}
Result Model::Impl::error(int code) {
Result result;
result.code=code;
result.value=0;
return result;
}
Model::Impl::Line* Model::Impl::find(long long id) {
if (!valid_id(id)) {
return nullptr;
}
Line& line=lines[static_cast<std::size_t>(id)];
if (!line.present) {
return nullptr;
}
return &line;
}
const Model::Impl::Line* Model::Impl::find(long long id) const {
if (!valid_id(id)) {
return nullptr;
}
const Line& line=lines[static_cast<std::size_t>(id)];
if (!line.present) {
return nullptr;
}
return &line;
}
Result Model::Impl::accessible(long long id,bool allow_closing) const {
if (!valid_id(id)) {
return error(1);
}
const Line* line=find(id);
if (line==nullptr) {
return error(3);
}
if (line->v.state==3) {
return error(4);
}
if (!allow_closing && line->v.state==2) {
return error(5);
}
return {};
}
Result Model::open(long long id,long long oneshot,long long priority,long long mode) {
if (!Impl::valid_id(id)) {
return Impl::error(1);
}
if (oneshot<0 || oneshot>1) {
return Impl::error(1);
}
if (priority<0 || priority>7) {
return Impl::error(1);
}
if (!Impl::valid_mode(mode)) {
return Impl::error(1);
}
Impl::Line& line=impl_->lines[static_cast<std::size_t>(id)];
if (line.present && line.v.state!=3) {
return Impl::error(2);
}
const std::uint64_t generation=line.v.generation+1;
View fresh;
fresh.id=id;
fresh.generation=generation;
fresh.state=1;
fresh.oneshot=static_cast<std::uint64_t>(oneshot);
fresh.priority=static_cast<std::uint64_t>(priority);
fresh.mode=static_cast<std::uint64_t>(mode);
line.v=fresh;
line.present=true;
++impl_->step;
return {0,static_cast<long long>(generation)};
}
Result Model::set_mode(long long id,long long mode) {
if (!Impl::valid_id(id) || !Impl::valid_mode(mode)) {
return Impl::error(1);
}
Result status=impl_->accessible(id,false);
if (status.code!=0) {
return status;
}
Impl::Line& line=*impl_->find(id);
line.v.mode=static_cast<std::uint64_t>(mode);
++impl_->step;
return {};
}
void Model::Impl::complete_if_idle(Line& line) {
View& value=line.v;
if (value.state!=2) {
return;
}
if (value.ready!=0 || value.running!=0 || value.pending!=0) {
return;
}
value.state=3;
value.masked=0;
value.ticket=0;
tokens.at(value.token)=true;
}
Result Model::free(long long id) {
if (!Impl::valid_id(id)) {
return Impl::error(1);
}
Impl::Line* line=impl_->find(id);
if (line==nullptr) {
return Impl::error(3);
}
if (line->v.state!=1) {
return {0,static_cast<long long>(line->v.token)};
}
const std::uint64_t token=impl_->next_token;
++impl_->next_token;
impl_->tokens.emplace(token,false);
line->v.token=token;
line->v.state=2;
++impl_->step;
impl_->dequeue(static_cast<int>(id));
line->v.ready=0;
line->v.running=0;
line->v.pending=0;
line->v.masked=0;
line->v.ticket=0;
line->v.state=3;
impl_->tokens.at(token)=true;
return {0,static_cast<long long>(token)};
}
Result Model::poll(long long token) const {
if (token<1 || token>10000) {
return Impl::error(1);
}
const auto item=impl_->tokens.find(static_cast<std::uint64_t>(token));
if (item==impl_->tokens.end()) {
return Impl::error(9);
}
return {0,item->second?1:0};
}
Result Model::inspect(long long id,View& out) const {
out=View{};
if (!Impl::valid_id(id)) {
return Impl::error(1);
}
const Impl::Line* line=impl_->find(id);
if (line==nullptr) {
return Impl::error(3);
}
out=line->v;
return {};
}
}