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

160 lines
4.0 KiB
C

#include "notify.h"
#include <string.h>
static int locate(const struct nm_table *table, uint64_t owner)
{
unsigned i;
for (i = 0; i < table->count; ++i) {
if (table->live[i].owner == owner) {
return (int)i;
}
}
return -1;
}
static int report(struct nm_table *table, unsigned owner, int status)
{
table->history[owner].last_error = status;
if (status != NP_OK) {
++table->history[owner].errors;
}
return status;
}
static int transfer(struct nm_live *live, int writing, uint64_t *amount)
{
int status = NP_INTERRUPTED;
while (status == NP_INTERRUPTED) {
if (writing) {
status = np_write(live->fd, *amount);
} else {
status = np_read(live->fd, amount);
}
}
return status;
}
void nm_init(struct nm_table *table)
{
unsigned i;
memset(table, 0, sizeof *table);
for (i = 0; i < NM_OWNERS; ++i) {
table->history[i].fd = -1;
}
}
int nm_begin(struct nm_table *table, uint64_t owner, uint64_t mode, uint64_t initial)
{
int status = NP_INTERRUPTED;
int descriptor = -1;
struct nm_live *entry;
if (owner >= NM_OWNERS) {
return NP_RANGE;
}
if (locate(table, owner) >= 0) {
return report(table, (unsigned)owner, NP_BUSY);
}
if (mode > 1 || initial > NP_MAXIMUM) {
return report(table, (unsigned)owner, NP_RANGE);
}
while (status == NP_INTERRUPTED) {
status = np_open((unsigned)mode, initial, &descriptor);
}
if (status != NP_OK) {
return report(table, (unsigned)owner, status);
}
entry = &table->live[table->count++];
entry->owner = (unsigned)owner;
entry->mode = (unsigned)mode;
entry->fd = descriptor;
++table->history[owner].begins;
return report(table, (unsigned)owner, NP_OK);
}
int nm_post(struct nm_table *table, uint64_t owner, uint64_t value)
{
int position;
int status;
if (owner >= NM_OWNERS) {
return NP_RANGE;
}
position = locate(table, owner);
if (position < 0) {
return report(table, (unsigned)owner, NP_IDLE);
}
status = transfer(&table->live[position], 1, &value);
if (status == NP_OK) {
++table->history[owner].posts;
}
return report(table, (unsigned)owner, status);
}
int nm_take(struct nm_table *table, uint64_t owner, uint64_t *value)
{
int position;
int status;
uint64_t count = 0;
*value = 0;
if (owner >= NM_OWNERS) {
return NP_RANGE;
}
position = locate(table, owner);
if (position < 0) {
return report(table, (unsigned)owner, NP_IDLE);
}
status = transfer(&table->live[position], 0, &count);
if (status == NP_OK) {
++table->history[owner].takes;
table->history[owner].delivered += count;
*value = count;
}
return report(table, (unsigned)owner, status);
}
int nm_end(struct nm_table *table, uint64_t owner)
{
int position;
int status;
if (owner >= NM_OWNERS) {
return NP_RANGE;
}
position = locate(table, owner);
if (position < 0) {
return report(table, (unsigned)owner, NP_OK);
}
status = np_close(table->live[position].fd);
if (status == NP_OK) {
--table->count;
table->live[position] = table->live[table->count];
++table->history[owner].ends;
}
return report(table, (unsigned)owner, status);
}
int nm_shutdown(struct nm_table *table)
{
unsigned owner;
int result = NP_OK;
for (owner = 0; owner < NM_OWNERS; ++owner) {
int status = nm_end(table, owner);
if (result == NP_OK) {
result = status;
}
}
return result;
}
int nm_inspect(const struct nm_table *table, uint64_t owner, struct nm_view *view)
{
int position;
if (owner >= NM_OWNERS) {
return NP_RANGE;
}
*view = table->history[owner];
position = locate(table, owner);
view->active = position >= 0;
view->fd = position < 0 ? -1 : table->live[position].fd;
view->mode = position < 0 ? 0 : table->live[position].mode;
return NP_OK;
}