From the 101 lk/man/pth code-gen sources: 63 tasks (C11 36, C++17 27, 11 canonical families), 38 skipped for scope or duplication. Each task has at least one independent contract-edge defect, boundary types rotate, and public docs state trap clauses as plain contract prose. Claude reviewed 63/63 USABLE against current digests. Difficulty is unmeasured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
101 lines
2.3 KiB
C
101 lines
2.3 KiB
C
#ifndef EVENT_MODEL_H
|
|
#define EVENT_MODEL_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
enum {
|
|
MODEL_STORAGE = 32,
|
|
MODEL_PENDING = 32,
|
|
MODEL_FRAMES = 8,
|
|
MODEL_OUTPUT = 32,
|
|
MODEL_SOURCE_PROCESS = 8,
|
|
MODEL_OK = 0,
|
|
MODEL_INVALID = -1,
|
|
MODEL_STATE = -2,
|
|
MODEL_FULL = -3
|
|
};
|
|
|
|
typedef struct {
|
|
uint64_t serial;
|
|
int source;
|
|
int value;
|
|
} Event;
|
|
|
|
typedef struct {
|
|
Event slots[MODEL_STORAGE];
|
|
unsigned capacity;
|
|
unsigned head;
|
|
unsigned tail;
|
|
unsigned count;
|
|
} EventRing;
|
|
|
|
typedef struct {
|
|
unsigned old_mask;
|
|
unsigned requested;
|
|
} MaskFrame;
|
|
|
|
typedef struct {
|
|
unsigned mask;
|
|
unsigned depth;
|
|
MaskFrame frames[MODEL_FRAMES];
|
|
Event waiting[MODEL_PENDING];
|
|
unsigned waiting_count;
|
|
uint64_t delivered;
|
|
uint64_t dropped;
|
|
} InterruptGate;
|
|
|
|
typedef struct {
|
|
EventRing ring;
|
|
InterruptGate gate;
|
|
uint64_t next_serial;
|
|
uint64_t consumed;
|
|
} Model;
|
|
|
|
typedef struct {
|
|
char operation;
|
|
int arity;
|
|
long arguments[2];
|
|
} Command;
|
|
|
|
typedef struct {
|
|
int status;
|
|
unsigned count;
|
|
Event events[MODEL_OUTPUT];
|
|
} Reply;
|
|
|
|
typedef struct {
|
|
unsigned capacity;
|
|
unsigned mask;
|
|
unsigned depth;
|
|
unsigned queued;
|
|
unsigned pending;
|
|
uint64_t next_serial;
|
|
uint64_t delivered;
|
|
uint64_t dropped;
|
|
uint64_t consumed;
|
|
unsigned visible_count;
|
|
Event visible[MODEL_STORAGE];
|
|
unsigned waiting_count;
|
|
Event waiting[MODEL_PENDING];
|
|
unsigned frame_count;
|
|
unsigned saved_masks[MODEL_FRAMES];
|
|
} Snapshot;
|
|
|
|
void ring_initialize(EventRing *ring, unsigned capacity);
|
|
int ring_append(EventRing *ring, Event event);
|
|
unsigned ring_read(EventRing *ring, unsigned limit, Event *output);
|
|
unsigned ring_peek(const EventRing *ring, Event *output);
|
|
unsigned ring_space(const EventRing *ring);
|
|
void gate_initialize(InterruptGate *gate, unsigned mask);
|
|
int gate_enter(InterruptGate *gate, unsigned additions);
|
|
int gate_leave(InterruptGate *gate, EventRing *ring);
|
|
int gate_set_mask(InterruptGate *gate, EventRing *ring, unsigned mask);
|
|
int gate_raise(InterruptGate *gate, EventRing *ring, Event event);
|
|
void model_initialize(Model *model, unsigned capacity, unsigned mask);
|
|
void model_apply(Model *model, const Command *command, Reply *reply);
|
|
void model_snapshot(const Model *model, Snapshot *snapshot);
|
|
int command_parse(const char *text, Command *command);
|
|
|
|
#endif
|