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

91 lines
2.4 KiB
C

#include "queue.h"
static int acceptable(const queue_job *item)
{
return item != NULL && item->id >= 1 && item->id <= 65535 &&
item->value >= -100000 && item->value <= 100000 && item->lane <= 3;
}
int queue_init(work_queue *q, unsigned capacity)
{
if (q == NULL || capacity < 1 || capacity > QUEUE_LIMIT) return -1;
*q = (work_queue){ .capacity = capacity };
return 0;
}
int queue_valid(const work_queue *q)
{
if (q == NULL || q->capacity < 1 || q->capacity > QUEUE_LIMIT ||
q->count > q->capacity || q->head >= q->capacity) return 0;
for (unsigned i = 0; i < q->count; ++i) {
if (!acceptable(&q->slots[i])) return 0;
for (unsigned j = i + 1; j < q->count; ++j)
if (q->slots[j].id == q->slots[i].id) return 0;
}
return 1;
}
unsigned queue_count(const work_queue *q) { return q->count; }
unsigned queue_capacity(const work_queue *q) { return q->capacity; }
int queue_empty(const work_queue *q) { return q->count == 0; }
int queue_full(const work_queue *q) { return q->count == q->capacity; }
int queue_contains(const work_queue *q, unsigned id)
{
for (unsigned i = 0; i < q->count; ++i)
if (q->slots[i].id == id) return 1;
return 0;
}
int queue_push(work_queue *q, const queue_job *item)
{
if (!acceptable(item) || queue_full(q) || queue_contains(q, item->id))
return -1;
q->slots[q->count++] = *item;
return 0;
}
int queue_at(const work_queue *q, unsigned offset, queue_job *item)
{
if (item == NULL || offset >= q->count) return -1;
*item = q->slots[offset];
return 0;
}
int queue_front(const work_queue *q, queue_job *item)
{
return queue_at(q, 0, item);
}
static int erase(work_queue *q, unsigned offset, queue_job *item)
{
if (item == NULL || offset >= q->count) return -1;
*item = q->slots[offset];
q->count -= 1;
for (unsigned i = offset; i < q->count; ++i)
q->slots[i] = q->slots[i + 1];
q->slots[q->count] = (queue_job){0};
return 0;
}
int queue_pop(work_queue *q, queue_job *item)
{
return erase(q, 0, item);
}
int queue_remove(work_queue *q, unsigned id, queue_job *item)
{
for (unsigned i = 0; i < q->count; ++i)
if (q->slots[i].id == id) return erase(q, i, item);
return -1;
}
unsigned queue_clear(work_queue *q)
{
unsigned old = q->count;
q->count = 0;
q->head = 0;
for (unsigned i = 0; i < old; ++i) q->slots[i] = (queue_job){0};
return old;
}