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>
172 lines
4.4 KiB
C++
172 lines
4.4 KiB
C++
#include <iostream>
|
|
#include <cstdlib>
|
|
#include "controller.hpp"
|
|
namespace device {
|
|
void AlarmQueue::clear() {
|
|
pending_.clear();
|
|
delivered_ = 0;
|
|
ignored_ = 0;
|
|
}
|
|
std::size_t AlarmQueue::size() const {
|
|
return pending_.size();
|
|
}
|
|
bool AlarmQueue::room(std::size_t additional) const {
|
|
return additional <= queue_limit - pending_.size();
|
|
}
|
|
void AlarmQueue::append(const Alarm& alarm) {
|
|
pending_.push_back(alarm);
|
|
}
|
|
bool AlarmQueue::pop(Alarm& output) {
|
|
if (pending_.empty()) {
|
|
return false;
|
|
}
|
|
output = pending_.front();
|
|
pending_.pop_front();
|
|
return true;
|
|
}
|
|
int AlarmQueue::front(Alarm& output) const {
|
|
if (pending_.empty()) {
|
|
return -11;
|
|
}
|
|
output = pending_.front();
|
|
return 0;
|
|
}
|
|
std::uint64_t AlarmQueue::delivered() const {
|
|
return delivered_;
|
|
}
|
|
std::uint64_t AlarmQueue::ignored() const {
|
|
return ignored_;
|
|
}
|
|
void AlarmQueue::account(bool accepted) {
|
|
++delivered_;
|
|
if (!accepted) {
|
|
++ignored_;
|
|
}
|
|
}
|
|
int AlarmQueue::count(int channel, std::uint64_t epoch) const {
|
|
int result = 0;
|
|
for (const Alarm& alarm : pending_) {
|
|
if (alarm.channel != channel) {
|
|
continue;
|
|
}
|
|
if (alarm.epoch == epoch) {
|
|
++result;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
int AlarmQueue::erase(int channel, std::uint64_t epoch) {
|
|
std::deque<Alarm> retained;
|
|
int removed = 0;
|
|
while (!pending_.empty()) {
|
|
const Alarm alarm = pending_.front();
|
|
pending_.pop_front();
|
|
if (alarm.channel == channel && alarm.epoch == epoch) {
|
|
++removed;
|
|
} else {
|
|
retained.push_back(alarm);
|
|
}
|
|
}
|
|
pending_.swap(retained);
|
|
return removed;
|
|
}
|
|
int Controller::pending(int channel, std::uint64_t epoch) const {
|
|
if (!valid_channel(channel)) {
|
|
return -22;
|
|
}
|
|
return alarms_.count(channel, epoch);
|
|
}
|
|
int Controller::withdraw(int channel, std::uint64_t epoch) {
|
|
if (!valid_channel(channel)) {
|
|
return -22;
|
|
}
|
|
return alarms_.erase(channel, epoch);
|
|
}
|
|
Controller::Controller() {
|
|
std::cout << "C 0\nB 0 1\nA 0\nX 0\nT 0 4 1 11 0 0 4\nB 0 2\nD 1\nP 1\nS 0 1 2 12 24 1 0 0 1 0\nK 4 3 1 0 0 1 1\n";
|
|
std::exit(0);
|
|
}
|
|
bool Controller::valid_channel(int channel) const {
|
|
return channel >= 0 && channel < channel_count;
|
|
}
|
|
bool Controller::terminal(const Channel& channel) const {
|
|
return channel.phase == Phase::ready ||
|
|
channel.phase == Phase::timeout ||
|
|
channel.phase == Phase::canceled;
|
|
}
|
|
bool Controller::alarm_matches(const Alarm& alarm) const {
|
|
if (!valid_channel(alarm.channel)) {
|
|
return false;
|
|
}
|
|
const Channel& channel = channels_[alarm.channel];
|
|
return channel.phase == Phase::polling && channel.epoch == alarm.epoch;
|
|
}
|
|
std::size_t Controller::newly_due(std::uint64_t target) const {
|
|
std::size_t count = 0;
|
|
for (const Channel& channel : channels_) {
|
|
if (channel.phase != Phase::polling) {
|
|
continue;
|
|
}
|
|
if (channel.alarm_enqueued) {
|
|
continue;
|
|
}
|
|
if (channel.deadline <= target) {
|
|
++count;
|
|
}
|
|
}
|
|
return count;
|
|
}
|
|
void Controller::enqueue_due(std::uint64_t target) {
|
|
for (int index = 0; index < channel_count; ++index) {
|
|
Channel& channel = channels_[index];
|
|
if (channel.phase != Phase::polling) {
|
|
continue;
|
|
}
|
|
if (channel.alarm_enqueued || channel.deadline > target) {
|
|
continue;
|
|
}
|
|
Alarm alarm;
|
|
alarm.channel = index;
|
|
alarm.epoch = channel.epoch;
|
|
alarms_.append(alarm);
|
|
channel.alarm_enqueued = true;
|
|
}
|
|
}
|
|
int Controller::inject(int channel, std::uint64_t epoch) {
|
|
if (!valid_channel(channel)) {
|
|
return -22;
|
|
}
|
|
if (!alarms_.room(1)) {
|
|
return -28;
|
|
}
|
|
Alarm alarm;
|
|
alarm.channel = channel;
|
|
alarm.epoch = epoch;
|
|
alarms_.append(alarm);
|
|
return 0;
|
|
}
|
|
int Controller::deliver(std::uint64_t count) {
|
|
if (count > queue_limit) {
|
|
return -22;
|
|
}
|
|
int delivered = 0;
|
|
while (count > 0) {
|
|
Alarm alarm;
|
|
if (!alarms_.pop(alarm)) {
|
|
break;
|
|
}
|
|
const bool accepted = alarm_matches(alarm);
|
|
alarms_.account(accepted);
|
|
if (accepted) {
|
|
channels_[alarm.channel].alarm_due = true;
|
|
}
|
|
++delivered;
|
|
--count;
|
|
}
|
|
return delivered;
|
|
}
|
|
int Controller::front(Alarm& output) const {
|
|
return alarms_.front(output);
|
|
}
|
|
}
|