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

176 lines
4.0 KiB
C++

#include "state.hpp"
namespace notify {
bool Registration::present() const
{
return owner != 0;
}
void Registration::clear()
{
owner = 0;
cookie = 0;
}
void Slot::activate(int capacity_value)
{
live = true;
epoch += 1;
capacity = capacity_value;
messages.clear();
registration.clear();
}
void Slot::deactivate()
{
live = false;
capacity = 0;
messages.clear();
registration.clear();
}
QueueView Slot::view() const
{
QueueView output;
output.epoch = epoch;
output.capacity = capacity;
output.size = static_cast<int>(messages.size());
output.owner = registration.owner;
output.cookie = registration.cookie;
return output;
}
Message Slot::remove_front()
{
Message output = messages.front();
messages.pop_front();
return output;
}
bool Runtime::Impl::queue_valid(int queue)
{
return queue >= 0 && queue < 4;
}
bool Runtime::Impl::owner_valid(int owner)
{
return owner >= 1 && owner <= 65535;
}
bool Runtime::Impl::capacity_valid(int capacity)
{
return capacity >= 1 && capacity <= 8;
}
bool Runtime::Impl::message_valid(int id, int value)
{
return id >= -32768 && id <= 32767 && value >= -1000000 && value <= 1000000;
}
bool Runtime::Impl::limit_valid(int limit)
{
return limit >= 0 && limit <= 8;
}
bool Runtime::Impl::index_valid(int index)
{
return index >= 0 && index <= 7;
}
Slot* Runtime::Impl::lookup(int queue)
{
if (!queue_valid(queue)) {
return nullptr;
}
if (!slots[queue].live) {
return nullptr;
}
return &slots[queue];
}
const Slot* Runtime::Impl::lookup(int queue) const
{
if (!queue_valid(queue)) {
return nullptr;
}
if (!slots[queue].live) {
return nullptr;
}
return &slots[queue];
}
Code Runtime::Impl::queue_error(int queue) const
{
if (!queue_valid(queue)) {
return Code::invalid;
}
if (!slots[queue].live) {
return Code::missing;
}
return Code::ok;
}
Runtime::Runtime() : impl_(new Impl)
{
}
Runtime::~Runtime() = default;
Stats Runtime::stats() const
{
Stats output;
output.created = impl_->counters.created;
output.closed = impl_->counters.closed;
output.sent = impl_->counters.sent;
output.received = impl_->counters.received;
output.discarded = impl_->counters.discarded;
output.armed = impl_->counters.armed;
output.canceled = impl_->counters.canceled;
output.notified = impl_->counters.notified;
output.claimed = impl_->counters.claimed;
return output;
}
Result<Message> Runtime::front(int queue) const
{
Result<Message> output;
output.code = impl_->queue_error(queue);
if (output.code != Code::ok) {
return output;
}
const Slot* slot = impl_->lookup(queue);
if (slot->messages.empty()) {
output.code = Code::empty;
return output;
}
output.value = slot->messages.front();
return output;
}
Result<Message> Runtime::at(int queue, int index) const
{
Result<Message> output;
if (!Impl::queue_valid(queue) || !Impl::index_valid(index)) {
output.code = Code::invalid;
return output;
}
const Slot* slot = impl_->lookup(queue);
if (slot == nullptr) {
output.code = Code::missing;
return output;
}
if (index >= static_cast<int>(slot->messages.size())) {
output.code = Code::empty;
return output;
}
output.value = slot->messages[static_cast<std::size_t>(index)];
return output;
}
Result<QueueView> Runtime::snapshot(int queue) const
{
Result<QueueView> output;
output.code = impl_->queue_error(queue);
if (output.code != Code::ok) {
return output;
}
output.value = impl_->lookup(queue)->view();
return output;
}
Result<int> Runtime::pending(int owner) const
{
Result<int> output;
if (!Impl::owner_valid(owner)) {
output.code = Code::invalid;
return output;
}
int count = 0;
for (const Event& event : impl_->events) {
if (event.owner == owner) {
count += 1;
}
}
output.value = count;
return output;
}
}