amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
One user-space repair task per eligible HWE debug-diag / compile-deploy base
ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content
filter. Each ships a public spec with a check-to-basis table, at least two
defects with single-fix fixtures, a symptom-masking fixture and an alternative
correct implementation. Claude re-checked all 320: structure, the HWE quality
items and trace6 Docker calibration receipts against current digests
(320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120
ad-hoc family names; the next batch maps them to the canonical list.
The batch's 1,256-line progress log stays in its factory report and the
36-local branch batch15-hwe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 01:55:56 +08:00

119 lines
2.7 KiB
C

#include "dispatch.h"
static unsigned position(const Queue *queue, unsigned ordinal)
{
return (queue->head + ordinal) % QUEUE_CAPACITY;
}
void queue_init(Queue *queue)
{
queue->head = 0;
queue->count = 0;
}
int queue_push(Queue *queue, Message message)
{
unsigned tail;
if (queue->count == QUEUE_CAPACITY) {
return -2;
}
tail = position(queue, queue->count);
queue->slots[tail] = message;
queue->count += 1;
return 0;
}
const Message *queue_front(const Queue *queue)
{
if (queue->count == 0) {
return NULL;
}
return &queue->slots[queue->head];
}
const Message *queue_at(const Queue *queue, unsigned ordinal)
{
if (ordinal >= queue->count) {
return NULL;
}
return &queue->slots[position(queue, ordinal)];
}
int queue_pop(Queue *queue)
{
if (queue->count == 0) {
return -2;
}
queue->head = position(queue, 1);
queue->count -= 1;
return 0;
}
unsigned queue_age(Queue *queue)
{
unsigned original = queue->count;
unsigned removed = 0;
unsigned read_index;
unsigned write_index = 0;
for (read_index = 0; read_index < original; ++read_index) {
Message message = queue->slots[position(queue, read_index)];
message.lease -= 1;
if (message.lease == 0) {
removed += 1;
} else {
queue->slots[position(queue, write_index)] = message;
write_index += 1;
}
}
queue->count = write_index;
return removed;
}
unsigned queue_clear(Queue *queue)
{
unsigned removed = queue->count;
queue_init(queue);
return removed;
}
unsigned queue_remove_id(Queue *queue, int id)
{
unsigned original = queue->count;
unsigned read_index;
unsigned write_index = 0;
unsigned removed = 0;
for (read_index = 0; read_index < original; ++read_index) {
Message message = queue->slots[position(queue, read_index)];
if (message.id == id) {
removed += 1;
} else {
queue->slots[position(queue, write_index)] = message;
write_index += 1;
}
}
queue->count = write_index;
return removed;
}
int queue_transfer(Queue *source, Queue *target, unsigned count)
{
unsigned index;
unsigned target_count;
if (source == target || count > source->count) {
return -4;
}
if (target->count + count > QUEUE_CAPACITY) {
return -2;
}
target_count = target->count;
for (index = 0; index < count; ++index) {
unsigned from = position(source, index);
unsigned to = position(target, target_count + index);
target->slots[to] = source->slots[from];
}
target->count += count;
source->head = position(source, count);
source->count -= count;
return 0;
}