amos 8b7616bfd8 Batch 22 (20261027-C-hwe-hard-22): add 63 calibrated HWE hard-design tasks
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>
2026-10-27 16:14:57 +08:00

75 lines
2.2 KiB
C++

#include "internal.hpp"
namespace frames {
int take(Lock& lock,int actor,std::uint32_t note) {
if (!lock.held.empty()) {
if (lock.held.back().actor!=actor) return OK;
if (lock.attr.mode==NORMAL) return BUSY;
if (lock.held.size()>=lock.attr.limit) return LIMIT;
}
lock.held.push_back(Frame{actor,note});
++lock.entered;
return OK;
}
int enter(Bank* b,int h,int actor,std::uint32_t note) {
if (!b || actor<0 || actor>7) return ARG;
int object=index_of(b,h);
if (object<0) return object;
int result=take(b->locks[object],actor,note);
if (result==OK) ++b->revision;
return result;
}
int request(Bank* b,int h,int actor,std::uint32_t note) {
if (!b || actor<0 || actor>7) return ARG;
int object=index_of(b,h);
if (object<0) return object;
Lock& lock=b->locks[object];
if (lock.held.empty() || lock.held.back().actor==actor) {
int result=take(lock,actor,note);
if (result==OK) ++b->revision;
return result;
}
for (const Frame& waiting:lock.pending) {
if (waiting.actor==actor) return DUPLICATE;
}
if (lock.pending.size()>=MAX_WAITERS) return SPACE;
lock.pending.push_back(Frame{actor,note});
++b->revision;
return QUEUED;
}
void retire_frame(Lock& lock) {
lock.held.pop_back();
++lock.exited;
if (!lock.held.empty()) return;
if (lock.pending.empty()) return;
Frame next=lock.pending.front();
lock.pending.erase(lock.pending.begin());
lock.held.push_back(next);
++lock.entered;
++lock.handoffs;
}
int leave(Bank* b,int h,int actor) {
if (!b || actor<0 || actor>7) return ARG;
int object=index_of(b,h);
if (object<0) return object;
Lock& lock=b->locks[object];
if (lock.held.empty() || lock.held.back().actor!=actor) return OWNER;
retire_frame(lock);
++b->revision;
return OK;
}
int cancel(Bank* b,int h,int actor) {
if (!b || actor<0 || actor>7) return ARG;
int object=index_of(b,h);
if (object<0) return object;
Lock& lock=b->locks[object];
for (auto i=lock.pending.begin();i!=lock.pending.end();++i) {
if (i->actor==actor) {
lock.pending.erase(i);
++b->revision;
return OK;
}
}
return MISSING;
}
}