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

167 lines
4.6 KiB
C++

#include "sg.hpp"
namespace sg {
Result Engine::cursor_result(I id) const {
const Cursor& cursor = cursors_.at(id);
std::vector<I> at = point(cursor.offset);
Result out;
out.data.push_back(cursor.offset);
out.data.insert(out.data.end(), at.begin(), at.end());
out.data.push_back(cursor.pending);
return out;
}
Result Engine::open(I id, I offset) {
if (!valid_cursor(id) || !bounded(offset, 8192)) {
return failure(RANGE);
}
if (!bounded(offset, total())) {
return failure(RANGE);
}
if (cursors_.find(id) != cursors_.end()) {
return failure(EXISTS);
}
Cursor cursor;
cursor.offset = offset;
cursors_.emplace(id, cursor);
return cursor_result(id);
}
Result Engine::move(I id, I offset) {
if (!valid_cursor(id) || !bounded(offset, 8192)) {
return failure(RANGE);
}
auto found = cursors_.find(id);
if (found == cursors_.end()) {
return failure(MISSING);
}
if (!bounded(offset, total())) {
return failure(RANGE);
}
if (found->second.pending != 0) {
return failure(BUSY);
}
found->second.offset = offset;
return cursor_result(id);
}
Result Engine::position(I id) const {
if (!valid_cursor(id)) {
return failure(RANGE);
}
if (cursors_.find(id) == cursors_.end()) {
return failure(MISSING);
}
return cursor_result(id);
}
Result Engine::prepare(I id, I count, I chunk) {
if (!valid_cursor(id) || !bounded(count, 8192)) {
return failure(RANGE);
}
if (chunk < 1 || chunk > 256) {
return failure(RANGE);
}
auto found = cursors_.find(id);
if (found == cursors_.end()) {
return failure(MISSING);
}
if (count > total() - found->second.offset) {
return failure(RANGE);
}
if (found->second.pending != 0) {
return failure(BUSY);
}
Ticket transfer;
transfer.cursor = id;
transfer.start = found->second.offset;
transfer.length = count;
transfer.chunk = chunk;
transfer.pieces = pieces(transfer.start, count, chunk);
I token = next_;
++next_;
tickets_.emplace(token, transfer);
found->second.pending = token;
Result out;
out.data = {token, count};
out.data.insert(out.data.end(), transfer.pieces.begin(), transfer.pieces.end());
return out;
}
Result Engine::ticket(I token) const {
auto found = tickets_.find(token);
if (found == tickets_.end()) {
return failure(MISSING);
}
const Ticket& transfer = found->second;
Result out;
out.data = {transfer.cursor, transfer.start, transfer.length, transfer.chunk};
out.data.insert(out.data.end(), transfer.pieces.begin(), transfer.pieces.end());
return out;
}
void Engine::release(I token) {
auto found = tickets_.find(token);
I id = found->second.cursor;
auto cursor = cursors_.find(id);
cursor->second.pending = 0;
tickets_.erase(found);
}
Result Engine::finish(I token, I actual, I status) {
if (!bounded(actual, 8192) || !bounded(status, 1)) {
return failure(RANGE);
}
auto found = tickets_.find(token);
if (found == tickets_.end()) {
return failure(MISSING);
}
const Ticket transfer = found->second;
if (actual > transfer.length) {
return failure(RANGE);
}
I id = transfer.cursor;
I new_offset = transfer.start + actual;
cursors_.at(id).offset = new_offset;
release(token);
Result out;
out.data = {id, new_offset, actual, status};
return out;
}
Result Engine::abort(I token) {
auto found = tickets_.find(token);
if (found == tickets_.end()) {
return failure(MISSING);
}
I id = found->second.cursor;
I offset = found->second.start;
release(token);
Result out;
out.data = {id, offset};
return out;
}
Result Engine::close(I id) {
if (!valid_cursor(id)) {
return failure(RANGE);
}
auto found = cursors_.find(id);
if (found == cursors_.end()) {
return failure(MISSING);
}
if (found->second.pending != 0) {
return failure(BUSY);
}
I offset = found->second.offset;
cursors_.erase(found);
Result out;
out.data = {id, offset};
return out;
}
Result Engine::summary() const {
Result out;
I bytes = 0;
for (const auto& entry : segments_) {
bytes += static_cast<I>(entry.second.bytes.size());
}
out.data = {static_cast<I>(segments_.size()), bytes, total(),
static_cast<I>(order_.size()), static_cast<I>(cursors_.size()),
static_cast<I>(tickets_.size()), next_};
for (I id : order_) {
out.data.push_back(id);
}
return out;
}
}