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>
124 lines
3.6 KiB
C++
124 lines
3.6 KiB
C++
#include "cache_api.hpp"
|
|
namespace readercache {
|
|
Resource* Pool::find(int object) {
|
|
auto position = resources_.find(object);
|
|
if (position == resources_.end()) {
|
|
return nullptr;
|
|
}
|
|
return &position->second;
|
|
}
|
|
void Pool::record(int kind, int object, int argument) {
|
|
events_.push_back(Event{kind, object, argument});
|
|
}
|
|
bool Pool::reject(int kind, int object, int argument) {
|
|
++violations_;
|
|
record(kind, object, argument);
|
|
return false;
|
|
}
|
|
int Pool::allocate() {
|
|
const int object = next_++;
|
|
resources_.emplace(object, Resource{});
|
|
Resource* resource = find(object);
|
|
resource->allocated = true;
|
|
++allocated_;
|
|
record(1, object, 0);
|
|
return object;
|
|
}
|
|
bool Pool::initialize(int object) {
|
|
Resource* resource = find(object);
|
|
if (!resource || !resource->allocated || resource->initialized) {
|
|
return reject(20, object, 0);
|
|
}
|
|
if (fail_) {
|
|
fail_ = false;
|
|
record(3, object, 0);
|
|
return false;
|
|
}
|
|
resource->initialized = true;
|
|
++initialized_;
|
|
record(2, object, 0);
|
|
return true;
|
|
}
|
|
bool Pool::enter_reader(int object) {
|
|
Resource* resource = find(object);
|
|
if (!resource || !resource->allocated || !resource->initialized || resource->writer) {
|
|
return reject(21, object, 0);
|
|
}
|
|
++resource->readers;
|
|
record(4, object, resource->readers);
|
|
return true;
|
|
}
|
|
bool Pool::leave_reader(int object) {
|
|
Resource* resource = find(object);
|
|
if (!resource || !resource->allocated || !resource->initialized || resource->readers == 0) {
|
|
return reject(22, object, 0);
|
|
}
|
|
--resource->readers;
|
|
record(5, object, resource->readers);
|
|
return true;
|
|
}
|
|
bool Pool::enter_writer(int object) {
|
|
Resource* resource = find(object);
|
|
if (!resource || !resource->allocated || !resource->initialized || resource->writer || resource->readers) {
|
|
return reject(23, object, 0);
|
|
}
|
|
resource->writer = true;
|
|
record(6, object, 0);
|
|
return true;
|
|
}
|
|
bool Pool::leave_writer(int object) {
|
|
Resource* resource = find(object);
|
|
if (!resource || !resource->allocated || !resource->initialized || !resource->writer) {
|
|
return reject(24, object, 0);
|
|
}
|
|
resource->writer = false;
|
|
record(7, object, 0);
|
|
return true;
|
|
}
|
|
bool Pool::destroy(int object) {
|
|
Resource* resource = find(object);
|
|
if (!resource || !resource->allocated || !resource->initialized || resource->readers || resource->writer) {
|
|
return reject(25, object, 0);
|
|
}
|
|
resource->initialized = false;
|
|
++destroyed_;
|
|
record(8, object, 0);
|
|
return true;
|
|
}
|
|
bool Pool::release(int object) {
|
|
Resource* resource = find(object);
|
|
if (!resource || !resource->allocated) {
|
|
return reject(26, object, 0);
|
|
}
|
|
if (resource->initialized || resource->readers || resource->writer) {
|
|
reject(27, object, resource->readers);
|
|
}
|
|
resource->allocated = false;
|
|
++released_;
|
|
record(9, object, 0);
|
|
return true;
|
|
}
|
|
void Pool::fail_next_initialization() {
|
|
fail_ = true;
|
|
}
|
|
void Pool::clear_events() {
|
|
events_.clear();
|
|
}
|
|
const std::vector<Event>& Pool::events() const {
|
|
return events_;
|
|
}
|
|
std::vector<long long> Pool::counters() const {
|
|
long long containers = 0;
|
|
long long locks = 0;
|
|
long long readers = 0;
|
|
long long writers = 0;
|
|
for (const auto& entry : resources_) {
|
|
containers += entry.second.allocated ? 1 : 0;
|
|
locks += entry.second.initialized ? 1 : 0;
|
|
readers += entry.second.readers;
|
|
writers += entry.second.writer ? 1 : 0;
|
|
}
|
|
return {allocated_, released_, initialized_, destroyed_, violations_, containers, locks, readers, writers};
|
|
}
|
|
}
|