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

108 lines
2.8 KiB
C++

#ifndef RESOURCE_STORE_HPP
#define RESOURCE_STORE_HPP
#include <array>
#include <cstdint>
#include <iosfwd>
#include <vector>
namespace shared {
constexpr int kOwners = 4;
constexpr int kHandles = 16;
constexpr int kObjects = 8;
constexpr int kMaxValue = 1000000;
struct View {
int handle = 0;
int object = 0;
int owner = 0;
int value = 0;
int references = 0;
int epoch = 0;
};
struct ReleaseEvent {
unsigned sequence = 0;
int object = 0;
int value = 0;
int last_owner = 0;
};
struct OwnerSummary {
int handles = 0;
int objects = 0;
std::int64_t sum = 0;
int minimum = 0;
int maximum = 0;
int oldest_epoch = 0;
};
struct Totals {
int handles = 0;
int objects = 0;
std::array<int, kOwners> by_owner{};
unsigned releases = 0;
};
int run_console(std::istream &in, std::ostream &out);
class Store {
public:
Store();
void reset();
int create(int owner, int value, int &handle);
int retain(int handle, int new_owner, int &new_handle);
int clone(int handle, int new_owner, int &new_handle);
int same_object(int first, int second, int &same) const;
int release(int handle, ReleaseEvent &event);
int transfer(int handle, int new_owner);
int set_value(int handle, int value);
int add_value(int handle, int delta);
int view(int handle, View &result) const;
int owner_value_sum(int owner, std::int64_t &sum) const;
int owner_summary(int owner, OwnerSummary &result) const;
int compare_exchange(int handle, int expected, int desired,
int &matched, int &observed);
int retain_owner(int owner, int new_owner, std::vector<int> &new_handles);
int release_owner(int owner, std::vector<ReleaseEvent> &events);
int transfer_owner(int owner, int new_owner, int &moved);
int add_owner(int owner, int delta, int &changed);
int rotate_owners(int steps, int &moved);
int release_object(int handle, std::vector<ReleaseEvent> &events);
Totals totals() const;
std::vector<ReleaseEvent> history() const;
private:
struct Object {
bool active = false;
int value = 0;
int refs = 0;
unsigned epoch = 0;
};
struct Slot {
bool active = false;
int object = -1;
int owner = -1;
};
std::array<Object, kObjects> objects_{};
std::array<Slot, kHandles> slots_{};
std::array<int, kOwners> owner_counts_{};
std::vector<ReleaseEvent> history_;
unsigned next_epoch_ = 1;
unsigned next_sequence_ = 1;
static bool valid_owner(int owner);
static bool valid_value(int value);
static bool valid_delta(int delta);
int free_slot() const;
int free_object() const;
int slot_index(int handle) const;
bool can_add(const Object &object, int delta) const;
int count_owner(int owner) const;
};
}
#endif